|
15 | 15 | package queries |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "fmt" |
18 | 19 | "math" |
19 | 20 | "time" |
20 | 21 |
|
@@ -121,6 +122,71 @@ type ScriptTestAssertion struct { |
121 | 122 | // Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of |
122 | 123 | // the tests. |
123 | 124 | var ScriptTests = []ScriptTest{ |
| 125 | + { |
| 126 | + // https://github.com/dolthub/dolt/issues/9873 |
| 127 | + // TODO: `FOR UPDATE OF` (`FOR UPDATE` in general) is currently a no-op: https://www.dolthub.com/blog/2023-10-23-hold-my-beer/ |
| 128 | + Name: "FOR UPDATE OF syntax support tests", |
| 129 | + Dialect: "mysql", |
| 130 | + SetUpScript: []string{ |
| 131 | + "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)", |
| 132 | + "CREATE TABLE job (id INT PRIMARY KEY, state VARCHAR(50))", |
| 133 | + "CREATE TABLE dag_run (dag_id VARCHAR(255), run_id VARCHAR(255), state VARCHAR(50))", |
| 134 | + "CREATE TABLE t (id INT PRIMARY KEY, name VARCHAR(50))", |
| 135 | + "INSERT INTO task_instance VALUES (1, 'task1', 'dag1', 'run1', 'running', 1)", |
| 136 | + "INSERT INTO job VALUES (1, 'running')", |
| 137 | + "INSERT INTO dag_run VALUES ('dag1', 'run1', 'running')", |
| 138 | + "INSERT INTO t VALUES (1, 'test')", |
| 139 | + }, |
| 140 | + Assertions: []ScriptTestAssertion{ |
| 141 | + { |
| 142 | + Query: `SELECT task_instance.id, task_instance.task_id, task_instance.dag_id, task_instance.run_id |
| 143 | +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 |
| 144 | + 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`, |
| 145 | + Expected: []sql.Row{}, |
| 146 | + }, |
| 147 | + { |
| 148 | + Query: "SELECT * FROM t FOR UPDATE", |
| 149 | + Expected: []sql.Row{{1, "test"}}, |
| 150 | + }, |
| 151 | + { |
| 152 | + Query: "SELECT * FROM t FOR UPDATE OF t", |
| 153 | + Expected: []sql.Row{{1, "test"}}, |
| 154 | + }, |
| 155 | + { |
| 156 | + Query: "SELECT * FROM t FOR UPDATE OF t SKIP LOCKED", |
| 157 | + Expected: []sql.Row{{1, "test"}}, |
| 158 | + }, |
| 159 | + { |
| 160 | + Query: "SELECT * FROM t FOR UPDATE OF t NOWAIT", |
| 161 | + Expected: []sql.Row{{1, "test"}}, |
| 162 | + }, |
| 163 | + { |
| 164 | + Query: "SELECT * FROM task_instance t1, job t2 FOR UPDATE OF t1, t2", |
| 165 | + Expected: []sql.Row{{1, "task1", "dag1", "run1", "running", 1, 1, "running"}}, |
| 166 | + }, |
| 167 | + { |
| 168 | + Query: "SELECT * FROM t FOR UPDATE OF nonexistent_table", |
| 169 | + ExpectedErr: sql.ErrUnresolvedTableLock, |
| 170 | + }, |
| 171 | + { |
| 172 | + Query: "SELECT * FROM t FOR UPDATE OF t, nonexistent_table", |
| 173 | + ExpectedErr: sql.ErrUnresolvedTableLock, |
| 174 | + ExpectedErrStr: fmt.Sprintf(sql.ErrUnresolvedTableLock.Message, "nonexistent_table"), |
| 175 | + }, |
| 176 | + { |
| 177 | + Query: "SELECT * FROM t FOR UPDATE OF", |
| 178 | + ExpectedErr: sql.ErrSyntaxError, |
| 179 | + }, |
| 180 | + { |
| 181 | + Query: "SELECT * FROM t FOR UPDATE test", |
| 182 | + ExpectedErr: sql.ErrSyntaxError, |
| 183 | + }, |
| 184 | + { |
| 185 | + Query: "SELECT * FROM t FOR UPDATE", |
| 186 | + Expected: []sql.Row{{1, "test"}}, |
| 187 | + }, |
| 188 | + }, |
| 189 | + }, |
124 | 190 | { |
125 | 191 | // https://github.com/dolthub/dolt/issues/9872 |
126 | 192 | Name: "TEXT(m) syntax support", |
|
0 commit comments