Skip to content

Commit b250ed0

Browse files
committed
table function tests
1 parent e53b43c commit b250ed0

13 files changed

Lines changed: 2396 additions & 1681 deletions

grammar/FuncTestCaseLexer.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Whitespace : [ \t\n\r]+ -> channel(HIDDEN) ;
1111
TripleHash: '###';
1212
SubstraitScalarTest: 'SUBSTRAIT_SCALAR_TEST';
1313
SubstraitAggregateTest: 'SUBSTRAIT_AGGREGATE_TEST';
14+
SubstraitTableTest: 'SUBSTRAIT_TABLE_TEST';
1415
SubstraitInclude: 'SUBSTRAIT_INCLUDE';
1516
SubstraitDependency: 'SUBSTRAIT_DEPENDENCY';
1617

grammar/FuncTestCaseParser.g4

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ header
1515
;
1616

1717
version
18-
: TripleHash (SubstraitScalarTest | SubstraitAggregateTest) Colon FormatVersion
18+
: TripleHash (SubstraitScalarTest | SubstraitAggregateTest | SubstraitTableTest) Colon FormatVersion
1919
;
2020

2121
include
@@ -37,6 +37,7 @@ testCase
3737
testGroup
3838
: testGroupDescription? (testCase)+ #scalarFuncTestGroup
3939
| testGroupDescription? (aggFuncTestCase)+ #aggregateFuncTestGroup
40+
| testGroupDescription? (tableFuncTestCase)+ #tableFuncTestGroup
4041
;
4142

4243
arguments
@@ -76,6 +77,18 @@ aggFuncTestCase
7677
: aggFuncCall ( OBracket funcOptions CBracket )? Eq result
7778
;
7879

80+
tableFuncTestCase
81+
: functionName=identifier OParen arguments CParen ( OBracket funcOptions CBracket )? Eq multiRowResult
82+
;
83+
84+
multiRowResult
85+
: OBracket (rowTuple (Comma rowTuple)*)? CBracket DoubleColon structType
86+
;
87+
88+
rowTuple
89+
: OParen (literal (Comma literal)*)? CParen
90+
;
91+
7992
aggFuncCall
8093
: tableData funcName=identifier OParen qualifiedAggregateFuncArgs? CParen #multiArgAggregateFuncCall
8194
| tableRows functName=identifier OParen aggregateFuncArgs? CParen #compactAggregateFuncCall
@@ -344,12 +357,16 @@ parameterizedType
344357
| precisionTimestampType
345358
| precisionTimestampTZType
346359
| funcType
360+
| structType
347361
// TODO implement the rest of the parameterized types
348-
// | Struct isnull='?'? Lt expr (Comma expr)* Gt #struct
349362
// | NStruct isnull='?'? Lt Identifier expr (Comma Identifier expr)* Gt #nStruct
350363
// | Map isnull='?'? Lt key=expr Comma value=expr Gt #map
351364
;
352365

366+
structType
367+
: Struct isnull=QMark? OAngleBracket dataType (Comma dataType)* CAngleBracket
368+
;
369+
353370
numericParameter
354371
: IntegerLiteral #integerLiteral
355372
;

tests/baseline.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"num_aggregate_functions": 29,
77
"num_scalar_functions": 166,
88
"num_window_functions": 11,
9-
"num_table_functions": 3,
9+
"num_table_functions": 4,
1010
"num_function_overloads": 536
1111
},
1212
"coverage": {
13-
"total_test_count": 1140,
13+
"total_test_count": 1158,
1414
"num_function_variants": 536,
15-
"num_covered_function_variants": 241
15+
"num_covered_function_variants": 247
1616
}
1717
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
### SUBSTRAIT_TABLE_TEST: v1.0
2+
### SUBSTRAIT_INCLUDE: '/extensions/functions_table_generic.yaml'
3+
4+
# basic_int: Basic integer array explosion
5+
explode([1, 2, 3]::list<i32>) = [(1), (2), (3)]::struct<i32>
6+
7+
# basic_string: Basic string array explosion
8+
explode(['a', 'b', 'c']::list<str>) = [('a'), ('b'), ('c')]::struct<str>
9+
10+
# empty: Empty arrays produce zero rows
11+
explode([]::list<i32>) = []::struct<i32>
12+
13+
# single_element: Single element arrays
14+
explode([42]::list<i32>) = [(42)]::struct<i32>
15+
16+
# two_elements: Two element arrays
17+
explode([10, 20]::list<i32>) = [(10), (20)]::struct<i32>
18+
19+
# large_array: Larger array
20+
explode([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]::list<i32>) = [(1), (2), (3), (4), (5), (6), (7), (8), (9), (10)]::struct<i32>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### SUBSTRAIT_TABLE_TEST: v1.0
2+
### SUBSTRAIT_INCLUDE: '/extensions/functions_table_generic.yaml'
3+
4+
# basic_int: Basic integer array with positions
5+
posexplode([10, 20, 30]::list<i32>) = [(0, 10), (1, 20), (2, 30)]::struct<i64,i32>
6+
7+
# basic_string: Basic string array with positions
8+
posexplode(['a', 'b', 'c']::list<str>) = [(0, 'a'), (1, 'b'), (2, 'c')]::struct<i64,str>
9+
10+
# empty: Empty arrays produce zero rows
11+
posexplode([]::list<i32>) = []::struct<i64,i32>
12+
13+
# single_element: Single element arrays start at position 0
14+
posexplode([42]::list<i32>) = [(0, 42)]::struct<i64,i32>
15+
16+
# two_elements: Two element arrays
17+
posexplode([100, 200]::list<i32>) = [(0, 100), (1, 200)]::struct<i64,i32>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### SUBSTRAIT_TABLE_TEST: v1.0
2+
### SUBSTRAIT_INCLUDE: '/extensions/functions_table_generic.yaml'
3+
4+
# single_list_int: Single list unnest (same as explode)
5+
unnest([1, 2, 3]::list<i32>) = [(1), (2), (3)]::struct<i32>
6+
7+
# single_list_string: Single list unnest with strings
8+
unnest(['a', 'b']::list<str>) = [('a'), ('b')]::struct<str>
9+
10+
# single_list_empty: Empty list produces zero rows
11+
unnest([]::list<i32>) = []::struct<i32>
12+
13+
# two_lists_same_length: Zip two lists of same length
14+
unnest([1, 2, 3]::list<i32>, [4, 5, 6]::list<i32>) = [(1, 4), (2, 5), (3, 6)]::struct<i32,i32>
15+
16+
# two_lists_different_types: Zip lists of different types
17+
unnest([1, 2]::list<i32>, ['a', 'b']::list<str>) = [(1, 'a'), (2, 'b')]::struct<i32,str>
18+
19+
# three_lists: Zip three lists
20+
unnest([1, 2]::list<i32>, [3, 4]::list<i32>, [5, 6]::list<i32>) = [(1, 3, 5), (2, 4, 6)]::struct<i32,i32,i32>
21+
22+
# four_lists: Zip four lists
23+
unnest([1, 2]::list<i32>, [3, 4]::list<i32>, [5, 6]::list<i32>, [7, 8]::list<i32>) = [(1, 3, 5, 7), (2, 4, 6, 8)]::struct<i32,i32,i32,i32>

0 commit comments

Comments
 (0)