-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add window func related logic plan to proto ability. #4485
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,14 +70,16 @@ mod roundtrip_tests { | |
}; | ||
use datafusion::test_util::{TestTableFactory, TestTableProvider}; | ||
use datafusion_common::{DFSchemaRef, DataFusionError, ScalarValue}; | ||
use datafusion_expr::create_udaf; | ||
use datafusion_expr::expr::{Between, BinaryExpr, Case, Cast, GroupingSet, Like}; | ||
use datafusion_expr::logical_plan::{Extension, UserDefinedLogicalNode}; | ||
use datafusion_expr::{ | ||
col, lit, Accumulator, AggregateFunction, AggregateState, | ||
BuiltinScalarFunction::{Sqrt, Substr}, | ||
Expr, LogicalPlan, Operator, Volatility, | ||
}; | ||
use datafusion_expr::{ | ||
create_udaf, WindowFrame, WindowFrameBound, WindowFrameUnits, WindowFunction, | ||
}; | ||
use prost::Message; | ||
use std::any::Any; | ||
use std::collections::HashMap; | ||
|
@@ -1331,4 +1333,67 @@ mod roundtrip_tests { | |
roundtrip_expr_test(test_expr, ctx.clone()); | ||
roundtrip_expr_test(test_expr_with_count, ctx); | ||
} | ||
#[test] | ||
fn roundtrip_window() { | ||
let ctx = SessionContext::new(); | ||
|
||
// 1. without window_frame | ||
let test_expr1 = Expr::WindowFunction { | ||
fun: WindowFunction::BuiltInWindowFunction( | ||
datafusion_expr::window_function::BuiltInWindowFunction::Rank, | ||
), | ||
args: vec![], | ||
partition_by: vec![col("col1")], | ||
order_by: vec![col("col2")], | ||
window_frame: None, | ||
}; | ||
|
||
// 2. with default window_frame | ||
let test_expr2 = Expr::WindowFunction { | ||
fun: WindowFunction::BuiltInWindowFunction( | ||
datafusion_expr::window_function::BuiltInWindowFunction::Rank, | ||
), | ||
args: vec![], | ||
partition_by: vec![col("col1")], | ||
order_by: vec![col("col2")], | ||
window_frame: Some(WindowFrame::default()), | ||
}; | ||
|
||
// 3. with window_frame with row numbers | ||
let range_number_frame = WindowFrame { | ||
units: WindowFrameUnits::Range, | ||
start_bound: WindowFrameBound::Preceding(ScalarValue::UInt64(Some(2))), | ||
end_bound: WindowFrameBound::Following(ScalarValue::UInt64(Some(2))), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without this commit, this test will fail. |
||
}; | ||
|
||
let test_expr3 = Expr::WindowFunction { | ||
fun: WindowFunction::BuiltInWindowFunction( | ||
datafusion_expr::window_function::BuiltInWindowFunction::Rank, | ||
), | ||
args: vec![], | ||
partition_by: vec![col("col1")], | ||
order_by: vec![col("col2")], | ||
window_frame: Some(range_number_frame), | ||
}; | ||
|
||
// 4. test with AggregateFunction | ||
let row_number_frame = WindowFrame { | ||
units: WindowFrameUnits::Rows, | ||
start_bound: WindowFrameBound::Preceding(ScalarValue::UInt64(Some(2))), | ||
end_bound: WindowFrameBound::Following(ScalarValue::UInt64(Some(2))), | ||
}; | ||
|
||
let test_expr4 = Expr::WindowFunction { | ||
fun: WindowFunction::AggregateFunction(AggregateFunction::Max), | ||
args: vec![col("col1")], | ||
partition_by: vec![col("col1")], | ||
order_by: vec![col("col2")], | ||
window_frame: Some(row_number_frame), | ||
}; | ||
|
||
roundtrip_expr_test(test_expr1, ctx.clone()); | ||
roundtrip_expr_test(test_expr2, ctx.clone()); | ||
roundtrip_expr_test(test_expr3, ctx.clone()); | ||
roundtrip_expr_test(test_expr4, ctx); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike WindowFunction with
AggrFunction
likemin(col)
.max(col)
.sum(col)
it must have required_expBuilt-in WindowFunction like
ROW_NUMBER()
.RANK()
.DENSE()
have to have this value