From 852b8cfbfc200b37e3d8b4c3324f6e73cf8bf42d Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 Mar 2024 16:55:25 -0800 Subject: [PATCH] feat: Enable min/max for boolean type (#165) --- .../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 a412720e5..b154fb62f 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..c2faa6544 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), MAX(a), BOOL_AND(a), BOOL_OR(a) FROM $table", + 2) + } + } + } + } + } + } + } + protected def checkSparkAnswerAndNumOfAggregates(query: String, numAggregates: Int): Unit = { val df = sql(query) checkSparkAnswer(df)