This is an automated email from the ASF dual-hosted git repository.
sunchao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git
The following commit(s) were added to refs/heads/main by this push:
new c0b0b5e7ff test: expand ANSI coverage for round, conv and elt (#5799)
c0b0b5e7ff is described below
commit c0b0b5e7fffbd625b573a96e6ea8e6aed9012a58
Author: KUAN-HAO HUANG <[email protected]>
AuthorDate: Thu Sep 10 07:12:23 2026 +0800
test: expand ANSI coverage for round, conv and elt (#5799)
---
.../resources/sql-tests/expressions/math/conv.sql | 2 +-
.../expressions/math/{conv.sql => conv_ansi.sql} | 20 +++++----
.../resources/sql-tests/expressions/math/round.sql | 15 +++++++
.../sql-tests/expressions/math/round_ansi.sql | 48 +++++++++++++++++++++
.../resources/sql-tests/expressions/string/elt.sql | 2 +-
.../sql-tests/expressions/string/elt_ansi.sql | 49 ++++++++++++++++++++++
6 files changed, 127 insertions(+), 9 deletions(-)
diff --git a/spark/src/test/resources/sql-tests/expressions/math/conv.sql
b/spark/src/test/resources/sql-tests/expressions/math/conv.sql
index 5cc5e2b89e..f00365bbaa 100644
--- a/spark/src/test/resources/sql-tests/expressions/math/conv.sql
+++ b/spark/src/test/resources/sql-tests/expressions/math/conv.sql
@@ -21,7 +21,7 @@ statement
CREATE TABLE test_conv(s string) USING parquet
statement
-INSERT INTO test_conv VALUES ('100'), ('FF'), ('0'), (NULL)
+INSERT INTO test_conv VALUES ('100'), ('FF'), ('0'), ('FFFFFFFFFFFFFFFF'),
('FFFFFFFFFFFFFFFFF'), (NULL)
query
SELECT s, conv(s, 16, 10) FROM test_conv
diff --git a/spark/src/test/resources/sql-tests/expressions/math/conv.sql
b/spark/src/test/resources/sql-tests/expressions/math/conv_ansi.sql
similarity index 55%
copy from spark/src/test/resources/sql-tests/expressions/math/conv.sql
copy to spark/src/test/resources/sql-tests/expressions/math/conv_ansi.sql
index 5cc5e2b89e..a4aca46df6 100644
--- a/spark/src/test/resources/sql-tests/expressions/math/conv.sql
+++ b/spark/src/test/resources/sql-tests/expressions/math/conv_ansi.sql
@@ -15,17 +15,23 @@
-- specific language governing permissions and limitations
-- under the License.
--- Routes conv through the codegen dispatcher so behavior matches Spark
exactly.
+-- Config: spark.sql.ansi.enabled=true
+-- conv executes Spark's generated code inside Comet's codegen dispatcher.
statement
-CREATE TABLE test_conv(s string) USING parquet
+CREATE TABLE test_conv_ansi(id int, s string) USING parquet
statement
-INSERT INTO test_conv VALUES ('100'), ('FF'), ('0'), (NULL)
+INSERT INTO test_conv_ansi VALUES
+ (1, 'FF'), (2, 'FFFFFFFFFFFFFFFF'), (3, NULL), (4, 'FFFFFFFFFFFFFFFFF')
+-- Valid input, the unsigned 64-bit boundary and NULL must execute inside
Comet.
query
-SELECT s, conv(s, 16, 10) FROM test_conv
+SELECT id, conv(s, 16, 10), conv(s, 16, -10) FROM test_conv_ansi WHERE id < 4
--- literal arguments across bases
-query
-SELECT conv('100', 2, 10), conv('FF', 16, 10), conv(15, 10, 2), conv('-10',
16, -10)
+-- One more hex digit exceeds the unsigned 64-bit range.
+query expect_error(ARITHMETIC_OVERFLOW)
+SELECT conv(s, 16, 10) FROM test_conv_ansi WHERE id = 4
+
+query expect_error(ARITHMETIC_OVERFLOW)
+SELECT conv('FFFFFFFFFFFFFFFFF', 16, 10)
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 9974d872a8..fc649cf78f 100644
--- a/spark/src/test/resources/sql-tests/expressions/math/round.sql
+++ b/spark/src/test/resources/sql-tests/expressions/math/round.sql
@@ -72,3 +72,18 @@ SELECT round(123.456, 2), round(2.5, 0), round(3.5, 0),
round(-2.5, 0), round(NU
query
SELECT round(2.5D, 0), round(3.5D, 0), round(-2.5D, 0), round(2.5F, 0),
round(-2.5F, 0)
+
+-- Legacy negative-scale overflow wraps rather than throwing or returning zero
(#5070).
+statement
+CREATE TABLE test_round_long_overflow(l bigint) USING parquet
+
+statement
+INSERT INTO test_round_long_overflow VALUES
+ (-5000000000000000000L), (-4999999999999999999L), (0L),
+ (4999999999999999999L), (5000000000000000000L), (NULL)
+
+query
+SELECT l, round(l, -19), round(l, -20) FROM test_round_long_overflow
+
+query
+SELECT round(5000000000000000000L, -19), round(-5000000000000000000L, -19)
diff --git a/spark/src/test/resources/sql-tests/expressions/math/round_ansi.sql
b/spark/src/test/resources/sql-tests/expressions/math/round_ansi.sql
new file mode 100644
index 0000000000..2eb93f0891
--- /dev/null
+++ b/spark/src/test/resources/sql-tests/expressions/math/round_ansi.sql
@@ -0,0 +1,48 @@
+-- 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.sql.ansi.enabled=true
+
+statement
+CREATE TABLE test_round_ansi(l bigint) USING parquet
+
+statement
+INSERT INTO test_round_ansi VALUES
+ (-5000000000000000000L), (-4999999999999999999L), (0L),
+ (4999999999999999999L), (5000000000000000000L), (NULL)
+
+-- Values just below the half-way boundary round to zero; NULL stays NULL.
+query
+SELECT l, round(l, -19) FROM test_round_ansi
+WHERE l BETWEEN -4999999999999999999L AND 4999999999999999999L OR l IS NULL
+
+-- A larger negative scale rounds even the overflow inputs below to zero.
+query
+SELECT l, round(l, -20) FROM test_round_ansi
+
+-- At scale -19, +/-5e18 rounds to +/-1e19, which cannot fit in a long (#5070).
+query expect_error(ARITHMETIC_OVERFLOW)
+SELECT round(l, -19) FROM test_round_ansi WHERE l = 5000000000000000000L
+
+query expect_error(ARITHMETIC_OVERFLOW)
+SELECT round(l, -19) FROM test_round_ansi WHERE l = -5000000000000000000L
+
+query expect_error(ARITHMETIC_OVERFLOW)
+SELECT round(5000000000000000000L, -19)
+
+query expect_error(ARITHMETIC_OVERFLOW)
+SELECT round(-5000000000000000000L, -19)
diff --git a/spark/src/test/resources/sql-tests/expressions/string/elt.sql
b/spark/src/test/resources/sql-tests/expressions/string/elt.sql
index fd526e2978..cd1f281385 100644
--- a/spark/src/test/resources/sql-tests/expressions/string/elt.sql
+++ b/spark/src/test/resources/sql-tests/expressions/string/elt.sql
@@ -21,7 +21,7 @@ statement
CREATE TABLE test_elt(n int) USING parquet
statement
-INSERT INTO test_elt VALUES (1), (2), (3), (NULL)
+INSERT INTO test_elt VALUES (1), (2), (0), (-1), (3), (NULL)
query
SELECT n, elt(n, 'a', 'b') FROM test_elt
diff --git a/spark/src/test/resources/sql-tests/expressions/string/elt_ansi.sql
b/spark/src/test/resources/sql-tests/expressions/string/elt_ansi.sql
new file mode 100644
index 0000000000..20c53dd558
--- /dev/null
+++ b/spark/src/test/resources/sql-tests/expressions/string/elt_ansi.sql
@@ -0,0 +1,49 @@
+-- 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.sql.ansi.enabled=true
+
+-- elt executes Spark's generated code inside Comet's codegen dispatcher.
+statement
+CREATE TABLE test_elt_ansi(n int) USING parquet
+
+statement
+INSERT INTO test_elt_ansi VALUES (1), (2), (0), (-1), (3), (NULL)
+
+-- Valid one-based indices, a NULL index and a selected NULL value stay inside
Comet.
+query
+SELECT n, elt(n, 'a', 'b'), elt(n, 'a', CAST(NULL AS STRING))
+FROM test_elt_ansi WHERE n IN (1, 2) OR n IS NULL
+
+-- Zero, negative and past-the-end indices raise INVALID_ARRAY_INDEX under
ANSI.
+query expect_error(INVALID_ARRAY_INDEX)
+SELECT elt(n, 'a', 'b') FROM test_elt_ansi WHERE n = 0
+
+query expect_error(INVALID_ARRAY_INDEX)
+SELECT elt(n, 'a', 'b') FROM test_elt_ansi WHERE n = -1
+
+query expect_error(INVALID_ARRAY_INDEX)
+SELECT elt(n, 'a', 'b') FROM test_elt_ansi WHERE n = 3
+
+query expect_error(INVALID_ARRAY_INDEX)
+SELECT elt(0, 'a', 'b')
+
+query expect_error(INVALID_ARRAY_INDEX)
+SELECT elt(-1, 'a', 'b')
+
+query expect_error(INVALID_ARRAY_INDEX)
+SELECT elt(3, 'a', 'b')
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]