r7raul1984 opened a new pull request, #52554:
URL: https://github.com/apache/spark/pull/52554
### What changes were proposed in this pull request?
By pushing down the filter condition in the count_if function, we can reduce
the volume of data that needs to be processed.
```
spark.sql("create table t1(a int, b int, c int) using parquet")
spark.sql("select count_if(a <>1) from t1").explain("cost")
```
Current:
```
== Optimized Logical Plan ==
Aggregate [count(if (NOT _common_expr_0#6) null else _common_expr_0#6) AS
count_if((NOT (a = 1)))#4L], Statistics(sizeInBytes=16.0 B, rowCount=1)
+- Project [NOT (a#0 = 1) AS _common_expr_0#6], Statistics(sizeInBytes=1.0 B)
+- Relation spark_catalog.default.t1[a#0,b#1,c#2] parquet,
Statistics(sizeInBytes=0.0 B)
```
After this pr:
```
== Optimized Logical Plan ==
Aggregate [count(if (NOT _common_expr_2#22) null else _common_expr_2#22) AS
count_if((NOT (a = 1)))#21L], Statistics(sizeInBytes=16.0 B, rowCount=1)
+- Project [NOT (a#3 = 1) AS _common_expr_2#22], Statistics(sizeInBytes=1.0
B)
+- Filter (isnotnull(a#3) AND NOT (a#3 = 1)), Statistics(sizeInBytes=1.0
B)
+- Relation spark_catalog.default.t1[a#3,b#4,c#5] parquet,
Statistics(sizeInBytes=0.0 B)
```
### Why are the changes needed?
Push down the conditional filter expressions in COUNT_IF to improve query
performance.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unit test.
### Was this patch authored or co-authored using generative AI tooling?
No.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]