Skip to content

Commit bbc1442

Browse files
committed
temporary: tests
1 parent 90c2400 commit bbc1442

File tree

1 file changed

+96
-13
lines changed

1 file changed

+96
-13
lines changed

enginetest/memory_engine_test.go

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,109 @@ func TestSingleQueryPrepared(t *testing.T) {
198198
enginetest.TestScriptWithEnginePrepared(t, engine, harness, test)
199199
}
200200

201+
// NOTE: This test works when we DO NOT include *plan.Project nodes
202+
func TestSingleTriggerScript(t *testing.T) {
203+
//t.Skip()
204+
var scripts = []queries.ScriptTest{
205+
{
206+
// TODO: This test is failing now!!!
207+
Name: "issue #9039: trigger insert projection index error",
208+
SetUpScript: []string{
209+
"create table a (x int primary key, y int default 1, z int)",
210+
"create table b (x int primary key)",
211+
"create table c (x int primary key, y tinyint)",
212+
"create table d (x int primary key)",
213+
"insert into b values (1), (2)",
214+
"insert into d values (1), (2)",
215+
`
216+
create trigger insert_into_a
217+
after insert on a
218+
for each row
219+
replace into c
220+
select max(d.x + new.x), 0 from d join b using (x)
221+
-- select d.x+2, 0 from d join b using (x)
222+
where d.x = new.x`,
223+
"insert into a (x,z) values (2,2)",
224+
},
225+
Query: "select x, y from c order by 1",
226+
Expected: []sql.Row{
227+
{4, 0},
228+
},
229+
},
230+
}
231+
232+
for _, test := range scripts {
233+
harness := enginetest.NewMemoryHarness("", 1, testNumPartitions, true, nil)
234+
//harness.UseServer()
235+
engine, err := harness.NewEngine(t)
236+
if err != nil {
237+
panic(err)
238+
}
239+
240+
engine.EngineAnalyzer().Debug = true
241+
engine.EngineAnalyzer().Verbose = true
242+
243+
enginetest.TestScriptWithEngine(t, engine, harness, test)
244+
}
245+
}
246+
201247
// Convenience test for debugging a single query. Unskip and set to the desired query.
202248
func TestSingleScript(t *testing.T) {
203-
t.Skip()
249+
//t.Skip()
250+
251+
// TODO: Move this into a trigger test
204252
var scripts = []queries.ScriptTest{
205253
{
206-
Name: "AS OF propagates to nested CALLs",
207-
SetUpScript: []string{},
254+
Name: "GROUP_CONCAT() use in triggers",
255+
SetUpScript: []string{
256+
`CREATE TABLE orders (
257+
id INT AUTO_INCREMENT PRIMARY KEY,
258+
customer_name VARCHAR(100),
259+
product VARCHAR(100),
260+
order_date DATETIME DEFAULT CURRENT_TIMESTAMP
261+
);`,
262+
263+
`CREATE TABLE order_audit (
264+
audit_id INT AUTO_INCREMENT PRIMARY KEY,
265+
customer_name VARCHAR(100),
266+
all_products TEXT,
267+
audit_time DATETIME DEFAULT CURRENT_TIMESTAMP
268+
);`,
269+
270+
`CREATE TRIGGER before_order_delete
271+
BEFORE DELETE ON orders
272+
FOR EACH ROW
273+
BEGIN
274+
DECLARE products TEXT;
275+
SELECT GROUP_CONCAT(product ORDER BY order_date SEPARATOR ', ')
276+
INTO products
277+
FROM orders
278+
WHERE customer_name = OLD.customer_name
279+
AND id != OLD.id;
280+
INSERT INTO order_audit (customer_name, all_products)
281+
VALUES (OLD.customer_name, products);
282+
END;`,
283+
284+
`INSERT INTO orders (customer_name, product) VALUES
285+
('Alice', 'Book'),
286+
('Alice', 'Pen'),
287+
('Bob', 'Notebook');`,
288+
},
208289
Assertions: []queries.ScriptTestAssertion{
209290
{
210-
Query: "create procedure create_proc() create table t (i int primary key, j int);",
211-
Expected: []sql.Row{
212-
{types.NewOkResult(0)},
213-
},
291+
// First try the query by itself
292+
Query: "SELECT GROUP_CONCAT(product ORDER BY order_date SEPARATOR ', ') FROM orders WHERE customer_name = 'Alice';",
293+
Expected: []sql.Row{{"Book, Pen"}},
214294
},
215295
{
216-
Query: "call create_proc()",
217-
Expected: []sql.Row{
218-
{types.NewOkResult(0)},
219-
},
296+
// Delete a row to trigger the BEFORE DELETE
297+
Query: "DELETE FROM orders WHERE customer_name = 'Alice' AND product = 'Pen';",
298+
Expected: []sql.Row{{types.NewOkResult(1)}},
220299
},
300+
//{
301+
// Query: "SELECT * FROM order_audit;",
302+
// Expected: []sql.Row{{"???"}},
303+
//},
221304
},
222305
},
223306
}
@@ -230,8 +313,8 @@ func TestSingleScript(t *testing.T) {
230313
panic(err)
231314
}
232315

233-
//engine.EngineAnalyzer().Debug = true
234-
//engine.EngineAnalyzer().Verbose = true
316+
engine.EngineAnalyzer().Debug = true
317+
engine.EngineAnalyzer().Verbose = true
235318

236319
enginetest.TestScriptWithEngine(t, engine, harness, test)
237320
}

0 commit comments

Comments
 (0)