Skip to content

[GLUTEN-9197][CH] Simplify sum aggregate expression#9198

Merged
taiyang-li merged 2 commits intoapache:mainfrom
bigo-sg:opt_aggr_const
Apr 2, 2025
Merged

[GLUTEN-9197][CH] Simplify sum aggregate expression#9198
taiyang-li merged 2 commits intoapache:mainfrom
bigo-sg:opt_aggr_const

Conversation

@taiyang-li
Copy link
Contributor

@taiyang-li taiyang-li commented Apr 1, 2025

What changes were proposed in this pull request?

Simplify sum with the following rules:

  • Rule 1: sum(expr / literal) -> sum(expr) / literal
  • Rule 2: sum(expr * literal) -> literal * sum(expr)
  • Rule 3: sum(literal * expr) -> literal * sum(expr)

If current rule is combined with #9185, we can easily transform

  • sum(if(cond, expr/literal, 0)) -> (sum(expr) filter (where cond)) / literal
  • sum(if(cond, expr * literal, 0)) -> (sum(expr) filter (where cond)) * literal
  • sum(if(cond, literal * expr, 0)) -> (sum(expr) filter (where cond)) * literal

(Fixes: #9197)

How was this patch tested?

(Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)

(If this patch involves UI changes, please attach a screenshot; otherwise, remove this)

@github-actions
Copy link

github-actions bot commented Apr 1, 2025

#9197

@github-actions
Copy link

github-actions bot commented Apr 1, 2025

Run Gluten Clickhouse CI on x86

@taiyang-li
Copy link
Contributor Author

Performance tests

CREATE TEMPORARY VIEW lineitem
USING org.apache.spark.sql.parquet
OPTIONS (
  path  "/data1/liyang/tpch/tpch-data-sf1/lineitem"
) ; 

select 
sum(l_quantity * 1.234), 
sum(1.234 * l_tax), 
sum(l_extendedprice / 1.234)
from lineitem;  

After 
1 row selected (0.3 seconds)
1 row selected (0.292 seconds)
1 row selected (0.296 seconds)

Before
1 row selected (0.348 seconds)
1 row selected (0.355 seconds)
1 row selected (0.34 seconds)

@github-actions
Copy link

github-actions bot commented Apr 1, 2025

Run Gluten Clickhouse CI on x86

@github-actions
Copy link

github-actions bot commented Apr 1, 2025

Run Gluten Clickhouse CI on x86

@taiyang-li taiyang-li requested a review from exmy April 2, 2025 01:36
Copy link
Contributor

@zhanglistar zhanglistar left a comment

Choose a reason for hiding this comment

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

LGTM

@taiyang-li taiyang-li merged commit 78e27ea into apache:main Apr 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CH] simplify sum expression with literals inside

2 participants