Skip to content
Snippets Groups Projects
Commit 4cca62ee authored by Denis Smirnov's avatar Denis Smirnov
Browse files

fix: cte with left join

parent 5e9782b9
Loading
Pipeline #39912 failed
...@@ -55,7 +55,7 @@ g.test_cte = function () ...@@ -55,7 +55,7 @@ g.test_cte = function ()
t.assert_items_equals(r["metadata"], { {name = "CTE.B", type = "number"} }) t.assert_items_equals(r["metadata"], { {name = "CTE.B", type = "number"} })
t.assert_items_equals(r["rows"], { {4}, {5}, {4}, {5} }) t.assert_items_equals(r["rows"], { {4}, {5}, {4}, {5} })
-- join table with cte -- inner join table with cte
r, err = api:call("sbroad.execute", { [[ r, err = api:call("sbroad.execute", { [[
WITH cte (b) AS (SELECT "a" FROM "t" WHERE "id" = 1 OR "id" = 2) WITH cte (b) AS (SELECT "a" FROM "t" WHERE "id" = 1 OR "id" = 2)
SELECT cte.b, "t"."a" FROM cte JOIN "t" ON cte.b = "t"."id" SELECT cte.b, "t"."a" FROM cte JOIN "t" ON cte.b = "t"."id"
...@@ -67,6 +67,18 @@ g.test_cte = function () ...@@ -67,6 +67,18 @@ g.test_cte = function ()
) )
t.assert_items_equals(r["rows"], { {1, 1}, {2, 2} }) t.assert_items_equals(r["rows"], { {1, 1}, {2, 2} })
-- left outer join table with cte
r, err = api:call("sbroad.execute", { [[
WITH cte (b) AS (SELECT "a" FROM "t" WHERE "id" = 1 OR "id" = 2)
SELECT cte.b, "t"."a" FROM cte LEFT JOIN "t" ON cte.b = "t"."id"
]], })
t.assert_equals(err, nil)
t.assert_items_equals(
r["metadata"],
{ {name = "B", type = "number"}, {name = "a", type = "number"} }
)
t.assert_items_equals( r["rows"], { {1, 1}, {2, 2} })
-- cte in aggregate -- cte in aggregate
r, err = api:call("sbroad.execute", { [[ r, err = api:call("sbroad.execute", { [[
WITH cte (b) AS (SELECT "a" FROM "t" WHERE "id" > 3) WITH cte (b) AS (SELECT "a" FROM "t" WHERE "id" > 3)
......
...@@ -263,14 +263,13 @@ impl ExecutionPlan { ...@@ -263,14 +263,13 @@ impl ExecutionPlan {
/// # Errors /// # Errors
/// - node is not valid /// - node is not valid
pub fn get_motion_alias(&self, node_id: usize) -> Result<Option<SmolStr>, SbroadError> { pub fn get_motion_alias(&self, node_id: usize) -> Result<Option<SmolStr>, SbroadError> {
let sq_id = &self.get_motion_child(node_id)?; let child_id = &self.get_motion_child(node_id)?;
if let Relational::ScanSubQuery { alias, .. } = let child_rel = self.get_ir_plan().get_relation_node(*child_id)?;
self.get_ir_plan().get_relation_node(*sq_id)? match child_rel {
{ Relational::ScanSubQuery { alias, .. } => Ok(alias.clone()),
return Ok(alias.clone()); Relational::ScanCte { alias, .. } => Ok(Some(alias.clone())),
_ => Ok(None),
} }
Ok(None)
} }
/// Get root from motion sub tree /// Get root from motion sub tree
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment