You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/28 09:16:33 UTC
[GitHub] [arrow-datafusion] ygf11 opened a new pull request, #4760: Refactor extract_ join_keys and move the ExtractEquijoinPredicate rule
ygf11 opened a new pull request, #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #4759.
# Rationale for this change
The other rule will depend on `ExtractEquijoinPredicate`.
# What changes are included in this PR?
1. Refactor extract_join_keys with `split_conjunction`.
2. Move the `ExtractEquijoinPredicate` rule behind `SubqueryFilterToJoin`.
# Are these changes tested?
Yes.
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ygf11 commented on a diff in pull request #4760: Refactor extract_join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
ygf11 commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1059725865
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -387,4 +357,33 @@ mod tests {
assert_plan_eq(&plan, expected)
}
+
+ #[test]
+ fn join_with_alias_filter() -> Result<()> {
Review Comment:
Since we can't create a join whose condition is an alias a sql, I add a integration-test with dataframe api.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ygf11 commented on a diff in pull request #4760: Refactor extract_ join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
ygf11 commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1058874708
##########
datafusion/core/tests/sql/joins.rs:
##########
@@ -2452,29 +2452,29 @@ async fn both_side_expr_key_inner_join() -> Result<()> {
"ProjectionExec: expr=[t1_id@0 as t1_id, t2_id@2 as t2_id, t1_name@1 as t1_name]",
" ProjectionExec: expr=[t1_id@0 as t1_id, t1_name@1 as t1_name, t2_id@3 as t2_id]",
" CoalesceBatchesExec: target_batch_size=4096",
- " HashJoinExec: mode=Partitioned, join_type=Inner, on=[(Column { name: \"t1.t1_id + Int64(12)\", index: 2 }, Column { name: \"t2.t2_id + Int64(1)\", index: 1 })]",
+ " HashJoinExec: mode=Partitioned, join_type=Inner, on=[(Column { name: \"t1.t1_id + UInt32(12)\", index: 2 }, Column { name: \"t2.t2_id + UInt32(1)\", index: 1 })]",
" CoalesceBatchesExec: target_batch_size=4096",
- " RepartitionExec: partitioning=Hash([Column { name: \"t1.t1_id + Int64(12)\", index: 2 }], 2)",
- " ProjectionExec: expr=[t1_id@0 as t1_id, t1_name@1 as t1_name, t1_id@0 + CAST(12 AS UInt32) as t1.t1_id + Int64(12)]",
+ " RepartitionExec: partitioning=Hash([Column { name: \"t1.t1_id + UInt32(12)\", index: 2 }], 2)",
Review Comment:
After we move the `ExtractEquijoinPredicate` rule, the optimizer will
1. `Simplify` the expression.
2. Extract join keys from join filter.
Since the `ExtractEquijoinPredicate` can unalias the filter, the result is the same as #4755 now.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #4760: Refactor extract_ join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#issuecomment-1368211786
I will take a look this pr carefully tomorrow.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ygf11 commented on a diff in pull request #4760: Refactor extract_join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
ygf11 commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1059725865
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -387,4 +357,33 @@ mod tests {
assert_plan_eq(&plan, expected)
}
+
+ #[test]
+ fn join_with_alias_filter() -> Result<()> {
Review Comment:
Since we can't create a join whose condition is an alias in sql api, I add a test case with dataframe api.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4760: Refactor extract_ join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1059478596
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -17,13 +17,17 @@
//! Optimizer rule to extract equijoin expr from filter
use crate::optimizer::ApplyOrder;
+use crate::utils::split_conjunction;
use crate::{OptimizerConfig, OptimizerRule};
use datafusion_common::DFSchema;
use datafusion_common::Result;
use datafusion_expr::utils::{can_hash, find_valid_equijoin_key_pair};
use datafusion_expr::{BinaryExpr, Expr, ExprSchemable, Join, LogicalPlan, Operator};
use std::sync::Arc;
+// equijoin predicate
+type EquijoinPredicate = (Expr, Expr);
Review Comment:
❤️
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -100,30 +99,22 @@ impl OptimizerRule for ExtractEquijoinPredicate {
}
}
-/// Extracts equijoin ON condition be a single Eq or multiple conjunctive Eqs
-/// Filters matching this pattern are added to `accum`
-/// Filters that don't match this pattern are added to `accum_filter`
-/// Examples:
-/// ```text
-/// foo = bar => accum=[(foo, bar)] accum_filter=[]
-/// foo = bar AND bar = baz => accum=[(foo, bar), (bar, baz)] accum_filter=[]
-/// foo = bar AND baz > 1 => accum=[(foo, bar)] accum_filter=[baz > 1]
-///
-/// For equijoin join key, assume we have tables -- a(c0, c1 c2) and b(c0, c1, c2):
-/// (a.c0 = 10) => accum=[], accum_filter=[a.c0 = 10]
-/// (a.c0 + 1 = b.c0 * 2) => accum=[(a.c0 + 1, b.c0 * 2)], accum_filter=[]
-/// (a.c0 + b.c0 = 10) => accum=[], accum_filter=[a.c0 + b.c0 = 10]
-/// ```
-fn extract_join_keys(
- expr: Expr,
- accum: &mut Vec<(Expr, Expr)>,
- accum_filter: &mut Vec<Expr>,
+fn split_eq_and_noneq_join_predicate(
+ filter: &Expr,
left_schema: &Arc<DFSchema>,
right_schema: &Arc<DFSchema>,
-) -> Result<()> {
- match &expr {
- Expr::BinaryExpr(BinaryExpr { left, op, right }) => match op {
- Operator::Eq => {
+) -> Result<(Vec<EquijoinPredicate>, Option<Expr>)> {
Review Comment:
this is a much nicer interface 👍 for being self documenting
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on pull request #4760: Refactor extract_join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#issuecomment-1368447088
Thanks @ygf11 @jackwener and @liukun4515
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb merged pull request #4760: Refactor extract_join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
alamb merged PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ygf11 commented on a diff in pull request #4760: Refactor extract_ join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
ygf11 commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1058870767
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -387,4 +357,33 @@ mod tests {
assert_plan_eq(&plan, expected)
}
+
+ #[test]
+ fn join_with_alias_filter() -> Result<()> {
+ let t1 = test_table_scan_with_name("t1")?;
+ let t2 = test_table_scan_with_name("t2")?;
+
+ let t1_schema = t1.schema().clone();
+ let t2_schema = t2.schema().clone();
+
+ // filter: t1.a + CAST(Int64(1), UInt32) = t2.a + CAST(Int64(2), UInt32) as t1.a + 1 = t2.a + 2
+ let filter = Expr::eq(
+ col("t1.a") + lit(1i64).cast_to(&DataType::UInt32, &t1_schema)?,
+ col("t2.a") + lit(2i32).cast_to(&DataType::UInt32, &t2_schema)?,
+ )
+ .alias("t1.a + 1 = t2.a + 2");
+ let plan = LogicalPlanBuilder::from(t1)
Review Comment:
The `split_conjunction` will unalias the expr.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ygf11 commented on a diff in pull request #4760: Refactor extract_join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
ygf11 commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1059725865
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -387,4 +357,33 @@ mod tests {
assert_plan_eq(&plan, expected)
}
+
+ #[test]
+ fn join_with_alias_filter() -> Result<()> {
Review Comment:
Since we can't create a join whose condition is an alias in sql api, I add a integration-test with dataframe api.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ursabot commented on pull request #4760: Refactor extract_join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#issuecomment-1368448049
Benchmark runs are scheduled for baseline = 0d6d37103c152eaba3553280276d736c01f7a549 and contender = 93052cdf030a2084f4b902e06e997011fca0d466. 93052cdf030a2084f4b902e06e997011fca0d466 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/bfb66158965c4ea380d7d08d4870ab2d...1328a361ce3245bfaf691a79bbb1071b/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/4c7de62b6457495ba5bfc249f06d5019...98ae1528318c4c698aa0b9da0592666a/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/72126ff7aab1493b89ce7a61ecad93f3...cb01cbcd96d64088bfe0243d3f61ed96/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/20f8fe8bde78409582b4787c5b7eafbb...b5f076c5179a45aa86543aed7335b5d7/)
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
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #4760: Refactor extract_ join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1059363301
##########
datafusion/optimizer/src/optimizer.rs:
##########
@@ -237,12 +237,12 @@ impl Optimizer {
let rules: Vec<Arc<dyn OptimizerRule + Sync + Send>> = vec![
Arc::new(InlineTableScan::new()),
Arc::new(TypeCoercion::new()),
- Arc::new(ExtractEquijoinPredicate::new()),
Arc::new(SimplifyExpressions::new()),
Arc::new(UnwrapCastInComparison::new()),
Arc::new(DecorrelateWhereExists::new()),
Arc::new(DecorrelateWhereIn::new()),
Arc::new(ScalarSubqueryToJoin::new()),
+ Arc::new(ExtractEquijoinPredicate::new()),
Review Comment:
👍 related comments from https://github.com/apache/arrow-datafusion/pull/4711#discussion_r1057109998
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #4760: Refactor extract_ join_keys and move the ExtractEquijoinPredicate rule
Posted by GitBox <gi...@apache.org>.
jackwener commented on code in PR #4760:
URL: https://github.com/apache/arrow-datafusion/pull/4760#discussion_r1059657596
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -387,4 +357,33 @@ mod tests {
assert_plan_eq(&plan, expected)
}
+
+ #[test]
+ fn join_with_alias_filter() -> Result<()> {
Review Comment:
BTW, I recommend add a integration-test to show the plan after all rule optimize it.
##########
datafusion/optimizer/src/extract_equijoin_predicate.rs:
##########
@@ -387,4 +357,33 @@ mod tests {
assert_plan_eq(&plan, expected)
}
+
+ #[test]
+ fn join_with_alias_filter() -> Result<()> {
Review Comment:
👍
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org