diff --git a/spark/src/main/scala/org/apache/comet/serde/arrays.scala b/spark/src/main/scala/org/apache/comet/serde/arrays.scala index 690bc376c7..f75acedc20 100644 --- a/spark/src/main/scala/org/apache/comet/serde/arrays.scala +++ b/spark/src/main/scala/org/apache/comet/serde/arrays.scala @@ -119,7 +119,7 @@ object CometArrayContains extends CometExpressionSerde[ArrayContains] { } } -object CometSortArray extends CometExpressionSerde[SortArray] { +object CometSortArray extends CometExpressionSerde[SortArray] with CodegenDispatchFallback { override def getIncompatibleReasons(): Seq[String] = Seq( "When `" + CometConf.COMET_EXEC_STRICT_FLOATING_POINT.key + "=true`, sorting on" + diff --git a/spark/src/test/resources/sql-tests/expressions/array/sort_array_strict_fp.sql b/spark/src/test/resources/sql-tests/expressions/array/sort_array_strict_fp.sql new file mode 100644 index 0000000000..29e27a7422 --- /dev/null +++ b/spark/src/test/resources/sql-tests/expressions/array/sort_array_strict_fp.sql @@ -0,0 +1,57 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +-- With strict floating-point mode on, Comet's native float sort is Incompatible with Spark +-- (NaN / signed-zero ordering). CometSortArray mixes in CodegenDispatchFallback, so it routes +-- through the JVM codegen dispatcher and matches Spark exactly instead of falling back. + +-- Config: spark.comet.exec.strictFloatingPoint=true + +statement +CREATE TABLE test_sort_array_strict_double(arr array) USING parquet + +statement +INSERT INTO test_sort_array_strict_double VALUES + (array(CAST('Infinity' AS DOUBLE), CAST('-Infinity' AS DOUBLE), CAST('NaN' AS DOUBLE), 3.0, 1.0, NULL, -0.0, 0.0)), + (array(CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE), -5.0, 2.0)), + (array()), + (NULL) + +query +SELECT sort_array(arr) FROM test_sort_array_strict_double + +query +SELECT sort_array(arr, false) FROM test_sort_array_strict_double + +statement +CREATE TABLE test_sort_array_strict_float(arr array) USING parquet + +statement +INSERT INTO test_sort_array_strict_float VALUES + (array(CAST('Infinity' AS FLOAT), CAST('-Infinity' AS FLOAT), CAST('NaN' AS FLOAT), CAST(3.0 AS FLOAT), CAST(NULL AS FLOAT), CAST(-0.0 AS FLOAT), CAST(0.0 AS FLOAT))), + (array()), + (NULL) + +query +SELECT sort_array(arr) FROM test_sort_array_strict_float + +query +SELECT sort_array(arr, false) FROM test_sort_array_strict_float + +-- nested float arrays also dispatch +query +SELECT sort_array(array(CAST('NaN' AS DOUBLE), -0.0, 0.0, 1.0, CAST('-Infinity' AS DOUBLE)))