Skip to content

Instantly share code, notes, and snippets.

@wamsiv
Created January 8, 2020 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wamsiv/d48ec37a9a9b5f4d484de6ff86a3870d to your computer and use it in GitHub Desktop.
Save wamsiv/d48ec37a9a9b5f4d484de6ff86a3870d to your computer and use it in GitHub Desktop.
#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