Skip to content

Commit c31951c

Browse files
committed
Merge branch 'main' of https://github.com/dolthub/go-mysql-server into angela/system_variables
2 parents 99a392b + 6d94caa commit c31951c

File tree

181 files changed

+5439
-2185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+5439
-2185
lines changed

enginetest/enginetests.go

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,21 @@ func TestQueryPlanWithEngine(t *testing.T, harness Harness, e QueryEngine, tt qu
793793
})
794794
}
795795

796+
func TestQueryPlanScripts(t *testing.T, harness Harness) {
797+
harness.Setup(setup.MydbData)
798+
for _, script := range queries.QueryPlanScriptTests {
799+
if sh, ok := harness.(SkippingHarness); ok {
800+
if sh.SkipQueryTest(script.Name) {
801+
t.Run(script.Name, func(t *testing.T) {
802+
t.Skip(script.Name)
803+
})
804+
continue
805+
}
806+
}
807+
TestScript(t, harness, script)
808+
}
809+
}
810+
796811
func TestOrderByGroupBy(t *testing.T, harness Harness) {
797812
for _, tt := range queries.OrderByGroupByScriptTests {
798813
TestScript(t, harness, tt)
@@ -3372,19 +3387,15 @@ func TestDropDatabase(t *testing.T, harness Harness) {
33723387

33733388
func TestCreateForeignKeys(t *testing.T, harness Harness) {
33743389
harness.Setup(setup.MydbData, setup.MytableData)
3375-
e := mustNewEngine(t, harness)
3376-
defer e.Close()
33773390
for _, tt := range queries.CreateForeignKeyTests {
3378-
TestScriptWithEngine(t, e, harness, tt)
3391+
TestScript(t, harness, tt)
33793392
}
33803393
}
33813394

33823395
func TestDropForeignKeys(t *testing.T, harness Harness) {
33833396
harness.Setup(setup.MydbData, setup.MytableData)
3384-
e := mustNewEngine(t, harness)
3385-
defer e.Close()
33863397
for _, tt := range queries.DropForeignKeyTests {
3387-
TestScriptWithEngine(t, e, harness, tt)
3398+
TestScript(t, harness, tt)
33883399
}
33893400
}
33903401

@@ -4527,14 +4538,14 @@ func TestPreparedInsert(t *testing.T, harness Harness) {
45274538
Bindings: map[string]sqlparser.Expr{
45284539
"v1": mustBuildBindVariable([]byte{0x99, 0x98, 0x97}),
45294540
},
4530-
ExpectedErrStr: "invalid string for charset utf8mb4: '[153 152 151]'",
4541+
ExpectedErrStr: "Incorrect string value: '\\x99\\x98\\x97' for column 'v1' at row 1",
45314542
},
45324543
{
45334544
Query: "INSERT INTO test VALUES (?);",
45344545
Bindings: map[string]sqlparser.Expr{
45354546
"v1": mustBuildBindVariable(string([]byte{0x99, 0x98, 0x97})),
45364547
},
4537-
ExpectedErrStr: "invalid string for charset utf8mb4: '[153 152 151]'",
4548+
ExpectedErrStr: "Incorrect string value: '\\x99\\x98\\x97' for column 'v1' at row 1",
45384549
},
45394550
{
45404551
Query: "INSERT INTO test2 VALUES (?);",
@@ -6151,6 +6162,26 @@ func TestSQLLogicTests(t *testing.T, harness Harness) {
61516162
}
61526163
}
61536164

6165+
func TestTimeQueries(t *testing.T, harness Harness) {
6166+
// "America/Phoenix" is a non-UTC time zone that does not observe daylight savings time
6167+
phoenixTimeZone, _ := time.LoadLocation("America/Phoenix")
6168+
mockNow := time.Date(2025, time.July, 23, 9, 43, 21, 0, phoenixTimeZone)
6169+
for _, script := range queries.TimeQueryTests {
6170+
if sh, ok := harness.(SkippingHarness); ok {
6171+
if sh.SkipQueryTest(script.Name) {
6172+
t.Run(script.Name, func(t *testing.T) {
6173+
t.Skip(script.Name)
6174+
})
6175+
continue
6176+
}
6177+
}
6178+
sql.RunWithNowFunc(func() time.Time { return mockNow }, func() error {
6179+
TestScript(t, harness, script)
6180+
return nil
6181+
})
6182+
}
6183+
}
6184+
61546185
// ExecuteNode builds an iterator and then drains it.
61556186
// This is useful for populating actual row counts for `DESCRIBE ANALYZE`.
61566187
func ExecuteNode(ctx *sql.Context, engine QueryEngine, node sql.Node) error {

enginetest/evaluation.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,20 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
144144
}
145145
TestQueryWithContext(t, ctx, e, harness, assertion.Query, expected, assertion.ExpectedColumns, assertion.Bindings, nil)
146146
}
147+
147148
if assertion.ExpectedIndexes != nil && !IsServerEngine(e) {
148149
evalIndexTest(t, harness, e, assertion.Query, assertion.ExpectedIndexes, assertion.Skip)
149150
}
150151
if assertion.JoinTypes != nil && !IsServerEngine(e) {
151152
evalJoinTypeTest(t, harness, e, assertion.Query, assertion.JoinTypes, assertion.Skip)
152153
}
154+
155+
if assertion.ExpectedPlan != "" && !IsServerEngine(e) {
156+
options := sql.DescribeOptions{
157+
Debug: true,
158+
}
159+
TestQueryPlanWithName(t, options.String(), harness, e, assertion.Query, assertion.ExpectedPlan, options)
160+
}
153161
})
154162
}
155163
})
@@ -852,7 +860,7 @@ func WidenRow(t *testing.T, sch sql.Schema, row sql.Row) sql.Row {
852860
widened := make(sql.Row, len(row))
853861
for i, v := range row {
854862
if i < len(sch) && types.IsJSON(sch[i].Type) {
855-
widened[i] = widenJSONValues(v)
863+
widened[i] = widenJSONValues(t.Context(), v)
856864
continue
857865
}
858866

@@ -893,7 +901,7 @@ func widenValue(t *testing.T, v interface{}) (vw interface{}) {
893901
return vw
894902
}
895903

896-
func widenJSONValues(val interface{}) sql.JSONWrapper {
904+
func widenJSONValues(ctx context.Context, val interface{}) sql.JSONWrapper {
897905
if val == nil {
898906
return nil
899907
}
@@ -907,7 +915,7 @@ func widenJSONValues(val interface{}) sql.JSONWrapper {
907915
js = types.MustJSON(str)
908916
}
909917

910-
doc, err := js.ToInterface()
918+
doc, err := js.ToInterface(ctx)
911919
if err != nil {
912920
panic(err)
913921
}

enginetest/join_op_tests.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,18 @@ SELECT SUM(x) FROM xy WHERE x IN (
19211921
},
19221922
},
19231923
},
1924+
{
1925+
name: "where not exists",
1926+
setup: [][]string{
1927+
setup.XyData[0],
1928+
},
1929+
tests: []JoinOpTests{
1930+
{
1931+
Query: `select * from xy_hasnull x where not exists(select 1 from ab_hasnull a where a.b = x.y)`,
1932+
Expected: []sql.Row{{1, 0}, {3, nil}},
1933+
},
1934+
},
1935+
},
19241936
{
19251937
name: "multi-column merge join",
19261938
setup: [][]string{

enginetest/memory_engine_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ func TestSingleQuery(t *testing.T) {
156156
Expected: []sql.Row{{-1}},
157157
}
158158

159-
fmt.Sprintf("%v", test)
160159
harness := enginetest.NewMemoryHarness("", 1, testNumPartitions, true, nil)
161160
// harness.UseServer()
162161
harness.Setup(setup.MydbData, setup.NiltableData)
@@ -186,7 +185,6 @@ func TestSingleQueryPrepared(t *testing.T) {
186185
},
187186
}
188187

189-
fmt.Sprintf("%v", test)
190188
harness := enginetest.NewMemoryHarness("", 1, testNumPartitions, false, nil)
191189
harness.Setup(setup.KeylessSetup...)
192190
engine, err := harness.NewEngine(t)
@@ -329,6 +327,10 @@ func TestQueryPlans(t *testing.T) {
329327
}
330328
}
331329

330+
func TestQueryPlanScripts(t *testing.T) {
331+
enginetest.TestQueryPlanScripts(t, enginetest.NewMemoryHarness("default", 1, testNumPartitions, true, mergableIndexDriver))
332+
}
333+
332334
func TestSingleQueryPlan(t *testing.T) {
333335
t.Skip()
334336
tt := []queries.QueryPlanTest{
@@ -1099,3 +1101,7 @@ func TestSQLLogicTestFiles(t *testing.T) {
10991101
}
11001102
logictest.RunTestFiles(h, paths...)
11011103
}
1104+
1105+
func TestTimeQueries(t *testing.T) {
1106+
enginetest.TestTimeQueries(t, enginetest.NewDefaultMemoryHarness())
1107+
}

0 commit comments

Comments
 (0)