Skip to content

Commit f237cbd

Browse files
authored
fix(query): allow window expr in group by query (#17962)
* chore(query): allow window expr in group by query * chore(query): allow window expr in group by query * chore(query): allow window expr in group by query
1 parent 39fd730 commit f237cbd

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,13 @@ jobs:
417417
version: ${{ needs.create_release.outputs.version }}
418418
arch: ${{ matrix.arch }}
419419

420-
# bindings_python:
421-
# if: needs.create_release.outputs.type == 'stable'
422-
# needs: create_release
423-
# uses: ./.github/workflows/bindings.python.yml
424-
# secrets: inherit
425-
# with:
426-
# tag: ${{ needs.create_release.outputs.version }}
420+
bindings_python:
421+
# if: needs.create_release.outputs.type == 'stable'
422+
needs: create_release
423+
uses: ./.github/workflows/bindings.python.yml
424+
secrets: inherit
425+
with:
426+
tag: ${{ needs.create_release.outputs.version }}
427427

428428
notify:
429429
runs-on: ubuntu-latest

src/query/functions/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ pub fn is_builtin_function(name: &str) -> bool {
4848
// The plan of search function, async function and udf contains some arguments defined in meta,
4949
// which may be modified by user at any time. Those functions are not not suitable for caching.
5050
pub fn is_cacheable_function(name: &str) -> bool {
51+
let n = name;
5152
let name = Ascii::new(name);
52-
BUILTIN_FUNCTIONS.contains(name.into_inner())
53+
(BUILTIN_FUNCTIONS.contains(name.into_inner())
54+
&& !BUILTIN_FUNCTIONS.get_property(n).unwrap().non_deterministic)
5355
|| AggregateFunctionFactory::instance().contains(name.into_inner())
5456
|| GENERAL_WINDOW_FUNCTIONS.contains(&name)
5557
|| GENERAL_LAMBDA_FUNCTIONS.contains(&name)

src/query/sql/src/planner/binder/window.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ impl WindowInfo {
282282
.insert(window.display_name.clone(), i);
283283
}
284284
}
285+
286+
pub fn get_window_info(&self, display_name: &str) -> Option<&WindowFunctionInfo> {
287+
self.window_functions_map
288+
.get(display_name)
289+
.map(|index| &self.window_functions[*index])
290+
}
285291
}
286292

287293
#[derive(Clone, PartialEq, Eq, Debug)]

src/query/sql/src/planner/semantic/grouping_check.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ impl VisitorMut<'_> for GroupingChecker<'_> {
206206
.aggregate_info
207207
.get_aggregate_function(&column.column.column_name)
208208
.is_some()
209+
{
210+
// Be replaced by `AggregateRewriter`.
211+
return Ok(());
212+
}
213+
214+
if self
215+
.bind_context
216+
.windows
217+
.get_window_info(&column.column.column_name)
218+
.is_some()
209219
{
210220
// Be replaced by `WindowRewriter`.
211221
return Ok(());

tests/sqllogictests/suites/query/aggregate.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ SELECT AVG(1 + a), sum(1 + a), count(1 + a) FROM tc;
105105
----
106106
3.0 9 3
107107

108+
## Aggregate with alias and window function
109+
statement ok
110+
select avg(1+a) score, a, percent_rank() over (partition by a % 3 order by score) d, d + 3 from tc group by a;
111+
112+
statement ok
113+
select avg(1+a) score, a, percent_rank() over (partition by a % 3 order by a) d, d + 3 from tc group by a;
114+
115+
statement error
116+
select avg(1+a) score, a, percent_rank() over (partition by a % 3 order by b) d, d + 3 from tc group by a;
117+
108118
## Create dimension tables with generic names
109119
statement ok
110120
CREATE or replace TABLE date_ranges (

0 commit comments

Comments
 (0)