From f79d7b21bbd68e3675a776ed39d25a8aae6c5fcc Mon Sep 17 00:00:00 2001 From: rich7420 Date: Fri, 11 Sep 2026 17:24:49 +0800 Subject: [PATCH 1/2] test: cover round expression routing configurations --- .../sql-tests/expressions/math/round.sql | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spark/src/test/resources/sql-tests/expressions/math/round.sql b/spark/src/test/resources/sql-tests/expressions/math/round.sql index 971ad0a4d5..5c5f461742 100644 --- a/spark/src/test/resources/sql-tests/expressions/math/round.sql +++ b/spark/src/test/resources/sql-tests/expressions/math/round.sql @@ -15,9 +15,13 @@ -- specific language governing permissions and limitations -- under the License. +-- Config: spark.comet.exec.scalaUDF.codegen.enabled=true +-- ConfigMatrix: spark.comet.expression.round.allowIncompatible=false,true + -- Integral and non-negative-scale decimal inputs round natively. Float and double inputs have no -- native implementation (Spark rounds them through BigDecimal built from Double.toString), so they --- route through the codegen dispatcher and must match Spark exactly. +-- route through the codegen dispatcher and must match Spark exactly. Enabling allowIncompatible +-- must not change either route. statement CREATE TABLE test_round(d double, f float, dec decimal(10,4), i int, l bigint) USING parquet @@ -93,3 +97,17 @@ SELECT l, round(l, -19), round(l, -20) FROM test_round_long_overflow query SELECT round(5000000000000000000L, -19), round(-5000000000000000000L, -19) + +-- Disabling the dispatcher leaves supported types native and sends float/double inputs to Spark, +-- even with allowIncompatible enabled. +statement +SET spark.comet.exec.scalaUDF.codegen.enabled=false + +query expect_native(round) +SELECT round(dec, 2), round(i, -1), round(l, -1) FROM test_round + +query expect_fallback(round: spark.comet.exec.scalaUDF.codegen.enabled=false) +SELECT round(d, 2) FROM test_round + +query expect_fallback(round: spark.comet.exec.scalaUDF.codegen.enabled=false) +SELECT round(f, 2) FROM test_round From 7df79ce0f1a333870cf079ba6bdcabd9b8356d16 Mon Sep 17 00:00:00 2001 From: rich7420 Date: Sun, 13 Sep 2026 22:33:16 +0800 Subject: [PATCH 2/2] test: refine round routing coverage after review --- .../sql-tests/expressions/math/round.sql | 26 ++++--------- .../math/round_dispatch_disabled.sql | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 spark/src/test/resources/sql-tests/expressions/math/round_dispatch_disabled.sql diff --git a/spark/src/test/resources/sql-tests/expressions/math/round.sql b/spark/src/test/resources/sql-tests/expressions/math/round.sql index 5c5f461742..1f3bd3d9e6 100644 --- a/spark/src/test/resources/sql-tests/expressions/math/round.sql +++ b/spark/src/test/resources/sql-tests/expressions/math/round.sql @@ -16,12 +16,10 @@ -- under the License. -- Config: spark.comet.exec.scalaUDF.codegen.enabled=true --- ConfigMatrix: spark.comet.expression.round.allowIncompatible=false,true -- Integral and non-negative-scale decimal inputs round natively. Float and double inputs have no -- native implementation (Spark rounds them through BigDecimal built from Double.toString), so they --- route through the codegen dispatcher and must match Spark exactly. Enabling allowIncompatible --- must not change either route. +-- route through the codegen dispatcher and must match Spark exactly. statement CREATE TABLE test_round(d double, f float, dec decimal(10,4), i int, l bigint) USING parquet @@ -45,10 +43,14 @@ SELECT d, round(d), round(d, 0), round(d, 2), round(d, -1) FROM test_round query expect_dispatch(round) SELECT f, round(f), round(f, 0), round(f, 2), round(f, -1) FROM test_round --- Null scale makes the whole result null without evaluating the child. -query +-- Null scale short-circuits in the dispatcher for floating-point inputs. +query expect_dispatch(round) SELECT round(d, NULL), round(f, NULL) FROM test_round +-- Compatible inputs use the native serializer's null-scale branch. +query expect_native(round) +SELECT round(dec, NULL), round(i, NULL), round(l, NULL) FROM test_round + -- Decimal and integral inputs stay on the native path. query expect_native(round) SELECT dec, round(dec), round(dec, 2), round(dec, -1) FROM test_round @@ -97,17 +99,3 @@ SELECT l, round(l, -19), round(l, -20) FROM test_round_long_overflow query SELECT round(5000000000000000000L, -19), round(-5000000000000000000L, -19) - --- Disabling the dispatcher leaves supported types native and sends float/double inputs to Spark, --- even with allowIncompatible enabled. -statement -SET spark.comet.exec.scalaUDF.codegen.enabled=false - -query expect_native(round) -SELECT round(dec, 2), round(i, -1), round(l, -1) FROM test_round - -query expect_fallback(round: spark.comet.exec.scalaUDF.codegen.enabled=false) -SELECT round(d, 2) FROM test_round - -query expect_fallback(round: spark.comet.exec.scalaUDF.codegen.enabled=false) -SELECT round(f, 2) FROM test_round diff --git a/spark/src/test/resources/sql-tests/expressions/math/round_dispatch_disabled.sql b/spark/src/test/resources/sql-tests/expressions/math/round_dispatch_disabled.sql new file mode 100644 index 0000000000..db0a60e3c3 --- /dev/null +++ b/spark/src/test/resources/sql-tests/expressions/math/round_dispatch_disabled.sql @@ -0,0 +1,37 @@ +-- 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. + +-- Config: spark.comet.exec.scalaUDF.codegen.enabled=false + +-- Disabling the dispatcher keeps supported inputs native and sends floating-point inputs to Spark. +statement +CREATE TABLE test_round_disabled(d double, f float, dec decimal(10,4), i int, l bigint) USING parquet + +statement +INSERT INTO test_round_disabled VALUES + (2.5, 2.5, 2.5, 25, 25), + (-2.5, -2.5, -2.5, -25, -25), + (NULL, NULL, NULL, NULL, NULL) + +query expect_native(round) +SELECT round(dec, 2), round(i, -1), round(l, -1) FROM test_round_disabled + +query expect_fallback(round: spark.comet.exec.scalaUDF.codegen.enabled=false) +SELECT round(d, 2) FROM test_round_disabled + +query expect_fallback(round: spark.comet.exec.scalaUDF.codegen.enabled=false) +SELECT round(f, 2) FROM test_round_disabled