You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What happened:
With Datafusion, when filtering a table on a non-partition column in a partitioned table leads to unexpected results or errors, when partition columns are defined "first" in schema.
What you expected to happen:
Expected filter to work on non-partition column correctly.
How to reproduce it:
Wrote this test. This fails because it is treating value (not partitioned as the part column Dict(UInt16, Int32) instead of Int32.
More details:
This seems to be happening because in the DataFusion scan, the FileScanConfig's FileSchema is built from non-partition cols and partition cols are provided as table_partition_cols. This is expected but the projection pass to FileScanConfig is not updated to account for this.
See the doc for projection on FileScanConfig:
/// Columns on which to project the data. Indexes that are higher than the
/// number of columns of `file_schema` refer to `table_partition_cols`.
Basically update the projection to use the indexes into file_schema + table_partition_cols.
This assumes the projection indexes are from schema.field() which it looks like it is up the stack in datafusion.
Making this change does fix the example tests but breaks test_datafusion_partitioned_types because the column output ordering is different.
I can dig in further and submit a PR (if something like this is the correct fix) once I go through my company's open source contribution policy.
The text was updated successfully, but these errors were encountered:
Generally speaking we are very happy about every contribution! On first glance it seems that you already narrowed down the source of the error, and more generally I "fear" we have to do some internal schema shenanigans anyhow, to account for potential differences in data types. i.e. the delta spec does not cover the entire range of types in parquet / arrow.
So while I generally hope we can leave as much of the schema handling to datafusion, we may have to manually interfere...
LEt me know If you want to / can take this on, otherwise I'll have a closer look soon.
Alternative and perhaps safer then changing the projection is to change TableProvider.schema impl for DeltaTable to provide the columns in the order expected by DataFusion, i.e. table partition cols at the end.
This also doesn't break test_datafusion_partitioned_types which also asserts already the schema on the collected record batches is ordered with partition cols last.
fnschema(&self) -> Arc<ArrowSchema>{let orig_schema = <ArrowSchemaasTryFrom<&schema::Schema>>::try_from(DeltaTable::schema(self).unwrap(),).unwrap();// DataFusion projection expects partition cols at end of schemalet table_partition_cols = self.get_metadata().unwrap().partition_columns.clone();let file_schema = orig_schema.fields().iter().filter(|f| !table_partition_cols.contains(f.name()));let partition_schema = orig_schema.fields().iter().filter(|f| table_partition_cols.contains(f.name()));let new_schema = ArrowSchema::new(file_schema.chain(partition_schema).cloned().collect::<Vec<_>>());Arc::new(new_schema)}
Environment
Delta-rs version: 0.7.0
Binding: Rust
Environment:
Bug
What happened:
With Datafusion, when filtering a table on a non-partition column in a partitioned table leads to unexpected results or errors, when partition columns are defined "first" in schema.
What you expected to happen:
Expected filter to work on non-partition column correctly.
How to reproduce it:
Wrote this test. This fails because it is treating value (not partitioned as the part column Dict(UInt16, Int32) instead of Int32.
More details:
This seems to be happening because in the DataFusion scan, the FileScanConfig's FileSchema is built from non-partition cols and partition cols are provided as table_partition_cols. This is expected but the projection pass to FileScanConfig is not updated to account for this.
See the doc for projection on FileScanConfig:
As a quick fix I added this to the scan:
Basically update the projection to use the indexes into file_schema + table_partition_cols.
This assumes the projection indexes are from
schema.field()
which it looks like it is up the stack in datafusion.Making this change does fix the example tests but breaks
test_datafusion_partitioned_types
because the column output ordering is different.I can dig in further and submit a PR (if something like this is the correct fix) once I go through my company's open source contribution policy.
The text was updated successfully, but these errors were encountered: