MCPcopy Create free account
hub / github.com/apache/arrow / ConvertJsonToArrow

Function ConvertJsonToArrow

cpp/src/arrow/integration/json_integration_test.cc:79–101  ·  view source on GitHub ↗

Convert JSON file to IPC binary format

Source from the content-addressed store, hash-verified

77
78// Convert JSON file to IPC binary format
79static Status ConvertJsonToArrow(const std::string& json_path,
80 const std::string& arrow_path) {
81 ARROW_ASSIGN_OR_RAISE(auto in_file, io::ReadableFile::Open(json_path));
82 ARROW_ASSIGN_OR_RAISE(auto out_file, io::FileOutputStream::Open(arrow_path));
83
84 ARROW_ASSIGN_OR_RAISE(int64_t file_size, in_file->GetSize());
85 ARROW_ASSIGN_OR_RAISE(auto json_buffer, in_file->Read(file_size));
86
87 ARROW_ASSIGN_OR_RAISE(auto reader, IntegrationJsonReader::Open(json_buffer));
88
89 if (FLAGS_verbose) {
90 std::cout << "Found schema:\n"
91 << reader->schema()->ToString(/* show_metadata = */ true) << std::endl;
92 }
93
94 ARROW_ASSIGN_OR_RAISE(auto writer, ipc::MakeFileWriter(out_file, reader->schema(),
95 IpcWriteOptions::Defaults()));
96 for (int i = 0; i < reader->num_record_batches(); ++i) {
97 ARROW_ASSIGN_OR_RAISE(auto batch, reader->ReadRecordBatch(i));
98 RETURN_NOT_OK(writer->WriteRecordBatch(*batch));
99 }
100 return writer->Close();
101}
102
103// Convert IPC binary format to JSON
104static Status ConvertArrowToJson(const std::string& arrow_path,

Callers 2

RunCommandFunction · 0.85
TEST_FFunction · 0.85

Calls 5

ToStringMethod · 0.45
schemaMethod · 0.45
num_record_batchesMethod · 0.45
WriteRecordBatchMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected