-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix NameMapping loss in ParquetUtil.footerMetrics #14617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When footerMetrics was called with a NameMapping, it correctly applied the mapping to get field IDs but then passed the wrong MessageType to ParquetMetrics.metrics, causing the IDs to be lost. This resulted in empty metrics for Parquet files without embedded field IDs. Fixed by passing parquetTypeWithIds instead of the original messageType.
| .optionalString("data") | ||
| .endRecord(); | ||
|
|
||
| ParquetWriter<GenericData.Record> writer = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can use try-with-resource here too.
| .endRecord(); | ||
|
|
||
| ParquetWriter<GenericData.Record> writer = | ||
| AvroParquetWriter.<GenericData.Record>builder(new org.apache.hadoop.fs.Path(file.toURI())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builder(Path file) is deprecated. Can we builder(OutputFile file) instead? You can refer to #14620
| reader.getFooter(), Stream.empty(), MetricsConfig.getDefault(), nameMapping); | ||
|
|
||
| // The key assertion: column sizes should be keyed by field IDs from NameMapping | ||
| assertThat(metrics.columnSizes()).containsKeys(1, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion passes even when the metrics.columnSizes() contains additional keys. Could you use containsOnlyKeys instead?
huaxingao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks @tmater for the PR. Thanks @ebyhr @nandorKollar for the review! |
|
Thanks @huaxingao , @nandorKollar, @ebyhr for the review! |
Fix NameMapping loss in ParquetUtil.footerMetrics
Summary
Fixed a bug where
ParquetUtil.footerMetricswas losing field IDs when using NameMapping, resulting in empty metrics for Parquet files without embedded field IDs.Background
When
footerMetricsis called with a NameMapping, it applies the mapping to get field IDs viagetParquetTypeWithIds(), but then passed the original MessageType toParquetMetrics.metrics. Later in themetrics()call, field IDs are extracted from the MessageType viatype.getColumnDescription().getPrimitiveType().getId(), which returns null for the original MessageType without IDs, causing all metrics to be skipped.Changes
parquetTypeWithIdstoParquetMetrics.metricsto preserve field IDs from NameMappingmessageTypevariableTesting
testFooterMetricsWithNameMappingForFileWithoutIdsthat verifies metrics are keyed by field IDs from NameMapping