Skip to content

Commit

Permalink
add testing, and format json output
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Nov 8, 2024
1 parent 2f13b2a commit 4aaa382
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions cpp/src/parquet/printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,18 @@ void ParquetFilePrinter::JSONPrint(std::ostream& stream, std::list<int> 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";

Expand Down
12 changes: 11 additions & 1 deletion cpp/src/parquet/reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -1196,7 +1206,7 @@ TEST_F(TestJSONWithLocalFile, ValidJsonOutput) {
std::vector<std::string_view> 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))
Expand Down

0 comments on commit 4aaa382

Please sign in to comment.