Created
January 8, 2020 17:50
-
-
Save wamsiv/d48ec37a9a9b5f4d484de6ff86a3870d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <arrow/api.h> | |
#include <arrow/io/memory.h> | |
inline constexpr auto arrow_throw_not_ok = [](auto status) { | |
if (!status.ok()) | |
{ | |
throw std::runtime_error(status.ToString()); | |
} | |
}; | |
int main() | |
{ | |
const std::vector<std::string> list = {"old lady", "sudens", "camp nou"}; | |
// initialize builder | |
std::unique_ptr<arrow::ArrayBuilder> builder; | |
arrow_throw_not_ok(arrow::MakeBuilder(arrow::default_memory_pool(), arrow::dictionary(arrow::int32(), arrow::utf8()), | |
&builder)); | |
// append/finish | |
std::shared_ptr<arrow::Array> value_array; | |
auto typed_builder = static_cast<arrow::StringDictionaryBuilder *>(builder.get()); | |
for (const auto &str : list) | |
{ | |
arrow_throw_not_ok(typed_builder->Append(str)); | |
} | |
arrow_throw_not_ok(builder->Finish(&value_array)); | |
std::cout << value_array->type()->ToString() << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment