You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Ted-Jiang (via GitHub)" <gi...@apache.org> on 2024/01/10 10:12:44 UTC
[PR] [Minor] extract const and add doc for in_list pruning [arrow-datafusion]
Ted-Jiang opened a new pull request, #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815
## 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 #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## 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
Re: [PR] [Minor] extract const and add doc for in_list pruning [arrow-datafusion]
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang commented on code in PR #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815#discussion_r1447167949
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1958,6 +1964,90 @@ mod tests {
Ok(())
}
+ #[test]
+ fn row_group_predicate_between() -> Result<()> {
Review Comment:
Add some test case.
```
ID IN (46402206,
201143645,
1147370581,
....
242375670,
38453705)
```
Before found `MAX_LIST_VALUE_SIZE_REWRITE ` I though this filter not push down is wrong 😭
--
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
Re: [PR] [Minor] extract const and add doc and more tests for in_list pruning [arrow-datafusion]
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang commented on code in PR #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815#discussion_r1448203774
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1958,6 +1964,90 @@ mod tests {
Ok(())
}
+ #[test]
+ fn row_group_predicate_between() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+
+ // test c1 BETWEEN 1 AND 5
+ let expr1 = Expr::Between(Between {
+ expr: Box::new(col("c1")),
+ negated: false,
+ low: Box::new(lit(1)),
+ high: Box::new(lit(5)),
+ });
Review Comment:
thanks!
--
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
Re: [PR] [Minor] extract const and add doc for in_list pruning [arrow-datafusion]
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang commented on code in PR #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815#discussion_r1447160948
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -926,11 +926,15 @@ fn build_is_null_column_expr(
}
}
+const MAX_LIST_VALUE_SIZE_REWRITE: usize = 20;
+
/// Translate logical filter expression into pruning predicate
/// expression that will evaluate to FALSE if it can be determined no
/// rows between the min/max values could pass the predicates.
///
/// Returns the pruning predicate as an [`PhysicalExpr`]
+///
+/// Notice: For [`InListExpr`] if in list values more than 20, it will be rewritten to TRUE
Review Comment:
Extract const and add explain for `InListExpr ` ,
--
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
Re: [PR] [Minor] extract const and add doc for in_list pruning [arrow-datafusion]
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang commented on code in PR #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815#discussion_r1447167949
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1958,6 +1964,90 @@ mod tests {
Ok(())
}
+ #[test]
+ fn row_group_predicate_between() -> Result<()> {
Review Comment:
Add some test case. because found
```
ID IN (46402206,
201143645,
1147370581,
....
242375670,
38453705)
```
Before found `MAX_LIST_VALUE_SIZE_REWRITE ` I though this filter not push down is wrong 😭
--
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
Re: [PR] [Minor] extract const and add doc for in_list pruning [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815#discussion_r1447892406
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1958,6 +1964,90 @@ mod tests {
Ok(())
}
+ #[test]
+ fn row_group_predicate_between() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+
+ // test c1 BETWEEN 1 AND 5
+ let expr1 = Expr::Between(Between {
+ expr: Box::new(col("c1")),
+ negated: false,
+ low: Box::new(lit(1)),
+ high: Box::new(lit(5)),
+ });
+
+ // test 1 <= c1 <= 5
+ let expr2 = col("c1").gt_eq(lit(1)).and(col("c1").lt_eq(lit(5)));
+
+ let predicate_expr1 =
+ test_build_predicate_expression(&expr1, &schema, &mut RequiredColumns::new());
+
+ let predicate_expr2 =
+ test_build_predicate_expression(&expr2, &schema, &mut RequiredColumns::new());
+ assert_eq!(predicate_expr1.to_string(), predicate_expr2.to_string());
+
+ Ok(())
+ }
+
+ #[test]
+ fn row_group_predicate_between_with_in_list() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+ // test c1 in(1, 2)
+ let expr1 = Expr::InList(InList::new(
Review Comment:
Could potentially use https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html#method.in_list
```rust
expr1 = col("cl").in_list(vec![lit(1), lit(2)], false)
```
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1958,6 +1964,90 @@ mod tests {
Ok(())
}
+ #[test]
+ fn row_group_predicate_between() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+
+ // test c1 BETWEEN 1 AND 5
+ let expr1 = Expr::Between(Between {
+ expr: Box::new(col("c1")),
+ negated: false,
+ low: Box::new(lit(1)),
+ high: Box::new(lit(5)),
+ });
Review Comment:
You could also use `between` to make this more concise: https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html#method.between like:
```suggestion
let expr1 = col("c1").between(lit(1), lit(5));
```
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -960,7 +964,9 @@ fn build_predicate_expression(
}
}
if let Some(in_list) = expr_any.downcast_ref::<phys_expr::InListExpr>() {
- if !in_list.list().is_empty() && in_list.list().len() < 20 {
+ if !in_list.list().is_empty()
+ && in_list.list().len() <= MAX_LIST_VALUE_SIZE_REWRITE
Review Comment:
👍
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1958,6 +1964,90 @@ mod tests {
Ok(())
}
+ #[test]
+ fn row_group_predicate_between() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+
+ // test c1 BETWEEN 1 AND 5
+ let expr1 = Expr::Between(Between {
+ expr: Box::new(col("c1")),
+ negated: false,
+ low: Box::new(lit(1)),
+ high: Box::new(lit(5)),
+ });
+
+ // test 1 <= c1 <= 5
+ let expr2 = col("c1").gt_eq(lit(1)).and(col("c1").lt_eq(lit(5)));
+
+ let predicate_expr1 =
+ test_build_predicate_expression(&expr1, &schema, &mut RequiredColumns::new());
+
+ let predicate_expr2 =
+ test_build_predicate_expression(&expr2, &schema, &mut RequiredColumns::new());
+ assert_eq!(predicate_expr1.to_string(), predicate_expr2.to_string());
+
+ Ok(())
+ }
+
+ #[test]
+ fn row_group_predicate_between_with_in_list() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+ // test c1 in(1, 2)
+ let expr1 = Expr::InList(InList::new(
+ Box::new(col("c1")),
+ vec![lit(1), lit(2)],
+ false,
+ ));
+
+ // test c2 BETWEEN 4 AND 5
+ let expr2 = Expr::Between(Between {
+ expr: Box::new(col("c2")),
+ negated: false,
+ low: Box::new(lit(4)),
+ high: Box::new(lit(5)),
+ });
+
+ // test c1 in(1, 2) and c2 BETWEEN 4 AND 5
+ let expr3 = Expr::BinaryExpr(BinaryExpr {
+ left: Box::new(expr1),
+ op: Operator::And,
+ right: Box::new(expr2),
+ });
+
+ let expected_expr = "(c1_min@0 <= 1 AND 1 <= c1_max@1 OR c1_min@0 <= 2 AND 2 <= c1_max@1) AND c2_max@2 >= 4 AND c2_min@3 <= 5";
+ let predicate_expr =
+ test_build_predicate_expression(&expr3, &schema, &mut RequiredColumns::new());
+ assert_eq!(predicate_expr.to_string(), expected_expr);
+
+ Ok(())
+ }
+
+ #[test]
+ fn row_group_predicate_in_list_to_many_values() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("c1", DataType::Int32, false)]);
+ // test c1 in(1..21)
+ // in pruning.rs has MAX_LIST_VALUE_SIZE_REWRITE = 20, more than this value will be rewrite
Review Comment:
👍
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -926,11 +926,15 @@ fn build_is_null_column_expr(
}
}
+const MAX_LIST_VALUE_SIZE_REWRITE: usize = 20;
Review Comment:
```suggestion
/// The maximum number of entries in an `InList` that might be rewritten into
/// an OR chain
const MAX_LIST_VALUE_SIZE_REWRITE: usize = 20;
```
--
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
Re: [PR] [Minor] extract const and add more tests for in_list pruning [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815#discussion_r1447899528
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -926,11 +926,15 @@ fn build_is_null_column_expr(
}
}
+const MAX_LIST_VALUE_SIZE_REWRITE: usize = 20;
+
/// Translate logical filter expression into pruning predicate
/// expression that will evaluate to FALSE if it can be determined no
/// rows between the min/max values could pass the predicates.
///
/// Returns the pruning predicate as an [`PhysicalExpr`]
+///
+/// Notice: For [`phys_expr::InListExpr`] if in list values more than 20, it will be rewritten to TRUE
Review Comment:
```suggestion
/// Notice: Does not handle [`phys_expr::InListExpr`] greater than 20, which will be rewritten to TRUE
```
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1958,6 +1964,90 @@ mod tests {
Ok(())
}
+ #[test]
+ fn row_group_predicate_between() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+
+ // test c1 BETWEEN 1 AND 5
+ let expr1 = Expr::Between(Between {
+ expr: Box::new(col("c1")),
+ negated: false,
+ low: Box::new(lit(1)),
+ high: Box::new(lit(5)),
+ });
+
+ // test 1 <= c1 <= 5
+ let expr2 = col("c1").gt_eq(lit(1)).and(col("c1").lt_eq(lit(5)));
+
+ let predicate_expr1 =
+ test_build_predicate_expression(&expr1, &schema, &mut RequiredColumns::new());
+
+ let predicate_expr2 =
+ test_build_predicate_expression(&expr2, &schema, &mut RequiredColumns::new());
+ assert_eq!(predicate_expr1.to_string(), predicate_expr2.to_string());
+
+ Ok(())
+ }
+
+ #[test]
+ fn row_group_predicate_between_with_in_list() -> Result<()> {
+ let schema = Schema::new(vec![
+ Field::new("c1", DataType::Int32, false),
+ Field::new("c2", DataType::Int32, false),
+ ]);
+ // test c1 in(1, 2)
+ let expr1 = Expr::InList(InList::new(
+ Box::new(col("c1")),
+ vec![lit(1), lit(2)],
+ false,
+ ));
+
+ // test c2 BETWEEN 4 AND 5
+ let expr2 = Expr::Between(Between {
+ expr: Box::new(col("c2")),
+ negated: false,
+ low: Box::new(lit(4)),
+ high: Box::new(lit(5)),
+ });
+
+ // test c1 in(1, 2) and c2 BETWEEN 4 AND 5
+ let expr3 = Expr::BinaryExpr(BinaryExpr {
+ left: Box::new(expr1),
+ op: Operator::And,
+ right: Box::new(expr2),
+ });
+
+ let expected_expr = "(c1_min@0 <= 1 AND 1 <= c1_max@1 OR c1_min@0 <= 2 AND 2 <= c1_max@1) AND c2_max@2 >= 4 AND c2_min@3 <= 5";
+ let predicate_expr =
+ test_build_predicate_expression(&expr3, &schema, &mut RequiredColumns::new());
+ assert_eq!(predicate_expr.to_string(), expected_expr);
+
+ Ok(())
+ }
+
+ #[test]
+ fn row_group_predicate_in_list_to_many_values() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("c1", DataType::Int32, false)]);
+ // test c1 in(1..21)
+ // in pruning.rs has MAX_LIST_VALUE_SIZE_REWRITE = 20, more than this value will be rewrite
Review Comment:
It is good to document the current behavior in a test, but I feel like we can do better -- like https://github.com/apache/arrow-datafusion/issues/7869 says even if we can't prove the expression is not true due to a large inlist, we shouldn't just disable pruning entirely
--
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
Re: [PR] [Minor] extract const and add doc and more tests for in_list pruning [arrow-datafusion]
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang merged PR #8815:
URL: https://github.com/apache/arrow-datafusion/pull/8815
--
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