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/24 10:33:16 UTC
[GitHub] [arrow-datafusion] ygf11 opened a new pull request, #4725: Support non-tuple expression for subquery-filter to join optimizer
ygf11 opened a new pull request, #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725
# 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 #4724.
# Rationale for this change
Currently datafusion support rewrite in-subquery to join when the expression is a column, like:
```sql
> select * from t1 where t1_id in (select t2_id from t2);
```
but following sql does not works:
```sql
> select * from t1 where t1_id + 11 in (select t2_id from t2);
NotImplemented("Physical plan does not support logical expression CAST(t1.t1_id AS Int64) + Int64(11) IN (<subquery>)")
```
We can rewrite these subquery to join also.
# What changes are included in this PR?
In `SubqueryFilterToJoin`:
1. Rewrite `where x+1 in (...)` to equi-join.
2. Rewrite `where 1 in (..)` to non equi-join.
# 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 closed pull request #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
ygf11 closed pull request #4725: Support non-tuple expression for in-subquery to join
URL: https://github.com/apache/arrow-datafusion/pull/4725
--
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 pull request #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
jackwener commented on PR #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725#issuecomment-1365004741
> why not implement this in the rule `decorrelate_where_in.rs`?
>
> The two rule of `decorrelate_where_in.rs` and `subquery_filter_to_join.rs` implement the same function, and convert the `in query` to Join. Maybe we can reduce the duplicate code and reduce the rule. cc @jackwener
Yes, I add it in new PR https://github.com/apache/arrow-datafusion/pull/4731
--
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 #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
jackwener commented on code in PR #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725#discussion_r1056956986
##########
datafusion/optimizer/src/subquery_filter_to_join.rs:
##########
@@ -108,13 +107,17 @@ impl OptimizerRule for SubqueryFilterToJoin {
};
let right_key = right_schema.field(0).qualified_column();
- let left_key = match *expr.clone() {
- Expr::Column(col) => col,
- _ => return Err(DataFusionError::NotImplemented(
- "Filtering by expression not implemented for InSubquery"
- .to_string(),
- )),
- };
+ let left_key = *expr.clone();
+ let (on, filter) =
+ // When left is a constant expression, like 1,
+ // the join predicate will be `1 = right_key`, it is better to add it to filter.
+ if left_key.to_columns()?.is_empty() {
+ let equi_expr =
+ Expr::eq(*expr.clone(), Expr::Column(right_key));
+ (vec![], Some(equi_expr))
+ } else {
Review Comment:
IMHO, I think it's a good improvement but maybe isn't suitable to put in this rule.🤔
It could be better to handle separate/handle `on/joinfilter` in a new rule(we also can add more improvement in it).
Just a thought, I think we also can add a TODO, and handle them as a future ticket.
--
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 #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
ygf11 commented on code in PR #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725#discussion_r1057088599
##########
datafusion/optimizer/src/subquery_filter_to_join.rs:
##########
@@ -108,13 +107,17 @@ impl OptimizerRule for SubqueryFilterToJoin {
};
let right_key = right_schema.field(0).qualified_column();
- let left_key = match *expr.clone() {
- Expr::Column(col) => col,
- _ => return Err(DataFusionError::NotImplemented(
- "Filtering by expression not implemented for InSubquery"
- .to_string(),
- )),
- };
+ let left_key = *expr.clone();
+ let (on, filter) =
+ // When left is a constant expression, like 1,
+ // the join predicate will be `1 = right_key`, it is better to add it to filter.
+ if left_key.to_columns()?.is_empty() {
+ let equi_expr =
+ Expr::eq(*expr.clone(), Expr::Column(right_key));
+ (vec![], Some(equi_expr))
+ } else {
Review Comment:
> It could be better to handle separate/handle on/joinfilter in a new rule(we also can add more improvement in it).
Agree.
There is another pr #4711 which will separate equi and non-equi predicate from filter.
We can add the `left-key = right-key` to join-filter in this rule, and let the other rule do the separating works.
--
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] Jefffrey commented on pull request #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
Jefffrey commented on PR #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725#issuecomment-1364736481
> A great improvement to me.+1 Thanks @Jefffrey
Got the wrong person :laughing:
--
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 pull request #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
ygf11 commented on PR #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725#issuecomment-1365068249
Close this pr, and I will submit a new pr based on `DecorrelateWhereIn` rule.
--
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 #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
jackwener commented on code in PR #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725#discussion_r1056956206
##########
datafusion/core/tests/sql/joins.rs:
##########
@@ -2837,3 +2837,96 @@ async fn type_coercion_join_with_filter_and_equi_expr() -> Result<()> {
Ok(())
}
+
+#[tokio::test]
+async fn reduce_where_in_to_expr_equijoin() -> Result<()> {
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
Review Comment:
👍
##########
datafusion/optimizer/src/subquery_filter_to_join.rs:
##########
@@ -108,13 +107,17 @@ impl OptimizerRule for SubqueryFilterToJoin {
};
let right_key = right_schema.field(0).qualified_column();
- let left_key = match *expr.clone() {
- Expr::Column(col) => col,
- _ => return Err(DataFusionError::NotImplemented(
- "Filtering by expression not implemented for InSubquery"
- .to_string(),
- )),
- };
+ let left_key = *expr.clone();
+ let (on, filter) =
+ // When left is a constant expression, like 1,
+ // the join predicate will be `1 = right_key`, it is better to add it to filter.
+ if left_key.to_columns()?.is_empty() {
+ let equi_expr =
+ Expr::eq(*expr.clone(), Expr::Column(right_key));
+ (vec![], Some(equi_expr))
+ } else {
Review Comment:
IMHO, I think it's a good improvement but maybe isn't suitable to put in this rule.🤔
It could be better to handle separate/handle `on/joinfilter` in a new rule(I also contain more improvement).
Just a thought, I think we also can add a TODO, and handle them as a future ticket.
--
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 #4725: Support non-tuple expression for in-subquery to join
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #4725:
URL: https://github.com/apache/arrow-datafusion/pull/4725#issuecomment-1364999536
why not implement this in the rule `decorrelate_where_in.rs`?
The two rule of `decorrelate_where_in.rs` and `subquery_filter_to_join.rs` implement the same function, and convert the `in query` to Join. Maybe we can reduce the duplicate code and reduce the rule. cc @jackwener
--
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