You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by lw...@apache.org on 2025/05/15 06:11:37 UTC
(incubator-gluten) branch GLUTEN-9647 created (now 16a3493ef1)
This is an automated email from the ASF dual-hosted git repository.
lwz9103 pushed a change to branch GLUTEN-9647
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
at 16a3493ef1 [GLUTEN-9647][CH] Fix SimplifySumRule on different types
This branch includes the following new commits:
new 16a3493ef1 [GLUTEN-9647][CH] Fix SimplifySumRule on different types
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
(incubator-gluten) 01/01: [GLUTEN-9647][CH] Fix SimplifySumRule on different types
Posted by lw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lwz9103 pushed a commit to branch GLUTEN-9647
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
commit 16a3493ef145594ddff6faa8c26fdddaabdedd4c
Author: lwz9103 <lw...@163.com>
AuthorDate: Thu May 15 14:11:09 2025 +0800
[GLUTEN-9647][CH] Fix SimplifySumRule on different types
---
.../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: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org