Skip to content

Commit

Permalink
feat(core): support querying window function
Browse files Browse the repository at this point in the history
  • Loading branch information
grieve54706 committed Dec 13, 2024
1 parent d10de9a commit 29778d6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions wren-core/core/src/logical_plan/analyze/model_anlayze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ impl ModelAnalyzeRule {
scope_mut.add_visited_table(subquery_alias.alias.clone());
Ok(Transformed::no(plan))
}
LogicalPlan::Window(window) => {
let mut scope_mut = scope.borrow_mut();
window
.window_expr
.iter()
.fold(HashSet::new(), |mut set, expr| {
Expr::add_column_refs(expr, &mut set);
set
})
.into_iter()
.try_for_each(|col| {
self.collect_required_column(
Expr::Column(col.to_owned()),
&mut scope_mut,
)
})?;
Ok(Transformed::no(plan))
}
_ => Ok(Transformed::no(plan)),
}
}
Expand Down
1 change: 1 addition & 0 deletions wren-core/core/src/mdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ mod test {
"select o_orderkey, count(*) from test.test.orders where orders.o_totalprice > 10 group by 1",
"select totalcost from test.test.profile",
"select totalcost from profile",
"select sum(c_custkey) over (order by c_name) from test.test.customer limit 1",
// TODO: support calculated without relationship
// "select orderkey_plus_custkey from orders",
];
Expand Down
3 changes: 3 additions & 0 deletions wren-core/sqllogictest/test_files/model.slt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ select * from wrenai.public."Customers";
statement ok
select count(*) from wrenai.public."Order_items";

statement ok
select sum("Price") over (order by "Product_id") from wrenai.public."Order_items" limit 1;

# check the count of order_items won't be increased by the relationship calculation
query B
select cnt1 = cnt2 from (select count(*) as cnt1 from (select "Customer_state" from wrenai.public."Order_items")), (select count(*) as cnt2 from datafusion.public.order_items) limit 1;
Expand Down

0 comments on commit 29778d6

Please sign in to comment.