-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix query results for predicates referencing partition columns and data columns #15935
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,6 +299,7 @@ struct PushdownChecker<'schema> { | |
non_primitive_columns: bool, | ||
/// Does the expression reference any columns that are in the table | ||
/// schema but not in the file schema? | ||
/// This includes partition columns and projected columns. | ||
projected_columns: bool, | ||
// Indices into the table schema of the columns required to evaluate the expression | ||
required_columns: BTreeSet<usize>, | ||
|
@@ -387,13 +388,12 @@ fn would_column_prevent_pushdown(column_name: &str, table_schema: &Schema) -> bo | |
/// Otherwise, true. | ||
pub fn can_expr_be_pushed_down_with_schemas( | ||
expr: &datafusion_expr::Expr, | ||
_file_schema: &Schema, | ||
table_schema: &Schema, | ||
file_schema: &Schema, | ||
) -> bool { | ||
let mut can_be_pushed = true; | ||
expr.apply(|expr| match expr { | ||
datafusion_expr::Expr::Column(column) => { | ||
can_be_pushed &= !would_column_prevent_pushdown(column.name(), table_schema); | ||
can_be_pushed &= !would_column_prevent_pushdown(column.name(), file_schema); | ||
Ok(if can_be_pushed { | ||
TreeNodeRecursion::Jump | ||
} else { | ||
|
@@ -649,8 +649,6 @@ mod test { | |
|
||
#[test] | ||
fn nested_data_structures_prevent_pushdown() { | ||
let table_schema = get_basic_table_schema(); | ||
|
||
let file_schema = Schema::new(vec![Field::new( | ||
"list_col", | ||
DataType::Struct(Fields::empty()), | ||
|
@@ -659,49 +657,31 @@ mod test { | |
|
||
let expr = col("list_col").is_not_null(); | ||
|
||
assert!(!can_expr_be_pushed_down_with_schemas( | ||
&expr, | ||
&file_schema, | ||
&table_schema | ||
)); | ||
assert!(!can_expr_be_pushed_down_with_schemas(&expr, &file_schema,)); | ||
} | ||
|
||
#[test] | ||
fn projected_columns_prevent_pushdown() { | ||
let table_schema = get_basic_table_schema(); | ||
|
||
fn projected_or_partition_columns_prevent_pushdown() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test actually tests for this... except that since both schemas were being passed in it hit the bug as well. |
||
let file_schema = | ||
Schema::new(vec![Field::new("existing_col", DataType::Int64, true)]); | ||
|
||
let expr = col("nonexistent_column").is_null(); | ||
|
||
assert!(!can_expr_be_pushed_down_with_schemas( | ||
&expr, | ||
&file_schema, | ||
&table_schema | ||
)); | ||
assert!(!can_expr_be_pushed_down_with_schemas(&expr, &file_schema,)); | ||
} | ||
|
||
#[test] | ||
fn basic_expr_doesnt_prevent_pushdown() { | ||
let table_schema = get_basic_table_schema(); | ||
|
||
let file_schema = | ||
Schema::new(vec![Field::new("string_col", DataType::Utf8, true)]); | ||
|
||
let expr = col("string_col").is_null(); | ||
|
||
assert!(can_expr_be_pushed_down_with_schemas( | ||
&expr, | ||
&file_schema, | ||
&table_schema | ||
)); | ||
assert!(can_expr_be_pushed_down_with_schemas(&expr, &file_schema,)); | ||
} | ||
|
||
#[test] | ||
fn complex_expr_doesnt_prevent_pushdown() { | ||
let table_schema = get_basic_table_schema(); | ||
|
||
let file_schema = Schema::new(vec![ | ||
Field::new("string_col", DataType::Utf8, true), | ||
Field::new("bigint_col", DataType::Int64, true), | ||
|
@@ -711,23 +691,6 @@ mod test { | |
.is_not_null() | ||
.or(col("bigint_col").gt(Expr::Literal(ScalarValue::Int64(Some(5))))); | ||
|
||
assert!(can_expr_be_pushed_down_with_schemas( | ||
&expr, | ||
&file_schema, | ||
&table_schema | ||
)); | ||
} | ||
|
||
fn get_basic_table_schema() -> Schema { | ||
let testdata = datafusion_common::test_util::parquet_test_data(); | ||
let file = std::fs::File::open(format!("{testdata}/alltypes_plain.parquet")) | ||
.expect("opening file"); | ||
|
||
let reader = SerializedFileReader::new(file).expect("creating reader"); | ||
|
||
let metadata = reader.metadata(); | ||
|
||
parquet_to_arrow_schema(metadata.file_metadata().schema_descr(), None) | ||
.expect("parsing schema") | ||
assert!(can_expr_be_pushed_down_with_schemas(&expr, &file_schema,)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm a bit confused, as we talked like
"keep supports_filters_pushdown so that TableProviders can do Exact pruning of filters, e.g. using partition columns.",
and that is making sense to me now. So, instead, should we pass only table_schema's to these
supports_filters_pushdown()
API's at ListingTable level? Theory and practice conflict in my mind nowThere 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.
We could! But we'd do that in #15769 right?
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.
It doesn't change any API?
I mean can we remove
file_schema: &Schema
ortable_schema: &Schema
from thesesupports_filters_pushdown()
API's? If we can, which one should we remove? In this PR, the fix shows that we utilizefile_schema: &Schema
, however, what I understand from that conversation is we should depend ontable_schema: &Schema
, notfile_schema: &Schema
. That's what confuses meUh oh!
There was an error while loading. Please reload this page.
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.
Well keep only the table_schema. This fix (this PR) becomes irrelevant once we merge the other one. But since that may take longer I thought it was best to make this PR as a simpler fix and not mix together a bug fix and larger change. Helps others who have forks copy the change, etc.