zhuqi-lucas opened a new pull request, #21756:
URL: https://github.com/apache/datafusion/pull/21756

   ## Which issue does this PR close?
   
   Closes #21755
   
   ## Rationale
   
   When a hive-partitioned listing table has files in the root directory (not 
inside any `partition_col=value/` path), queries that reference partition 
columns crash with `Unable to get field named "partition_col"`.
   
   This is a common scenario when a table transitions from non-partitioned to 
hive-partitioned storage — the original root file may still exist alongside the 
new partition directories.
   
   ## What changes are included in this PR?
   
   `try_into_partitioned_file` now returns `Ok(None)` for files that don't 
match the partition structure (where `parse_partitions_for_path` returns 
`None`). The caller skips them via `try_filter_map`.
   
   Previously, `None` from `parse_partitions_for_path` was converted to empty 
`partition_values` via `.into_iter().flatten()`, causing downstream errors.
   
   ## Are these changes tested?
   
   Yes, 5 unit tests added:
   - `test_try_into_partitioned_file_valid_partition` — normal case
   - `test_try_into_partitioned_file_root_file_skipped` — root file skipped
   - `test_try_into_partitioned_file_wrong_partition_name` — wrong partition 
col name
   - `test_try_into_partitioned_file_multiple_partitions` — multi-level 
partitions
   - `test_try_into_partitioned_file_partial_partition_skipped` — incomplete 
partition path
   
   ## Are there any user-facing changes?
   
   Files outside the hive partition structure are now silently skipped instead 
of causing query failures. This may change `COUNT(*)` results if such files 
previously contributed rows (with empty partition values).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to