Skip to content

Commit f468825

Browse files
committed
enginetest: add CREATE VIEW parentheses tests for MySQL compatibility
1 parent a5d281d commit f468825

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

enginetest/queries/view_queries.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package queries
1717
import (
1818
"github.com/dolthub/go-mysql-server/sql"
1919
"github.com/dolthub/go-mysql-server/sql/types"
20+
"time"
2021
)
2122

2223
var ViewScripts = []ScriptTest{
@@ -364,6 +365,47 @@ var ViewCreateInSubroutineTests = []ScriptTest{
364365
},
365366
},
366367
},
368+
{
369+
// https://github.com/dolthub/dolt/issues/9738
370+
Name: "CREATE VIEW with parentheses around SELECT",
371+
SetUpScript: []string{
372+
"CREATE TABLE test_table (id INT, name VARCHAR(50), active BOOLEAN);",
373+
"INSERT INTO test_table VALUES (1, 'Alice', true), (2, 'Bob', false), (3, 'Charlie', true);",
374+
"CREATE TABLE task_history (id INT, task VARCHAR(100), db_id INT, started_at DATETIME, ended_at DATETIME, duration INT, task_details TEXT);",
375+
"INSERT INTO task_history VALUES (1, 'Task 1', 1, '2023-01-01 10:00:00', '2023-01-01 11:00:00', 3600000, 'Task details 1'), (2, 'Task 2', 2, '2023-01-02 10:00:00', '2023-01-02 12:00:00', 7200000, 'Task details 2');",
376+
},
377+
Assertions: []ScriptTestAssertion{
378+
{
379+
Query: "CREATE VIEW simple_view AS (SELECT id, name FROM test_table WHERE active = true);",
380+
Expected: []sql.Row{
381+
{types.NewOkResult(0)},
382+
},
383+
},
384+
{
385+
Query: "SELECT * FROM simple_view ORDER BY id;",
386+
Expected: []sql.Row{{1, "Alice"}, {3, "Charlie"}},
387+
},
388+
{
389+
Query: "CREATE VIEW complex_view AS (SELECT id, name, CONCAT('user_', id) AS user_id FROM test_table WHERE active = true);",
390+
Expected: []sql.Row{
391+
{types.NewOkResult(0)},
392+
},
393+
},
394+
{
395+
Query: "SELECT * FROM complex_view ORDER BY id;",
396+
Expected: []sql.Row{{1, "Alice", "user_1"}, {3, "Charlie", "user_3"}},
397+
},
398+
{
399+
Query: "CREATE OR REPLACE VIEW v_tasks AS (SELECT id, task, CONCAT('database_', db_id) AS database_qualified_id, started_at, ended_at, CAST(duration AS DOUBLE) / 1000 AS duration_seconds, task_details AS details FROM task_history);",
400+
Expected: []sql.Row{
401+
{types.NewOkResult(0)},
402+
},
403+
},
404+
{
405+
Query: "SELECT * FROM v_tasks ORDER BY id;",
406+
Expected: []sql.Row{{1, "Task 1", "database_1", time.Date(2023, time.January, 1, 10, 0, 0, 0, time.UTC), time.Date(2023, time.January, 1, 11, 0, 0, 0, time.UTC), 3600.0, "Task details 1"}, {2, "Task 2", "database_2", time.Date(2023, time.January, 2, 10, 0, 0, 0, time.UTC), time.Date(2023, time.January, 2, 12, 0, 0, 0, time.UTC), 7200.0, "Task details 2"}},
407+
}},
408+
},
367409
{
368410
Name: "trigger contains CREATE VIEW AS",
369411
SetUpScript: []string{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250820171420-f2b78f56ce9f
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250814204310-c749d213f235
9+
github.com/dolthub/vitess v0.0.0-20250828224346-f347481664da
1010
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1111
github.com/gocraft/dbr/v2 v2.7.2
1212
github.com/google/uuid v1.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ github.com/dolthub/vitess v0.0.0-20250813175212-45844169a751 h1:BBQKyvyODewdQxS+
2626
github.com/dolthub/vitess v0.0.0-20250813175212-45844169a751/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
2727
github.com/dolthub/vitess v0.0.0-20250814204310-c749d213f235 h1:uXrK+xn8rCwz/8jWDKaDyqZG1HbZI9F4V4HJ7zXFPMY=
2828
github.com/dolthub/vitess v0.0.0-20250814204310-c749d213f235/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
29+
github.com/dolthub/vitess v0.0.0-20250828224346-f347481664da h1:8yD4o8bK8giyoJvjxYQ48mmNoBQ1WaBOUbIGhP3J0Ms=
30+
github.com/dolthub/vitess v0.0.0-20250828224346-f347481664da/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
2931
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
3032
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
3133
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

0 commit comments

Comments
 (0)