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
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -55,7 +55,7 @@ g.test_cte = function ()
t.assert_items_equals(r["metadata"], { {name = "CTE.B", type = "number"} })
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", { [[
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"
......@@ -67,6 +67,18 @@ g.test_cte = function ()
)
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
r, err = api:call("sbroad.execute", { [[
WITH cte (b) AS (SELECT "a" FROM "t" WHERE "id" > 3)
......
......@@ -263,14 +263,13 @@ impl ExecutionPlan {
/// # Errors
/// - node is not valid
pub fn get_motion_alias(&self, node_id: usize) -> Result<Option<SmolStr>, SbroadError> {
let sq_id = &self.get_motion_child(node_id)?;
if let Relational::ScanSubQuery { alias, .. } =
self.get_ir_plan().get_relation_node(*sq_id)?
{
return Ok(alias.clone());
let child_id = &self.get_motion_child(node_id)?;
let child_rel = self.get_ir_plan().get_relation_node(*child_id)?;
match child_rel {
Relational::ScanSubQuery { alias, .. } => Ok(alias.clone()),
Relational::ScanCte { alias, .. } => Ok(Some(alias.clone())),
_ => Ok(None),
}
Ok(None)
}
/// 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