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

Method JSONPrint

cpp/src/parquet/printer.cc:254–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252}
253
254void ParquetFilePrinter::JSONPrint(std::ostream& stream, std::list<int> selected_columns,
255 const char* filename) {
256 const FileMetaData* file_metadata = fileReader->metadata().get();
257 stream << "{\n";
258 stream << " \"FileName\": \"" << filename << "\",\n";
259 stream << " \"Version\": \"" << ParquetVersionToString(file_metadata->version())
260 << "\",\n";
261 stream << " \"CreatedBy\": \"" << file_metadata->created_by() << "\",\n";
262 stream << " \"TotalRows\": \"" << file_metadata->num_rows() << "\",\n";
263 stream << " \"NumberOfRowGroups\": \"" << file_metadata->num_row_groups() << "\",\n";
264 stream << " \"NumberOfRealColumns\": \""
265 << file_metadata->schema()->group_node()->field_count() << "\",\n";
266 stream << " \"NumberOfColumns\": \"" << file_metadata->num_columns() << "\",\n";
267
268 if (selected_columns.empty()) {
269 for (int i = 0; i < file_metadata->num_columns(); i++) {
270 selected_columns.push_back(i);
271 }
272 } else {
273 for (auto i : selected_columns) {
274 if (i < 0 || i >= file_metadata->num_columns()) {
275 throw ParquetException("Selected column is out of range");
276 }
277 }
278 }
279
280 stream << " \"Columns\": [\n";
281 int c = 0;
282 for (auto i : selected_columns) {
283 const ColumnDescriptor* descr = file_metadata->schema()->Column(i);
284 stream << " { \"Id\": \"" << i << "\","
285 << " \"Name\": \"" << descr->path()->ToDotString() << "\","
286 << " \"PhysicalType\": \""
287 << TypeToString(descr->physical_type(), descr->type_length()) << "\","
288 << " \"ConvertedType\": \"" << ConvertedTypeToString(descr->converted_type())
289 << "\","
290 << " \"LogicalType\": " << (descr->logical_type())->ToJSON() << " }";
291 c++;
292 if (c != static_cast<int>(selected_columns.size())) {
293 stream << ",\n";
294 }
295 }
296
297 stream << "\n ],\n \"RowGroups\": [\n";
298 for (int r = 0; r < file_metadata->num_row_groups(); ++r) {
299 stream << " {\n \"Id\": \"" << r << "\", ";
300
301 auto group_reader = fileReader->RowGroup(r);
302 std::unique_ptr<RowGroupMetaData> group_metadata = file_metadata->RowGroup(r);
303
304 stream << " \"TotalBytes\": \"" << group_metadata->total_byte_size() << "\", ";
305 stream << " \"TotalCompressedBytes\": \"" << group_metadata->total_compressed_size()
306 << "\", ";
307 auto row_group_sorting_columns = group_metadata->sorting_columns();
308 if (!row_group_sorting_columns.empty()) {
309 stream << " \"SortColumns\": [\n";
310 for (size_t i = 0; i < row_group_sorting_columns.size(); i++) {
311 stream << " {\"column_idx\": " << row_group_sorting_columns[i].column_idx

Callers 3

mainFunction · 0.80
ReadFromLocalFileMethod · 0.80
TESTFunction · 0.80

Calls 15

ParquetVersionToStringFunction · 0.85
ParquetExceptionFunction · 0.85
TypeToStringFunction · 0.85
ConvertedTypeToStringFunction · 0.85
FormatStatValueFunction · 0.85
AsciiToUpperFunction · 0.85
EncodingToStringFunction · 0.85
PrintPageEncodingStatsFunction · 0.85
push_backMethod · 0.80
ToDotStringMethod · 0.80
physical_typeMethod · 0.80
type_lengthMethod · 0.80

Tested by 2

ReadFromLocalFileMethod · 0.64
TESTFunction · 0.64