This is an automated email from the ASF dual-hosted git repository.
lwz9103 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 608f00cd8d [GLUTEN-9647][CH] Fix SimplifySumRule on different types
(#9648)
608f00cd8d is described below
commit 608f00cd8d237d9b83760dd29a7ed1ad8dbf4718
Author: Wenzheng Liu <[email protected]>
AuthorDate: Thu May 15 16:07:01 2025 +0800
[GLUTEN-9647][CH] Fix SimplifySumRule on different types (#9648)
---
.../apache/gluten/extension/SimplifySumRule.scala | 7 ++++---
.../hive/GlutenClickHouseHiveTableSuite.scala | 23 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git
a/backends-clickhouse/src/main/scala/org/apache/gluten/extension/SimplifySumRule.scala
b/backends-clickhouse/src/main/scala/org/apache/gluten/extension/SimplifySumRule.scala
index 27e57eeb08..e5c1b1606e 100644
---
a/backends-clickhouse/src/main/scala/org/apache/gluten/extension/SimplifySumRule.scala
+++
b/backends-clickhouse/src/main/scala/org/apache/gluten/extension/SimplifySumRule.scala
@@ -19,6 +19,7 @@ package org.apache.gluten.extension
import org.apache.gluten.backendsapi.clickhouse.CHBackendSettings
import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.analysis.TypeCoercion.ImplicitTypeCasts
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.aggregate._
import org.apache.spark.sql.catalyst.plans.logical._
@@ -48,17 +49,17 @@ case class SimplifySumRule(spark: SparkSession) extends
Rule[LogicalPlan] {
// Rule 1: sum(expr / literal) -> sum(expr) / literal
case Divide(numerator, denominator @ Literal(_, _), _) =>
val newSum = aggrExpr.copy(aggregateFunction = Sum(numerator))
- Divide(newSum, denominator)
+ ImplicitTypeCasts.transform(Divide(newSum, denominator))
// Rule 2: sum(expr * literal) -> literal * sum(expr)
case Multiply(expr, literal @ Literal(_, _), _) =>
val newSum = aggrExpr.copy(aggregateFunction = Sum(expr))
- Multiply(literal, newSum)
+ ImplicitTypeCasts.transform(Multiply(literal, newSum))
// Rule 3: sum(literal * expr) -> literal * sum(expr)
case Multiply(literal @ Literal(_, _), expr, _) =>
val newSum = aggrExpr.copy(aggregateFunction = Sum(expr))
- Multiply(literal, newSum)
+ ImplicitTypeCasts.transform(Multiply(literal, newSum))
case _ => aggrExpr
}
diff --git
a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/hive/GlutenClickHouseHiveTableSuite.scala
b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/hive/GlutenClickHouseHiveTableSuite.scala
index bf885ffd99..f53fa397cb 100644
---
a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/hive/GlutenClickHouseHiveTableSuite.scala
+++
b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/hive/GlutenClickHouseHiveTableSuite.scala
@@ -1700,4 +1700,27 @@ class GlutenClickHouseHiveTableSuite
}
}
+ test("GLUTEN-9647: Fix SimplifySumRule on different types") {
+ val sql =
+ s"""
+ | select sum(int_field * 2L),
+ | min(float_field / 2),
+ | max(double_field * 0.03),
+ | sum(short_field * 2),
+ | sum(decimal_field * 3L)
+ | from $json_table_name
+ | where day = '2023-06-06'
+ |""".stripMargin
+ compareResultsAgainstVanillaSpark(
+ sql,
+ compareResult = true,
+ df => {
+ val jsonFileScan = collect(df.queryExecution.executedPlan) {
+ case l: HiveTableScanExecTransformer => l
+ }
+ assert(jsonFileScan.size == 1)
+ }
+ )
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]