Skip to content

Commit f2a02a4

Browse files
committed
add tests
1 parent 63c9c0f commit f2a02a4

File tree

2 files changed

+67
-19
lines changed

2 files changed

+67
-19
lines changed

enginetest/queries/script_queries.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11584,6 +11584,7 @@ select * from t1 except (
1158411584
Query: "select * from test01 where pk in (11)",
1158511585
Expected: []sql.Row{
1158611586
{"11"},
11587+
{"11-5"},
1158711588
{"11d"},
1158811589
{"11wha?"},
1158911590
},
@@ -11628,6 +11629,71 @@ select * from t1 except (
1162811629
},
1162911630
},
1163011631
},
11632+
{
11633+
// https://github.com/dolthub/dolt/issues/6899
11634+
Name: "window function tests",
11635+
SetUpScript: []string{
11636+
"CREATE TABLE c (c_id INT PRIMARY KEY, bill TEXT);",
11637+
"CREATE TABLE o (o_id INT PRIMARY KEY, c_id INT, ship TEXT);",
11638+
"INSERT INTO c VALUES (1, 'CA'), (2, 'TX'), (3, 'MA'), (4, 'TX'), (5, NULL), (6, 'FL');",
11639+
"INSERT INTO o VALUES (10, 1, 'CA'), (20, 1, 'CA'), (30, 1, 'CA'), (40, 2, 'CA'), (50, 2, 'TX'), (60, 2, NULL), (70, 4, 'WY'), (80, 4, NULL), (90, 6, 'WA');",
11640+
},
11641+
Assertions: []ScriptTestAssertion{
11642+
{
11643+
Query: "select row_number() over () as rn from o where c_id=-999",
11644+
Expected: []sql.Row{},
11645+
},
11646+
{
11647+
Query: "select row_number() over () as rn from o where c_id=1",
11648+
Expected: []sql.Row{{1}, {2}, {3}},
11649+
},
11650+
{
11651+
Query: "select rank() over() as rnk from o where c_id=-999",
11652+
Expected: []sql.Row{},
11653+
},
11654+
{
11655+
Query: "select o_id, c_id, rank() over(order by o_id) as rnk from o where c_id=1",
11656+
Expected: []sql.Row{
11657+
{10, 1, uint64(1)},
11658+
{20, 1, uint64(2)},
11659+
{30, 1, uint64(3)},
11660+
},
11661+
},
11662+
{
11663+
Query: "select dense_rank() over() as rnk from o where c_id=-999",
11664+
Expected: []sql.Row{},
11665+
},
11666+
{
11667+
Query: "select ship, dense_rank() over (order by ship) as drnk from o where c_id in (1, 2) order by ship",
11668+
Expected: []sql.Row{
11669+
{nil, uint64(1)},
11670+
{"CA", uint64(2)},
11671+
{"CA", uint64(2)},
11672+
{"CA", uint64(2)},
11673+
{"CA", uint64(2)},
11674+
{"TX", uint64(3)},
11675+
},
11676+
},
11677+
{
11678+
Query: "select count(*) from o where c_id=-999",
11679+
Expected: []sql.Row{{0}},
11680+
},
11681+
{
11682+
Query: "SELECT * FROM (SELECT c_id AS c_c_id, bill FROM c) sq1, LATERAL (SELECT row_number() OVER () AS rownum FROM o WHERE c_id = c_c_id) sq2 ORDER BY c_c_id, bill, rownum;",
11683+
Expected: []sql.Row{
11684+
{1, "CA", 1},
11685+
{1, "CA", 2},
11686+
{1, "CA", 3},
11687+
{2, "TX", 1},
11688+
{2, "TX", 2},
11689+
{2, "TX", 3},
11690+
{4, "TX", 1},
11691+
{4, "TX", 2},
11692+
{6, "FL", 1},
11693+
},
11694+
},
11695+
},
11696+
},
1163111697
}
1163211698

1163311699
var SpatialScriptTests = []ScriptTest{

sql/expression/function/aggregation/window_partition_test.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func TestWindowPartition_MaterializeOutput(t *testing.T) {
215215
require.ElementsMatch(t, expOutput, output)
216216
})
217217

218-
t.Run("nil input with partition by", func(t *testing.T) {
218+
t.Run("nil input", func(t *testing.T) {
219219
ctx := sql.NewEmptyContext()
220220
i := NewWindowPartitionIter(
221221
&WindowPartition{
@@ -231,24 +231,6 @@ func TestWindowPartition_MaterializeOutput(t *testing.T) {
231231
require.Equal(t, io.EOF, err)
232232
require.ElementsMatch(t, nil, output)
233233
})
234-
235-
//t.Run("nil input no partition by", func(t *testing.T) {
236-
// ctx := sql.NewEmptyContext()
237-
// i := NewWindowPartitionIter(
238-
// &WindowPartition{
239-
// PartitionBy: nil,
240-
// Aggs: []*Aggregation{
241-
// NewAggregation(NewCountAgg(expression.NewGetField(0, types.Int64, "z", true)), NewGroupByFramer()),
242-
// },
243-
// })
244-
// i.input = []sql.Row{}
245-
// i.partitions = []sql.WindowInterval{{0, 0}}
246-
// i.outputOrdering = nil
247-
// output, err := i.materializeOutput(ctx)
248-
// require.NoError(t, err)
249-
// expOutput := []sql.Row{{int64(0), nil}}
250-
// require.ElementsMatch(t, expOutput, output)
251-
//})
252234
}
253235

254236
func TestWindowPartition_SortAndFilterOutput(t *testing.T) {

0 commit comments

Comments
 (0)