Skip to content

GH-47189: [C++][Parquet] Fix ParquetFilePrinter to produce valid JSON statistics - #47190

Merged
wgtmac merged 3 commits into
apache:mainfrom
wgtmac:fix_json_stats
Aug 4, 2025
Merged

wgtmac merged 3 commits into
apache:mainfrom
wgtmac:fix_json_stats

Conversation

@wgtmac

@wgtmac wgtmac commented Jul 25, 2025 •

Copy link
Copy Markdown
Member

Rationale for this change

ParquetFilePrinter uses FormatStatValue to print min/max stats. If stats contain non-UTF8 data, produced JSON is invalid.

What changes are included in this PR?

Make FormatStatValue aware of logical type and print hex values for binary data.

Are these changes tested?

Added test case to validate json output.

Are there any user-facing changes?

Yes, users may see hex values for binary values instead of char values in the past.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #47189 has been automatically assigned in GitHub to PR creator.

@wgtmac

wgtmac commented Jul 25, 2025

Copy link
Copy Markdown
Member Author

Current output:

{
  "FileName": "No Name",
  "Version": "2.6",
  "CreatedBy": "parquet-cpp-arrow version 22.0.0-SNAPSHOT",
  "TotalRows": "4",
  "NumberOfRowGroups": "1",
  "NumberOfRealColumns": "2",
  "NumberOfColumns": "2",
  "Columns": [
     { "Id": "0", "Name": "string_field", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "UTF8", "LogicalType": {"Type": "String"} },
     { "Id": "1", "Name": "binary_field", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} }
  ],
  "RowGroups": [
     {
       "Id": "0",  "TotalBytes": "143",  "TotalCompressedBytes": "143",  "Rows": "4",
       "ColumnChunks": [
          {"Id": "0", "Values": "4", "StatsSet": "True", "Stats": {"NumNulls": "0", "Max": "🌟", "Min": "Hello" },
           "Compression": "UNCOMPRESSED", "Encodings": "PLAIN(DICT_PAGE) RLE_DICTIONARY", "UncompressedSize": "76", "CompressedSize": "76", "ColumnIndex": {"offset": "147", "length": "24"}, "OffsetIndex": {"offset": "194", "length": "13"} },
          {"Id": "1", "Values": "4", "StatsSet": "True", "Stats": {"NumNulls": "0", "Max": "0xfffefdfc", "Min": "0x00010203" },
           "Compression": "UNCOMPRESSED", "Encodings": "PLAIN(DICT_PAGE) RLE_DICTIONARY", "UncompressedSize": "67", "CompressedSize": "67", "ColumnIndex": {"offset": "171", "length": "23"}, "OffsetIndex": {"offset": "207", "length": "14"} }
        ]
     }
  ]
}

Before:

{
  "FileName": "No Name",
  "Version": "2.6",
  "CreatedBy": "parquet-cpp-arrow version 22.0.0-SNAPSHOT",
  "TotalRows": "4",
  "NumberOfRowGroups": "1",
  "NumberOfRealColumns": "2",
  "NumberOfColumns": "2",
  "Columns": [
     { "Id": "0", "Name": "string_field", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "UTF8", "LogicalType": {"Type": "String"} },
     { "Id": "1", "Name": "binary_field", "PhysicalType": "BYTE_ARRAY", "ConvertedType": "NONE", "LogicalType": {"Type": "None"} }
  ],
  "RowGroups": [
     {
       "Id": "0",  "TotalBytes": "143",  "TotalCompressedBytes": "143",  "Rows": "4",
       "ColumnChunks": [
          {"Id": "0", "Values": "4", "StatsSet": "True", "Stats": {"NumNulls": "0", "Max": "🌟", "Min": "Hello" },
           "Compression": "UNCOMPRESSED", "Encodings": "PLAIN(DICT_PAGE) RLE_DICTIONARY", "UncompressedSize": "76", "CompressedSize": "76", "ColumnIndex": {"offset": "147", "length": "24"}, "OffsetIndex": {"offset": "194", "length": "13"} },
          {"Id": "1", "Values": "4", "StatsSet": "True", "Stats": {"NumNulls": "0", "Max": "����", "Min": "\0" },
           "Compression": "UNCOMPRESSED", "Encodings": "PLAIN(DICT_PAGE) RLE_DICTIONARY", "UncompressedSize": "67", "CompressedSize": "67", "ColumnIndex": {"offset": "171", "length": "23"}, "OffsetIndex": {"offset": "207", "length": "14"} }
        ]
     }
  ]
}

@wgtmac

wgtmac commented Jul 25, 2025

Copy link
Copy Markdown
Member Author

cc @raulcd This might affect your changes on stats.

@mapleFU
mapleFU self-requested a review July 29, 2025 15:25
Comment thread cpp/src/parquet/types.h Resolved
Comment thread cpp/src/parquet/types.cc Outdated
std::memcpy(&value, bytes, sizeof(bool));
result << value;
break;
return FormatNumericValue<bool>(val);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is bool numeric value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about an extra << boolalpha ? I think using numeric here is too C-style...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Let me revert this.

Comment thread cpp/src/parquet/types.cc
Comment on lines +186 to +188
if (logical_type != nullptr && logical_type->is_decimal()) {
return FormatDecimalValue(parquet_type, val, logical_type);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this duplicate with L175?

@wgtmac wgtmac Jul 30, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I forgot to clean up these duplicate lines.

Comment thread cpp/src/parquet/types.cc Resolved
Comment thread cpp/src/parquet/types.cc
Comment on lines +114 to +115
const std::shared_ptr<const LogicalType>& logical_type) {
ARROW_DCHECK(logical_type != nullptr && logical_type->is_decimal());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can pass in argument just be const DecimalLogicalType&? ( Current also LGTM)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the caller needs to check nullability.

Comment thread cpp/src/parquet/types.cc
}
if (logical_type->is_string()) {
return std::string(val);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about fp16?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. I think we are still missing format functions for other logical types like timestamp, geometry, etc. We can add them as needed.

@mapleFU mapleFU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good begining for prining specific values!

@wgtmac
wgtmac merged commit 19f3b85 into apache:main Aug 4, 2025
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 19f3b85.

There weren't enough matching historic benchmark results to make a call on whether there were regressions.

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants