From 7f5502a332d8676b5b0750bb7a5e487240d8b3ce Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 Mar 2024 13:30:03 -0800 Subject: [PATCH 1/2] feat: Enable min/max for boolean type --- .../apache/comet/serde/QueryPlanSerde.scala | 2 +- .../comet/exec/CometAggregateSuite.scala | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala index 75a2ff981..b47789868 100644 --- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala +++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala @@ -181,7 +181,7 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde { private def minMaxDataTypeSupported(dt: DataType): Boolean = { dt match { - case _: NumericType | DateType | TimestampType => true + case _: NumericType | DateType | TimestampType | BooleanType => true case _ => false } } diff --git a/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala b/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala index d64a3a3ae..cf54e34ec 100644 --- a/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala +++ b/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala @@ -886,6 +886,32 @@ class CometAggregateSuite extends CometTestBase with AdaptiveSparkPlanHelper { } } + test("test bool_and/bool_or") { + withSQLConf(CometConf.COMET_EXEC_SHUFFLE_ENABLED.key -> "true") { + Seq(true, false).foreach { bosonColumnShuffleEnabled => + withSQLConf( + CometConf.COMET_COLUMNAR_SHUFFLE_ENABLED.key -> bosonColumnShuffleEnabled.toString) { + Seq(true, false).foreach { dictionary => + withSQLConf("parquet.enable.dictionary" -> dictionary.toString) { + val table = "test" + withTable(table) { + sql(s"create table $table(a boolean, b int) using parquet") + sql(s"insert into $table values(true, 1)") + sql(s"insert into $table values(false, 2)") + sql(s"insert into $table values(true, 3)") + sql(s"insert into $table values(true, 3)") + // Spark maps BOOL_AND to MIN and BOOL_OR to MAX + checkSparkAnswerAndNumOfAggregates( + s"SELECT MIN(a), MIN(b), BOOL_AND(a), BOOL_OR(a) FROM $table", + 2) + } + } + } + } + } + } + } + protected def checkSparkAnswerAndNumOfAggregates(query: String, numAggregates: Int): Unit = { val df = sql(query) checkSparkAnswer(df) From 816ce17d6d4551f6db83e5a9ff83669f024acffd Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 Mar 2024 14:06:47 -0800 Subject: [PATCH 2/2] address comments --- .../test/scala/org/apache/comet/exec/CometAggregateSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala b/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala index cf54e34ec..c2faa6544 100644 --- a/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala +++ b/spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala @@ -902,7 +902,7 @@ class CometAggregateSuite extends CometTestBase with AdaptiveSparkPlanHelper { sql(s"insert into $table values(true, 3)") // Spark maps BOOL_AND to MIN and BOOL_OR to MAX checkSparkAnswerAndNumOfAggregates( - s"SELECT MIN(a), MIN(b), BOOL_AND(a), BOOL_OR(a) FROM $table", + s"SELECT MIN(a), MAX(a), BOOL_AND(a), BOOL_OR(a) FROM $table", 2) } }