Skip to content

Commit f980416

Browse files
authored
Merge pull request #3180 from dolthub/elian/9738
dolthub/dolt#9738 - Add CREATE VIEW parentheses tests for MySQL compatibility
2 parents 0308d9f + bbe482d commit f980416

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

enginetest/queries/view_queries.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package queries
1616

1717
import (
18+
"time"
19+
1820
"github.com/dolthub/go-mysql-server/sql"
1921
"github.com/dolthub/go-mysql-server/sql/types"
2022
)
@@ -364,6 +366,47 @@ var ViewCreateInSubroutineTests = []ScriptTest{
364366
},
365367
},
366368
},
369+
{
370+
// https://github.com/dolthub/dolt/issues/9738
371+
Name: "CREATE VIEW with parentheses around SELECT",
372+
SetUpScript: []string{
373+
"CREATE TABLE test_table (id INT, name VARCHAR(50), active BOOLEAN);",
374+
"INSERT INTO test_table VALUES (1, 'Alice', true), (2, 'Bob', false), (3, 'Charlie', true);",
375+
"CREATE TABLE task_history (id INT, task VARCHAR(100), db_id INT, started_at DATETIME, ended_at DATETIME, duration INT, task_details TEXT);",
376+
"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');",
377+
},
378+
Assertions: []ScriptTestAssertion{
379+
{
380+
Query: "CREATE VIEW simple_view AS (SELECT id, name FROM test_table WHERE active = true);",
381+
Expected: []sql.Row{
382+
{types.NewOkResult(0)},
383+
},
384+
},
385+
{
386+
Query: "SELECT * FROM simple_view ORDER BY id;",
387+
Expected: []sql.Row{{1, "Alice"}, {3, "Charlie"}},
388+
},
389+
{
390+
Query: "CREATE VIEW complex_view AS (SELECT id, name, CONCAT('user_', id) AS user_id FROM test_table WHERE active = true);",
391+
Expected: []sql.Row{
392+
{types.NewOkResult(0)},
393+
},
394+
},
395+
{
396+
Query: "SELECT * FROM complex_view ORDER BY id;",
397+
Expected: []sql.Row{{1, "Alice", "user_1"}, {3, "Charlie", "user_3"}},
398+
},
399+
{
400+
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);",
401+
Expected: []sql.Row{
402+
{types.NewOkResult(0)},
403+
},
404+
},
405+
{
406+
Query: "SELECT * FROM v_tasks ORDER BY id;",
407+
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"}},
408+
}},
409+
},
367410
{
368411
Name: "trigger contains CREATE VIEW AS",
369412
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-20250828002016-b8fc8e714bf8
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
1818
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
1919
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
2020
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
21-
github.com/dolthub/vitess v0.0.0-20250828002016-b8fc8e714bf8 h1:RJwo+L0E5NDcYsipjwWau0I85SlPPhtx9xN2UMYtfd4=
22-
github.com/dolthub/vitess v0.0.0-20250828002016-b8fc8e714bf8/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
21+
github.com/dolthub/vitess v0.0.0-20250730174048-497aebb8cea7 h1:l+mWO0xoh4eG1J9gMS87opL6N6WGAQitF36R/Lg4bWs=
22+
github.com/dolthub/vitess v0.0.0-20250730174048-497aebb8cea7/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
23+
github.com/dolthub/vitess v0.0.0-20250813175212-45844169a751 h1:BBQKyvyODewdQxS+ICklMn1d/fFj2pVlkmMN1QFY4ms=
24+
github.com/dolthub/vitess v0.0.0-20250813175212-45844169a751/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
25+
github.com/dolthub/vitess v0.0.0-20250814204310-c749d213f235 h1:uXrK+xn8rCwz/8jWDKaDyqZG1HbZI9F4V4HJ7zXFPMY=
26+
github.com/dolthub/vitess v0.0.0-20250814204310-c749d213f235/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
27+
github.com/dolthub/vitess v0.0.0-20250828224346-f347481664da h1:8yD4o8bK8giyoJvjxYQ48mmNoBQ1WaBOUbIGhP3J0Ms=
28+
github.com/dolthub/vitess v0.0.0-20250828224346-f347481664da/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
2329
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
2430
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
2531
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

0 commit comments

Comments
 (0)