Skip to content

Commit 2577d99

Browse files
committed
add gms tests for
1 parent 5d3eaa8 commit 2577d99

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

enginetest/memory_engine_test.go

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,51 @@ func TestSingleQueryPrepared(t *testing.T) {
200200

201201
// Convenience test for debugging a single query. Unskip and set to the desired query.
202202
func TestSingleScript(t *testing.T) {
203-
t.Skip()
203+
// t.Skip()
204204
var scripts = []queries.ScriptTest{
205205
{
206-
Name: "AS OF propagates to nested CALLs",
207-
SetUpScript: []string{},
206+
// https://github.com/dolthub/dolt/issues/9873
207+
Name: "FOR UPDATE OF syntax support tests",
208+
SetUpScript: []string{
209+
"CREATE TABLE task_instance (id INT PRIMARY KEY, task_id VARCHAR(255), dag_id VARCHAR(255), run_id VARCHAR(255), state VARCHAR(50), queued_by_job_id INT)",
210+
"CREATE TABLE job (id INT PRIMARY KEY, state VARCHAR(50))",
211+
"CREATE TABLE dag_run (dag_id VARCHAR(255), run_id VARCHAR(255), state VARCHAR(50))",
212+
"CREATE TABLE t (id INT PRIMARY KEY, name VARCHAR(50))",
213+
"INSERT INTO task_instance VALUES (1, 'task1', 'dag1', 'run1', 'running', 1)",
214+
"INSERT INTO job VALUES (1, 'running')",
215+
"INSERT INTO dag_run VALUES ('dag1', 'run1', 'running')",
216+
"INSERT INTO t VALUES (1, 'test')",
217+
},
208218
Assertions: []queries.ScriptTestAssertion{
209219
{
210-
Query: "create procedure create_proc() create table t (i int primary key, j int);",
211-
Expected: []sql.Row{
212-
{types.NewOkResult(0)},
213-
},
220+
Query: `SELECT task_instance.id, task_instance.task_id, task_instance.dag_id, task_instance.run_id
221+
FROM task_instance INNER JOIN job ON job.id = task_instance.queued_by_job_id INNER JOIN dag_run ON dag_run.dag_id = task_instance.dag_id AND dag_run.run_id = task_instance.run_id
222+
WHERE task_instance.state IN ('running', 'queued', 'scheduled') AND NOT (job.state <=> 'running') AND dag_run.state = 'running' FOR UPDATE OF task_instance SKIP LOCKED`,
223+
Expected: []sql.Row{},
214224
},
215225
{
216-
Query: "call create_proc()",
217-
Expected: []sql.Row{
218-
{types.NewOkResult(0)},
219-
},
226+
Query: "SELECT * FROM t FOR UPDATE",
227+
Expected: []sql.Row{{1, "test"}},
228+
},
229+
{
230+
Query: "SELECT * FROM t FOR UPDATE OF t",
231+
Expected: []sql.Row{{1, "test"}},
232+
},
233+
{
234+
Query: "SELECT * FROM t FOR UPDATE OF t SKIP LOCKED",
235+
Expected: []sql.Row{{1, "test"}},
236+
},
237+
{
238+
Query: "SELECT * FROM t FOR UPDATE OF t NOWAIT",
239+
Expected: []sql.Row{{1, "test"}},
240+
},
241+
{
242+
Query: "SELECT * FROM task_instance t1, job t2 FOR UPDATE OF t1, t2",
243+
Expected: []sql.Row{{1, "task1", "dag1", "run1", "running", 1, 1, "running"}},
244+
},
245+
{
246+
Query: "SELECT * FROM t FOR UPDATE OF nonexistent_table",
247+
ExpectedErr: true,
220248
},
221249
},
222250
},

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ require (
4242
)
4343

4444
go 1.25
45+
46+
replace github.com/dolthub/vitess => /workspace/vitess

sql/planbuilder/select.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919

2020
ast "github.com/dolthub/vitess/go/vt/sqlparser"
21+
"github.com/sirupsen/logrus"
2122

2223
"github.com/dolthub/go-mysql-server/sql"
2324
"github.com/dolthub/go-mysql-server/sql/expression"
@@ -59,6 +60,14 @@ func (b *Builder) buildSelect(inScope *scope, s *ast.Select) (outScope *scope) {
5960
// 5) Build top-level scopes, replacing aggregation and aliases with
6061
// projections from (4).
6162
// 6) Finish with final target projections.
63+
64+
// Process the Lock field for FOR UPDATE clauses
65+
if s.Lock != "" {
66+
logrus.Info("SELECT statement has Lock field:", s.Lock)
67+
// For now, we'll just log the lock information
68+
// In a full implementation, this would create a lock node
69+
// that would be applied to the final query result
70+
}
6271
fromScope := b.buildFrom(inScope, s.From)
6372
if cn, ok := fromScope.node.(sql.CommentedNode); ok && len(s.Comments) > 0 {
6473
fromScope.node = cn.WithComment(string(s.Comments[0]))

0 commit comments

Comments
 (0)