Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25212 +/- ##
==========================================
+ Coverage 81.88% 82.48% +0.60%
==========================================
Files 1133 1140 +7
Lines 424522 437681 +13159
Branches 424522 437681 +13159
==========================================
+ Hits 347623 361032 +13409
+ Misses 56285 54845 -1440
- Partials 20614 21804 +1190 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…istingTable Files written with `keep_partition_by_columns = true` physically contain the partition column. `ListingTable::try_new` appended the configured partition columns to the inferred file schema unconditionally, so the table schema listed the column twice and any query failed with "Schema contains duplicate qualified field name". The partition column now appears once, with the declared partition type, and its values come from the path, matching what CREATE EXTERNAL TABLE with an explicit column list already did. Closes apache#17420 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
b4e7b2c to
c4fdbdd
Compare
|
Hello @alamb, when you get a chance can you please review this PR? |
kosiew
left a comment
There was a problem hiding this comment.
Thanks for working on this. The fix looks good to me, and the regression coverage does a nice job covering both explicit and inferred Hive partition discovery. I just have one small suggestion to strengthen the unit coverage.
| .iter() | ||
| .enumerate() | ||
| .filter(|(_, field)| { | ||
| !options |
There was a problem hiding this comment.
Could we add a small unit case with two overlapping partition columns, with one of them appearing in the middle of the physical schema? It would be useful to assert that the final order has all remaining file fields first, followed by the partition fields in their configured order. The current single trailing-column case covers deduplication well, but does not exercise the projection and ordering behavior introduced by this filter.
There was a problem hiding this comment.
Thank you, added a test for two overlapping partition columns with one mid-schema.
Which issue does this PR close?
Rationale for this change
Parquet files written with
datafusion.execution.keep_partition_by_columns = truephysically contain the partition column. Reading them back as a hive-partitioned table then fails:DESCRIBE t2showsgrptwice: once with the type inferred from the files and once with the partition column type. The same error is hit withoutPARTITIONED BY(the factory infers hive partitions from the directory names by default) and when querying the directory path directly (SELECT * FROM '/tmp/out/').ListingTable::try_newunconditionally appends every configured partition column to the inferred file schema. When the file schema already has a field with that name, the table schema ends up with a duplicate.CREATE EXTERNAL TABLEwith an explicit column list already works because the factory projects the partition columns out of the provided schema; the inferred-schema path had no equivalent.What changes are included in this PR?
ListingTable::try_newnow drops any file-schema field whose name matches a configured partition column before appending the partition columns. The partition value continues to be read from the path and keeps the declared (or inferred) partition column type, matching the existing behaviour of the explicit-schema path. The trimmed schema is also whatcreate_file_sourceand the file-schema fingerprint use, so the physical scan and the table schema agree.What is the testing strategy for this PR?
test_partition_column_present_in_file_schema_is_not_duplicatedindatafusion/core/src/datasource/listing/table.rsbuilds aListingTablewhose file schema already contains the partition column and asserts the table schema lists it once, with the partition type. It failed before the fix with["a", "pid", "pid"].datafusion/sqllogictest/test_files/copy.sltreuse the existingkeep_partition_by_columnsoutput directory and create a table over the whole directory, once with an explicitPARTITIONED BYand once relying on partition inference. Both failed before the fix with the duplicate field error.parquet_overlapping_columnstest indatafusion/core/tests/sql/path_partition.rsasserted that a partition column sharing a name with a file column must raise an error. This PR intentionally changes that behaviour to match howCREATE EXTERNAL TABLEwith an explicit column list already handles the overlap. The test now asserts the new behaviour: the column appears once, with the partition type, and its values come from the path.Are there any user-facing changes?
Reading hive-partitioned Parquet data whose files also contain the partition column now works instead of raising a schema error.
Conflict policy, made explicit: when a file column and a partition column share a name, the partition column's path-derived value and declared type take precedence. The file column is ignored, and its values are not validated against the path value.
No API changes.
🤖 Generated with Claude Code