28int main(
int argc,
char** argv)
30 std::vector<std::string> args;
32 for (
int i = 1;
i < argc; ++
i) {
33 if (std::strcmp(argv[
i],
"--threads") == 0 &&
i + 1 < argc) {
34 options.threads = std::stoi(argv[++
i]);
35 }
else if (std::strcmp(argv[
i],
"--pread") == 0) {
36 options.localIO = Options::LocalIO::PRead;
38 args.push_back(argv[
i]);
41 if (args.size() != 3 || args[1].find(
'/') == std::string::npos) {
42 std::fprintf(stderr,
"usage: %s <file> <DF_x/O2tree> <output.arrow> [--threads N] [--pread]\n", argv[0]);
45 auto df = args[1].substr(0, args[1].find(
'/'));
46 auto treeName = args[1].substr(args[1].find(
'/') + 1);
49 std::optional<TreeInfo>
tree;
50 for (
auto&
key : file.keysOf(df)) {
51 if (
key.name == treeName) {
56 throw FormatError(
"no tree " + treeName +
" in " + df);
58 auto batch =
readTree(file.source(), *
tree, options).ValueOrDie();
59 auto out = arrow::io::FileOutputStream::Open(args[2]).ValueOrDie();
60 auto writer = arrow::ipc::MakeStreamWriter(out, batch->schema()).ValueOrDie();
61 auto status = writer->WriteRecordBatch(*batch);
63 status = writer->Close();
66 std::fprintf(stderr,
"%s: %s\n", argv[0], status.ToString().c_str());
70 std::fprintf(stderr,
"%s: %s\n", argv[0], e.what());
arrow::Result< std::shared_ptr< arrow::RecordBatch > > readTree(ByteSource &source, TreeInfo const &tree, Options const &options, arrow::MemoryPool *pool=arrow::default_memory_pool())
Reads a whole tree into heap memory: plan, execute, wrap.