diff --git a/cpp/src/parquet/printer.cc b/cpp/src/parquet/printer.cc index 4d2cb75b15e64..82029edcb208c 100644 --- a/cpp/src/parquet/printer.cc +++ b/cpp/src/parquet/printer.cc @@ -296,17 +296,18 @@ void ParquetFilePrinter::JSONPrint(std::ostream& stream, std::list selected << "\", "; auto row_group_sorting_columns = group_metadata->sorting_columns(); if (!row_group_sorting_columns.empty()) { - stream << " \"SortColumns\": ["; + stream << " \"SortColumns\": [\n"; for (size_t i = 0; i < row_group_sorting_columns.size(); i++) { - stream << "{\"column_idx\":" << row_group_sorting_columns[i].column_idx + stream << " {\"column_idx\":" << row_group_sorting_columns[i].column_idx << ", \"descending\":" << row_group_sorting_columns[i].descending << ", \"nulls_first\": " << row_group_sorting_columns[i].nulls_first << "}"; if (i + 1 != row_group_sorting_columns.size()) { - stream << ", "; + stream << ","; } + stream << '\n'; } - stream << "], "; + stream << " ], "; } stream << " \"Rows\": \"" << group_metadata->num_rows() << "\",\n"; diff --git a/cpp/src/parquet/reader_test.cc b/cpp/src/parquet/reader_test.cc index 688c875b9ec0f..df8c5c63bfeea 100644 --- a/cpp/src/parquet/reader_test.cc +++ b/cpp/src/parquet/reader_test.cc @@ -1180,6 +1180,16 @@ TEST_F(TestJSONWithLocalFile, JSONOutputFLBA) { EXPECT_THAT(json_content, testing::HasSubstr(json_contains)); } +TEST_F(TestJSONWithLocalFile, JSONOutputSortColumns) { + std::string json_content = ReadFromLocalFile("sort_columns.parquet"); + + std::string json_contains = R"###("SortColumns": [ + {"column_idx":0, "descending":1, "nulls_first": 1}, + {"column_idx":1, "descending":0, "nulls_first": 0} + ])###"; + EXPECT_THAT(json_content, testing::HasSubstr(json_contains)); +} + // GH-44101: Test that JSON output is valid JSON TEST_F(TestJSONWithLocalFile, ValidJsonOutput) { auto check_json_valid = [](std::string_view json_string) -> ::arrow::Status { @@ -1196,7 +1206,7 @@ TEST_F(TestJSONWithLocalFile, ValidJsonOutput) { std::vector check_file_lists = { "data_index_bloom_encoding_with_length.parquet", "data_index_bloom_encoding_stats.parquet", "alltypes_tiny_pages_plain.parquet", - "concatenated_gzip_members.parquet", "nulls.snappy.parquet"}; + "concatenated_gzip_members.parquet", "nulls.snappy.parquet", "sort_columns.parquet"}; for (const auto& file : check_file_lists) { std::string json_content = ReadFromLocalFile(file); ASSERT_OK(check_json_valid(json_content))