MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cpp-samples / ProcessRecordBatch

Function ProcessRecordBatch

bigquery/read/arrow/arrow_read.cc:72–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72void ProcessRecordBatch(std::shared_ptr<arrow::Schema> schema,
73 std::shared_ptr<arrow::RecordBatch> record_batch,
74 std::int64_t num_rows) {
75 // If you want to see what the result looks like without parsing the
76 // datatypes, use `record_batch->ToString()` for quick debugging.
77 // Note: you might need to adjust the formatting depending on how big the data
78 // in your table is.
79 for (std::int64_t row = 0; row < record_batch->num_rows(); ++row) {
80 std::cout << std::format("Row {}: ", row + num_rows);
81
82 for (std::int64_t col = 0; col < record_batch->num_columns(); ++col) {
83 std::shared_ptr<arrow::Array> column = record_batch->column(col);
84 arrow::Result<std::shared_ptr<arrow::Scalar> > result =
85 column->GetScalar(row);
86 if (!result.ok()) {
87 std::cout << "Unable to parse scalar\n";
88 throw result.status();
89 }
90
91 std::shared_ptr<arrow::Scalar> scalar = result.ValueOrDie();
92 switch (scalar->type->id()) {
93 case arrow::Type::INT64:
94 std::cout
95 << std::left << std::setw(15)
96 << std::dynamic_pointer_cast<arrow::Int64Scalar>(scalar)->value
97 << " ";
98 break;
99 case arrow::Type::STRING:
100 std::cout
101 << std::left << std::setw(15)
102 << std::dynamic_pointer_cast<arrow::StringScalar>(scalar)->view()
103 << " ";
104 break;
105 // Depending on the table you are reading, you might need to add cases
106 // for other datatypes here. The schema will tell you what datatypes
107 // need to be handled.
108 default:
109 std::cout << std::left << std::setw(15) << "UNDEFINED ";
110 }
111 }
112 std::cout << "\n";
113 }
114}
115
116} // namespace
117

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected