Skip to content

Commit b79502c

Browse files
authored
Merge pull request #3009 from dolthub/zachmu/group_concat
New skipped tests for group_concat
2 parents b7b74d4 + e361051 commit b79502c

File tree

1 file changed

+162
-5
lines changed

1 file changed

+162
-5
lines changed

enginetest/queries/script_queries.go

Lines changed: 162 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ CREATE TABLE tab3 (
16751675
"INSERT INTO tab2 VALUES (1, 'b'), (2, 'm'), (3, 'g')",
16761676
"SELECT m.id, t.s FROM tab1 m JOIN tab2 t on m.id = t.i2 ORDER BY t.s DESC LIMIT 1 INTO @myId, @myText",
16771677
// TODO: union statement does not handle order by and limit clauses
1678-
//"SELECT id FROM tab1 UNION select s FROM tab2 LIMIT 1 INTO @myUnion",
1678+
// "SELECT id FROM tab1 UNION select s FROM tab2 LIMIT 1 INTO @myUnion",
16791679
"SELECT id FROM tab1 WHERE id > 3 UNION select s FROM tab2 WHERE s < 'f' INTO @mustSingleVar",
16801680
},
16811681
Assertions: []ScriptTestAssertion{
@@ -2760,6 +2760,163 @@ CREATE TABLE tab3 (
27602760
},
27612761
},
27622762
},
2763+
{
2764+
Name: "Group Concat with Subquery in ORDER BY",
2765+
Dialect: "mysql",
2766+
SetUpScript: []string{
2767+
"CREATE TABLE test_data (id INT PRIMARY KEY, name VARCHAR(50), age INT, category VARCHAR(10))",
2768+
`INSERT INTO test_data VALUES
2769+
(1, 'Alice', 25, 'A'),
2770+
(2, 'Bob', 30, 'B'),
2771+
(3, 'Charlie', 22, 'A'),
2772+
(4, 'Diana', 28, 'C'),
2773+
(5, 'Eve', 35, 'B'),
2774+
(6, 'Frank', 26, 'A')`,
2775+
},
2776+
Assertions: []ScriptTestAssertion{
2777+
{
2778+
Skip: true,
2779+
Query: "SELECT category, group_concat(name ORDER BY (SELECT COUNT(*) FROM test_data t2 WHERE t2.category = test_data.category AND t2.age < test_data.age)) FROM test_data GROUP BY category ORDER BY category",
2780+
Expected: []sql.Row{{"A", "Charlie,Alice,Frank"}, {"B", "Bob,Eve"}, {"C", "Diana"}},
2781+
},
2782+
{
2783+
Skip: true,
2784+
Query: "SELECT group_concat(name ORDER BY (SELECT AVG(age) FROM test_data t2 WHERE t2.category = test_data.category), id) FROM test_data;",
2785+
Expected: []sql.Row{{"Alice,Charlie,Frank,Diana,Bob,Eve"}},
2786+
},
2787+
{
2788+
Query: "SELECT category, group_concat(name ORDER BY (SELECT MAX(age) FROM test_data t2 WHERE t2.id <= test_data.id)) FROM test_data GROUP BY category ORDER BY category",
2789+
Expected: []sql.Row{{"A", "Alice,Charlie,Frank"}, {"B", "Bob,Eve"}, {"C", "Diana"}},
2790+
},
2791+
},
2792+
},
2793+
{
2794+
Name: "Group Concat with Subquery in ORDER BY - Additional Edge Cases",
2795+
Dialect: "mysql",
2796+
SetUpScript: []string{
2797+
"CREATE TABLE products (id INT PRIMARY KEY, name VARCHAR(50), price DECIMAL(10,2), category_id INT, supplier_id INT)",
2798+
"CREATE TABLE categories (id INT PRIMARY KEY, name VARCHAR(50), priority INT)",
2799+
"CREATE TABLE suppliers (id INT PRIMARY KEY, name VARCHAR(50), rating INT)",
2800+
"INSERT INTO products VALUES (1, 'Laptop', 999.99, 1, 1), (2, 'Mouse', 25.50, 1, 2), (3, 'Keyboard', 75.00, 1, 1)",
2801+
"INSERT INTO products VALUES (4, 'Chair', 150.00, 2, 3), (5, 'Desk', 300.00, 2, 3), (6, 'Monitor', 250.00, 1, 2)",
2802+
"INSERT INTO categories VALUES (1, 'Electronics', 1), (2, 'Furniture', 2)",
2803+
"INSERT INTO suppliers VALUES (1, 'TechCorp', 5), (2, 'GadgetInc', 4), (3, 'OfficeSupply', 3)",
2804+
},
2805+
Assertions: []ScriptTestAssertion{
2806+
{
2807+
Skip: true,
2808+
Query: "SELECT category_id, GROUP_CONCAT(name ORDER BY (SELECT rating FROM suppliers WHERE suppliers.id = products.supplier_id) DESC, id ASC) FROM products GROUP BY category_id ORDER BY category_id",
2809+
Expected: []sql.Row{{1, "Laptop,Keyboard,Mouse,Monitor"}, {2, "Chair,Desk"}},
2810+
},
2811+
{
2812+
Skip: true,
2813+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT COUNT(*) FROM products p2 WHERE p2.price < products.price), id) FROM products",
2814+
Expected: []sql.Row{{"Mouse,Keyboard,Chair,Monitor,Desk,Laptop"}},
2815+
},
2816+
{
2817+
Skip: true,
2818+
Query: "SELECT category_id, GROUP_CONCAT(DISTINCT supplier_id ORDER BY (SELECT rating FROM suppliers WHERE suppliers.id = products.supplier_id)) FROM products GROUP BY category_id",
2819+
Expected: []sql.Row{{1, "2,1"}, {2, "3"}},
2820+
},
2821+
{
2822+
Skip: true,
2823+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT priority FROM categories WHERE categories.id = products.category_id), price) FROM products",
2824+
Expected: []sql.Row{{"Mouse,Keyboard,Monitor,Laptop,Chair,Desk"}},
2825+
},
2826+
{
2827+
Query: "SELECT category_id, GROUP_CONCAT(name ORDER BY (SELECT AVG(price) FROM products p2 WHERE p2.category_id = products.category_id) DESC, name) FROM products GROUP BY category_id ORDER BY category_id",
2828+
Expected: []sql.Row{{1, "Keyboard,Laptop,Monitor,Mouse"}, {2, "Chair,Desk"}},
2829+
},
2830+
},
2831+
},
2832+
{
2833+
Name: "Group Concat Subquery ORDER BY Error Cases",
2834+
Dialect: "mysql",
2835+
SetUpScript: []string{
2836+
"CREATE TABLE test_table (id INT PRIMARY KEY, name VARCHAR(50), value INT)",
2837+
"INSERT INTO test_table VALUES (1, 'A', 10), (2, 'B', 20), (3, 'C', 30)",
2838+
},
2839+
Assertions: []ScriptTestAssertion{
2840+
{
2841+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT name, value FROM test_table t2 WHERE t2.id = test_table.id)) FROM test_table",
2842+
ExpectedErr: sql.ErrInvalidOperandColumns,
2843+
},
2844+
{
2845+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT value FROM test_table)) FROM test_table",
2846+
ExpectedErr: sql.ErrExpectedSingleRow,
2847+
},
2848+
},
2849+
},
2850+
{
2851+
Name: "Group Concat Subquery ORDER BY Additional Edge Cases",
2852+
Dialect: "mysql",
2853+
SetUpScript: []string{
2854+
"CREATE TABLE complex_test (id INT PRIMARY KEY, name VARCHAR(50), value INT, category VARCHAR(10), created_at DATE)",
2855+
"INSERT INTO complex_test VALUES (1, 'Alpha', 100, 'X', '2023-01-01')",
2856+
"INSERT INTO complex_test VALUES (2, 'Beta', 50, 'Y', '2023-01-15')",
2857+
"INSERT INTO complex_test VALUES (3, 'Gamma', 75, 'X', '2023-02-01')",
2858+
"INSERT INTO complex_test VALUES (4, 'Delta', 25, 'Z', '2023-02-15')",
2859+
"INSERT INTO complex_test VALUES (5, 'Epsilon', 90, 'Y', '2023-03-01')",
2860+
},
2861+
Assertions: []ScriptTestAssertion{
2862+
{
2863+
// Test with subquery returning NULL values
2864+
Skip: true,
2865+
Query: "SELECT category, GROUP_CONCAT(name ORDER BY (SELECT CASE WHEN complex_test.value > 80 THEN NULL ELSE complex_test.value END), name) FROM complex_test GROUP BY category ORDER BY category",
2866+
Expected: []sql.Row{{"X", "Alpha,Gamma"}, {"Y", "Epsilon,Beta"}, {"Z", "Delta"}},
2867+
},
2868+
{
2869+
// Test with correlated subquery using multiple tables
2870+
Skip: true,
2871+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT COUNT(*) FROM complex_test c2 WHERE c2.category = complex_test.category AND c2.value > complex_test.value), name) FROM complex_test",
2872+
Expected: []sql.Row{{"Alpha,Delta,Epsilon,Beta,Gamma"}},
2873+
},
2874+
{
2875+
// Test with subquery using aggregate functions with HAVING
2876+
Skip: true,
2877+
Query: "SELECT category, GROUP_CONCAT(name ORDER BY (SELECT AVG(value), name FROM complex_test c2 WHERE c2.id <= complex_test.id HAVING AVG(value) > 50) DESC) FROM complex_test GROUP BY category ORDER BY category",
2878+
Expected: []sql.Row{{"X", "Alpha,Gamma"}, {"Y", "Beta,Epsilon"}, {"Z", "Delta"}},
2879+
},
2880+
{
2881+
// Test with DISTINCT and complex subquery
2882+
Query: "SELECT GROUP_CONCAT(DISTINCT category ORDER BY (SELECT SUM(value) FROM complex_test c2 WHERE c2.category = complex_test.category) DESC SEPARATOR '|') FROM complex_test",
2883+
Expected: []sql.Row{{"X|Y|Z"}},
2884+
},
2885+
{
2886+
// Test with nested subqueries
2887+
Skip: true,
2888+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT COUNT(*) FROM complex_test c2 WHERE c2.value > (SELECT MIN(value) FROM complex_test c3 WHERE c3.category = complex_test.category))) FROM complex_test",
2889+
Expected: []sql.Row{{"Gamma,Alpha,Epsilon,Beta,Delta"}},
2890+
},
2891+
},
2892+
},
2893+
{
2894+
Name: "Group Concat Subquery ORDER BY Performance and Boundary Cases",
2895+
Dialect: "mysql",
2896+
SetUpScript: []string{
2897+
"CREATE TABLE perf_test (id INT PRIMARY KEY, data VARCHAR(10), weight DECIMAL(5,2))",
2898+
"INSERT INTO perf_test VALUES (1, 'A', 1.5), (2, 'B', 2.5), (3, 'C', 0.5), (4, 'D', 3.5), (5, 'E', 2.0)",
2899+
},
2900+
Assertions: []ScriptTestAssertion{
2901+
{
2902+
// Test with subquery returning same value for multiple rows (stability)
2903+
Query: "SELECT GROUP_CONCAT(data ORDER BY (SELECT 42), id) FROM perf_test",
2904+
Expected: []sql.Row{{"A,B,C,D,E"}},
2905+
},
2906+
{
2907+
// Test with subquery using LIMIT
2908+
Skip: true,
2909+
Query: "SELECT GROUP_CONCAT(data ORDER BY (SELECT weight FROM perf_test p2 WHERE p2.id = perf_test.id LIMIT 1)) FROM perf_test",
2910+
Expected: []sql.Row{{"C,A,E,B,D"}},
2911+
},
2912+
{
2913+
// Test with very small decimal differences in ORDER BY subquery
2914+
Skip: true,
2915+
Query: "SELECT GROUP_CONCAT(data ORDER BY (SELECT weight + 0.001 * perf_test.id FROM perf_test p2 WHERE p2.id = perf_test.id)) FROM perf_test",
2916+
Expected: []sql.Row{{"C,A,E,B,D"}},
2917+
},
2918+
},
2919+
},
27632920
{
27642921
Name: "CONVERT USING still converts between incompatible character sets",
27652922
Dialect: "mysql",
@@ -2998,7 +3155,7 @@ CREATE TABLE tab3 (
29983155
`CREATE TABLE t1 (pk int PRIMARY KEY, v1 varchar(10))`,
29993156
`INSERT INTO t1 VALUES (1,"1"), (2,"2"), (3,"3")`,
30003157
`CREATE TABLE t2 AS SELECT * FROM t1`,
3001-
//`CREATE TABLE t3(v0 int) AS SELECT pk FROM t1`, // parser problems
3158+
// `CREATE TABLE t3(v0 int) AS SELECT pk FROM t1`, // parser problems
30023159
`CREATE TABLE t3 AS SELECT pk FROM t1`,
30033160
`CREATE TABLE t4 AS SELECT pk, v1 FROM t1`,
30043161
`CREATE TABLE t5 SELECT * FROM t1 ORDER BY pk LIMIT 1`,
@@ -3163,7 +3320,7 @@ CREATE TABLE tab3 (
31633320
},
31643321
},
31653322
},
3166-
//todo(max): fix arithmatic on bindvar typing
3323+
// todo(max): fix arithmatic on bindvar typing
31673324
SkipPrepared: true,
31683325
},
31693326
{
@@ -4193,7 +4350,7 @@ CREATE TABLE tab3 (
41934350
// but GMS builds GroupBy for any aggregate function.
41944351
Skip: true,
41954352
Query: "select count(*) from numbers having count(*) > val;",
4196-
//ExpectedErrStr: "found HAVING clause with no GROUP BY", // not the exact error we want
4353+
// ExpectedErrStr: "found HAVING clause with no GROUP BY", // not the exact error we want
41974354
},
41984355
{
41994356
Query: "select count(*) from numbers group by val having count(*) < val;",
@@ -4205,7 +4362,7 @@ CREATE TABLE tab3 (
42054362
Name: "using having and group by clauses in subquery ",
42064363
SetUpScript: []string{
42074364
"CREATE TABLE t (i int, t varchar(2));",
4208-
"insert into t values (1, 'a'), (1, 'a2'), (2, 'b'), (3, 'c'), (3, 'c2'), (4, 'd'), (5, 'e'), (5, 'e2');", //, (6, 'f'), (7, 'g'), (7, 'g2')
4365+
"insert into t values (1, 'a'), (1, 'a2'), (2, 'b'), (3, 'c'), (3, 'c2'), (4, 'd'), (5, 'e'), (5, 'e2');", // , (6, 'f'), (7, 'g'), (7, 'g2')
42094366
},
42104367
Assertions: []ScriptTestAssertion{
42114368
{

0 commit comments

Comments
 (0)