Skip to content

Commit fcd8ea2

Browse files
committed
add more tests
1 parent e8e1045 commit fcd8ea2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

enginetest/queries/order_by_group_by_queries.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,43 @@ var OrderByGroupByScriptTests = []ScriptTest{
362362
},
363363
},
364364
},
365+
{
366+
Name: "valid group by order by queries",
367+
SetUpScript: []string{
368+
"create table t0(c0 int primary key, c1 int, c2 int, c3 int)",
369+
"insert into t0 values (3, 1, 3, 1), (4, 1, 7, 2), (5, 2, 9, 3),(6,2, 1, 3), (7,2, 2, 2),(8,3,2, 5)",
370+
},
371+
Assertions: []ScriptTestAssertion{
372+
{
373+
// group by primary key
374+
Query: "select c1 from t0 group by c0 order by c2",
375+
Expected: []sql.Row{{2}, {2}, {3}, {1}, {1}, {2}},
376+
},
377+
{
378+
// order by aggregate
379+
Query: "select c1 from t0 group by c1 order by min(c2)",
380+
Expected: []sql.Row{{2}, {3}, {1}},
381+
},
382+
{
383+
// order by alias for column in group by clause
384+
Query: "select c1 as col from t0 group by c1 order by col",
385+
Expected: []sql.Row{{1}, {2}, {3}},
386+
},
387+
{
388+
// order by alias for aggregate column
389+
Query: "select min(c0) as min, c1 from t0 group by c1 order by min",
390+
Expected: []sql.Row{{3, 1}, {5, 2}, {8, 3}},
391+
},
392+
{
393+
// order by multiple columns
394+
Query: "select c1 from t0 group by c1, c2, c3 order by c2, c3",
395+
Expected: []sql.Row{{2}, {2}, {3}, {1}, {1}, {2}},
396+
},
397+
{
398+
// order by functionally dependent column
399+
Query: "select c1 from t0 where c2 = 3 group by c1 order by c2",
400+
Expected: []sql.Row{{1}},
401+
},
402+
},
403+
},
365404
}

0 commit comments

Comments
 (0)