-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support simple window functions (#787)
* support basic window function Signed-off-by: Runji Wang <[email protected]> * support aggregate functions as window function Signed-off-by: Runji Wang <[email protected]> * forbid window functions in WHERE and HAVING clause Signed-off-by: Runji Wang <[email protected]> * forbid nested window function Signed-off-by: Runji Wang <[email protected]> * ignore window function test in v1 Signed-off-by: Runji Wang <[email protected]> * fix clippy Signed-off-by: Runji Wang <[email protected]> --------- Signed-off-by: Runji Wang <[email protected]>
- Loading branch information
1 parent
0e81535
commit 604b4a1
Showing
14 changed files
with
231 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2023 RisingLight Project Authors. Licensed under Apache-2.0. | ||
|
||
use super::*; | ||
use crate::array::DataChunkBuilder; | ||
|
||
/// The executor of window functions. | ||
pub struct WindowExecutor { | ||
/// A list of over window functions. | ||
/// | ||
/// e.g. `(list (over (lag #0) list list))` | ||
pub exprs: RecExpr, | ||
/// The types of window function columns. | ||
pub types: Vec<DataType>, | ||
} | ||
|
||
impl WindowExecutor { | ||
#[try_stream(boxed, ok = DataChunk, error = ExecutorError)] | ||
pub async fn execute(self, child: BoxedExecutor) { | ||
let mut states = Evaluator::new(&self.exprs).init_agg_states::<Vec<_>>(); | ||
|
||
#[for_await] | ||
for chunk in child { | ||
let chunk = chunk?; | ||
let mut builder = DataChunkBuilder::new(&self.types, chunk.cardinality() + 1); | ||
for i in 0..chunk.cardinality() { | ||
Evaluator::new(&self.exprs).agg_list_append(&mut states, chunk.row(i).values()); | ||
_ = builder.push_row(states.clone()); | ||
} | ||
let window_chunk = builder.take().unwrap(); | ||
yield chunk.row_concat(window_chunk); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.