Skip to content
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

Add Filter::try_new with validation #3796

Merged
merged 12 commits into from
Oct 12, 2022
Merged

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Oct 11, 2022

Which issue does this PR close?

Closes #3795

Rationale for this change

Filters should not use aliased expressions

What changes are included in this PR?

  • Implement Filter::try_new and make Filter attributes private to force the use of the constructor in other crates
  • Add accessor methods for Fitler attributes
  • Add check that filter predicate returns a boolean value
  • Remove aliases from filter predicate
  • Update all call sites
  • Update tests

Are there any user-facing changes?

Yes. Filter attributes are now pub(crate) but accessor methods have been added.

@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules sql SQL Planner labels Oct 11, 2022
@andygrove andygrove added the api change Changes the API exposed to users of the crate label Oct 11, 2022
@@ -580,12 +580,12 @@ mod tests {
let table_scan = test_table_scan()?;

let plan = LogicalPlanBuilder::from(table_scan)
.filter(col("c"))?
.filter(col("c").gt(lit(1)))?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was invalid and the new validation checks caught this.

@@ -1930,7 +1930,7 @@ mod tests {
assert_optimized_plan_eq(
&plan,
"\
Filter: test.b > Int32(1) AS test.b > Int32(1) AND test.b > Int32(1)\
Filter: test.b > Int32(1)\
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated tests here demonstrate that we no longer have aliases for filter predicates.

@andygrove andygrove marked this pull request as ready for review October 11, 2022 14:17
@andygrove andygrove changed the title WIP: Add Filter::try_new with validation Add Filter::try_new with validation Oct 11, 2022
@andygrove andygrove requested review from liukun4515 and alamb October 11, 2022 14:23
}
}

// filter predicates should not contain aliased expressions so we remove any aliases here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the rationale here that the the output of a FilterExpr has the same schema as its input -- since the Filter never changes its input if we find an alias on the FilterExpr then something is likely wrong as it won't change anything?

I would personally prefer to throw an error rather than stripping the aliases and then track down what is adding aliases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FilterExec::try_new now throws an exception when passed an aliased predicate and the rewrite logic has moved to utils::from_plan which is called from multiple optimizer rules

datafusion/expr/src/logical_plan/plan.rs Outdated Show resolved Hide resolved
@alamb
Copy link
Contributor

alamb commented Oct 11, 2022

The CI test is unrelated: #3798

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

datafusion/expr/src/logical_plan/plan.rs Outdated Show resolved Hide resolved
datafusion/expr/src/logical_plan/plan.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ship it!

@alamb alamb merged commit 3af09fb into apache:master Oct 12, 2022
@ursabot
Copy link

ursabot commented Oct 12, 2022

Benchmark runs are scheduled for baseline = e27e86b and contender = 3af09fb. 3af09fb is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter predicates should not be aliased
3 participants