Skip to content

Commit 693ba61

Browse files
Add test coverage for Spark Array functions: repeat, shuffle, slice
1 parent 53b0ffb commit 693ba61

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed

datafusion/sqllogictest/test_files/spark/array/array_repeat.slt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ SELECT array_repeat('123', -1);
3131
----
3232
[]
3333

34+
query ?
35+
SELECT array_repeat('123', CAST('2' AS INT));
36+
----
37+
[123, 123]
38+
39+
query ?
40+
SELECT array_repeat(123, 3);
41+
----
42+
[123, 123, 123]
43+
44+
query ?
45+
SELECT array_repeat('2001-09-28T01:00:00'::timestamp, 2);
46+
----
47+
[2001-09-28T01:00:00, 2001-09-28T01:00:00]
48+
49+
query ?
50+
SELECT array_repeat(array_repeat('123', CAST('2' AS INT)), CAST('3' AS INT));
51+
----
52+
[[123, 123], [123, 123], [123, 123]]
53+
3454
query ?
3555
SELECT array_repeat(['123'], 2);
3656
----

datafusion/sqllogictest/test_files/spark/array/shuffle.slt

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,36 @@ SELECT shuffle(column1, 1) FROM test_shuffle_fixed_size;
8787
[9, NULL, 8]
8888
NULL
8989

90-
# Clean up
91-
statement ok
92-
DROP TABLE test_shuffle_list_types;
90+
query ?
91+
SELECT shuffle(['2001-09-28T01:00:00'::timestamp, '2001-08-28T01:00:00'::timestamp, '2001-07-28T01:00:00'::timestamp, '2001-06-28T01:00:00'::timestamp, '2001-05-28T01:00:00'::timestamp], 1);
92+
----
93+
[2001-09-28T01:00:00, 2001-06-28T01:00:00, 2001-07-28T01:00:00, 2001-08-28T01:00:00, 2001-05-28T01:00:00]
9394

94-
statement ok
95-
DROP TABLE test_shuffle_fixed_size;
95+
query ?
96+
SELECT shuffle(shuffle([1, 20, NULL, 3, 100, NULL, 98, 99], 1), 1);
97+
----
98+
[1, 99, NULL, 98, 100, NULL, 3, 20]
99+
100+
query ?
101+
SELECT shuffle([' ', NULL, 'abc'], 1);
102+
----
103+
[ , NULL, abc]
104+
105+
query ?
106+
SELECT shuffle([1, 2, 3, 4], CAST('2' AS INT));
107+
----
108+
[1, 4, 2, 3]
109+
110+
111+
query error
112+
SELECT shuffle([2, 1, 'abc'], 1);
113+
----
114+
DataFusion error: Optimizer rule 'simplify_expressions' failed
115+
caused by
116+
Arrow error: Cast error: Cannot cast string 'abc' to value of Int64 type
117+
118+
119+
query error
120+
SELECT shuffle([2, 1], NULL);
121+
----
122+
DataFusion error: Execution error: shuffle seed must be Int64 type, got 'Int64'

datafusion/sqllogictest/test_files/spark/array/slice.slt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,18 @@ FROM VALUES
9999
NULL
100100
NULL
101101
NULL
102+
103+
query ?
104+
SELECT slice(['2001-09-28T01:00:00'::timestamp, '2001-08-28T01:00:00'::timestamp, '2001-07-28T01:00:00'::timestamp, '2001-06-28T01:00:00'::timestamp, '2001-05-28T01:00:00'::timestamp], 1, 3);
105+
----
106+
[2001-09-28T01:00:00, 2001-08-28T01:00:00, 2001-07-28T01:00:00]
107+
108+
query ?
109+
SELECT slice(slice([1, 2, 3, 4], 1, 3), 1, 2);
110+
----
111+
[1, 2]
112+
113+
query ?
114+
SELECT slice([1, 2, 3, 4], CAST('2' AS INT), 3);
115+
----
116+
[2, 3, 4]

docs/source/contributor-guide/testing.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ DataFusion's SQL implementation is tested using [sqllogictest](https://github.co
7070
cargo test --profile=ci --test sqllogictests
7171
# Run a specific test file
7272
cargo test --profile=ci --test sqllogictests -- aggregate.slt
73-
# Run and update expected outputs
73+
# Run a specific test file and update expected outputs
74+
cargo test --profile=ci --test sqllogictests -- aggregate.slt --complete
75+
# Run and update expected outputs for all test files
7476
cargo test --profile=ci --test sqllogictests -- --complete
7577
```
7678

0 commit comments

Comments
 (0)