Skip to content

Instantly share code, notes, and snippets.

@rvernica
Created September 10, 2017 03:03
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 rvernica/bacf6a9eba87fa1460aca75ff182255d to your computer and use it in GitHub Desktop.
Save rvernica/bacf6a9eba87fa1460aca75ff182255d to your computer and use it in GitHub Desktop.
/*
g++-4.9 -std=c++11 arrow-feather-example.cpp -larrow
>>> import pandas
>>> pandas.read_feather('example.feather')
*/
#include <iostream>
#include <arrow/api.h>
#include <arrow/io/file.h>
#include <arrow/ipc/feather.h>
#include <arrow/pretty_print.h>
int main() {
// 1. Build Array
arrow::Int64Builder builder(arrow::default_memory_pool(), arrow::int64());
builder.Append(1);
builder.Append(2);
builder.Append(3);
builder.AppendNull();
builder.Append(5);
builder.Append(6);
builder.Append(7);
builder.Append(8);
std::shared_ptr<arrow::Array> array;
builder.Finish(&array);
arrow::PrettyPrint(*array, 0, &std::cout);
std::cout << std::endl;
// 2. Write to Feather file
std::shared_ptr<arrow::io::FileOutputStream> stream;
arrow::io::FileOutputStream::Open("example.feather", false, &stream);
std::unique_ptr<arrow::ipc::feather::TableWriter> writer;
arrow::ipc::feather::TableWriter::Open(stream, &writer);
writer->SetNumRows(8);
writer->Append("id", *array);
writer->Finalize();
stream->Close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment