From cb926adfad1cd0d5f7265be25d0344f2079fdc0b Mon Sep 17 00:00:00 2001 From: kevinyhzou <37431499+KevinyhZou@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:13:04 +0800 Subject: [PATCH] [GLUTEN-7220][CH]Fix expand bug in grouping sets query (#7221) * fix grouping set * remove useless code --- .../hive/GlutenClickHouseHiveTableSuite.scala | 1 + .../GlutenClickHouseTPCHSaltNullParquetSuite.scala | 12 ++++++++++++ .../Operator/DefaultHashAggregateResult.cpp | 2 +- cpp-ch/local-engine/Operator/ExpandStep.cpp | 2 +- cpp-ch/local-engine/Operator/ExpandTransform.cpp | 6 +++--- .../Operator/{ExpandTransorm.h => ExpandTransform.h} | 0 6 files changed, 18 insertions(+), 5 deletions(-) rename cpp-ch/local-engine/Operator/{ExpandTransorm.h => ExpandTransform.h} (100%) 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 b16ae3c119cc..6778dccd3340 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 @@ -1415,4 +1415,5 @@ class GlutenClickHouseHiveTableSuite runQueryAndCompare(selectSql)(df => checkOperatorCount[ProjectExecTransformer](3)(df)) spark.sql("DROP TABLE test_tbl_7054") } + } diff --git a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/tpch/GlutenClickHouseTPCHSaltNullParquetSuite.scala b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/tpch/GlutenClickHouseTPCHSaltNullParquetSuite.scala index 9ac35441acb4..0536d9136ec8 100644 --- a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/tpch/GlutenClickHouseTPCHSaltNullParquetSuite.scala +++ b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/tpch/GlutenClickHouseTPCHSaltNullParquetSuite.scala @@ -2991,5 +2991,17 @@ class GlutenClickHouseTPCHSaltNullParquetSuite extends GlutenClickHouseTPCHAbstr checkGlutenOperatorMatch[ProjectExecTransformer] } } + + test("GLUTEN-7220: Fix bug of grouping sets") { + val table_create_sql = "create table test_tbl_7220(id bigint, name string) using parquet" + val insert_data_sql = "insert into test_tbl_7220 values(1, 'a123'), (2, 'a124'), (3, 'a125')" + val query_sql = "select '2024-08-26' as day, id,name from" + + " (select id, name from test_tbl_7220 group by id, name grouping sets((id),(id,name))) " + + " where name = 'a124'" + spark.sql(table_create_sql) + spark.sql(insert_data_sql) + compareResultsAgainstVanillaSpark(query_sql, true, { _ => }) + spark.sql("drop table test_tbl_7220") + } } // scalastyle:on line.size.limit diff --git a/cpp-ch/local-engine/Operator/DefaultHashAggregateResult.cpp b/cpp-ch/local-engine/Operator/DefaultHashAggregateResult.cpp index fa8d51aee26a..3c5450f74674 100644 --- a/cpp-ch/local-engine/Operator/DefaultHashAggregateResult.cpp +++ b/cpp-ch/local-engine/Operator/DefaultHashAggregateResult.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/cpp-ch/local-engine/Operator/ExpandStep.cpp b/cpp-ch/local-engine/Operator/ExpandStep.cpp index 8770c4c405cc..518f094cdbd6 100644 --- a/cpp-ch/local-engine/Operator/ExpandStep.cpp +++ b/cpp-ch/local-engine/Operator/ExpandStep.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/cpp-ch/local-engine/Operator/ExpandTransform.cpp b/cpp-ch/local-engine/Operator/ExpandTransform.cpp index 29e254bc01a7..a3192dbf522a 100644 --- a/cpp-ch/local-engine/Operator/ExpandTransform.cpp +++ b/cpp-ch/local-engine/Operator/ExpandTransform.cpp @@ -27,7 +27,7 @@ #include #include -#include "ExpandTransorm.h" +#include "ExpandTransform.h" namespace DB { @@ -122,8 +122,8 @@ void ExpandTransform::work() else if (kind == EXPAND_FIELD_KIND_LITERAL) { /// Add const column with field value - auto column = type->createColumnConst(rows, field); - columns[col_i] = column; + auto column = type->createColumnConst(rows, field)->convertToFullColumnIfConst(); + columns[col_i] = std::move(column); } else throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "Unknown ExpandFieldKind {}", magic_enum::enum_name(kind)); diff --git a/cpp-ch/local-engine/Operator/ExpandTransorm.h b/cpp-ch/local-engine/Operator/ExpandTransform.h similarity index 100% rename from cpp-ch/local-engine/Operator/ExpandTransorm.h rename to cpp-ch/local-engine/Operator/ExpandTransform.h