0lai0 commented on code in PR #5614: URL: https://github.com/apache/datafusion-comet/pull/5614#discussion_r3914045727
########## spark/src/test/resources/sql-tests/expressions/array/sequence.sql: ########## @@ -15,17 +15,131 @@ -- specific language governing permissions and limitations -- under the License. --- Routes sequence through the codegen dispatcher so behavior matches Spark exactly. +-- sequence(start, stop[, step]) for integral element types runs on the native kernel +-- (https://github.com/apache/datafusion-comet/issues/5349). Date and timestamp sequences +-- stay on the JVM codegen dispatcher and are exercised at the bottom of this file. statement -CREATE TABLE test_sequence(a int, b int) USING parquet +CREATE TABLE test_sequence( + b_start tinyint, b_stop tinyint, b_step tinyint, + s_start smallint, s_stop smallint, s_step smallint, + i_start int, i_stop int, i_step int, + l_start bigint, l_stop bigint, l_step bigint) +USING parquet +-- Row 2 descends, row 3 has start == stop, rows 4-6 carry NULLs in each argument position. statement -INSERT INTO test_sequence VALUES (1, 5), (5, 1), (3, 3), (NULL, 5) +INSERT INTO test_sequence VALUES + (1Y, 5Y, 1Y, 1S, 5S, 1S, 1, 10, 3, 1L, 5L, 2L), + (-3Y, -1Y, 1Y, 100S, 90S, -2S, 20, 2, -6, 9223372036854775802L, 9223372036854775807L, 1L), + (0Y, 0Y, 0Y, -5S, -5S, 0S, 7, 7, 0, -9223372036854775808L, -9223372036854775800L, 3L), + (NULL, 5Y, 1Y, NULL, 5S, 1S, NULL, 10, 1, NULL, 5L, 1L), + (1Y, NULL, 1Y, 1S, NULL, 1S, 1, NULL, 1, 1L, NULL, 1L), + (1Y, 5Y, NULL, 1S, 5S, NULL, 1, 10, NULL, 1L, 5L, NULL) + +-- ============================================================================ +-- Explicit step, all four integral types +-- ============================================================================ + +query +SELECT sequence(i_start, i_stop, i_step) FROM test_sequence query -SELECT a, b, sequence(a, b) FROM test_sequence +SELECT sequence(l_start, l_stop, l_step) FROM test_sequence + +-- Column step for the narrow integral types exercises the Byte/Short monomorphizations +-- of the native kernel, not just the literal-step shape. +query +SELECT sequence(b_start, b_stop, b_step) FROM test_sequence + +query +SELECT sequence(s_start, s_stop, s_step) FROM test_sequence + +-- ============================================================================ +-- Default step: per-row start <= stop ? 1 : -1, both directions in one column +-- ============================================================================ + +query +SELECT sequence(b_start, b_stop), sequence(s_start, s_stop) FROM test_sequence + +query +SELECT sequence(i_start, i_stop), sequence(l_start, l_stop) FROM test_sequence + +-- ============================================================================ +-- Literal and mixed literal/column arguments +-- ============================================================================ + +query +SELECT sequence(1, 10), sequence(10, 1), sequence(5, 5), sequence(5, 5, 0) --- literal arguments with step query SELECT sequence(1, 5), sequence(5, 1, -1), sequence(1, 10, 2) + +query +SELECT sequence(1L, 9L, 2L), sequence(-128Y, -120Y), sequence(32760S, 32767S) + +-- On row 2 the source row is (i_start=20, i_stop=2, i_step=-6), so the literal-step column +-- asks for sequence(1, 2, 2) = [1] while the default-step column asks for sequence(20, 25) +-- = [20, 21, 22, 23, 24, 25]. The two columns disagreeing in direction on the same row is +-- intentional coverage, not an oversight. +query +SELECT sequence(1, i_stop, 2), sequence(i_start, 25) FROM test_sequence WHERE i_start IS NOT NULL AND i_stop IS NOT NULL + +query +SELECT sequence(CAST(NULL AS int), 5), sequence(1, CAST(NULL AS int)), sequence(1, 5, CAST(NULL AS int)) + +-- Integer.MIN_VALUE/MAX_VALUE bounds for int, and a sequence spanning zero +query +SELECT sequence(2147483642, 2147483647), sequence(-2147483648, -2147483643), sequence(-3, 3, 3) + +-- ============================================================================ +-- sequence feeding explode, the common date-spine shape (with integers) +-- ============================================================================ + +query +SELECT i_start, x FROM test_sequence LATERAL VIEW explode(sequence(i_start, i_stop)) AS x WHERE i_start IS NOT NULL AND i_stop IS NOT NULL + +-- ============================================================================ +-- Error paths: step direction contradicts bounds, or zero step with start != stop +-- ============================================================================ + +query expect_error(Illegal sequence boundaries: 1 to 5 by -1) Review Comment: Thanks, Added all three to sequence.sql: full byte/short range, Int32 step overflow, and CASE WHEN guarded branch. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
