-
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
Remove Option from window frame #4516
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
269495c
window frame none, non empty orderby handling logic
mustafasrepo 2e7ec65
window frame none, empty orderby handling logic
mustafasrepo e926a2a
Remove window frame option
mustafasrepo e89c2e1
Minor changes
mustafasrepo 24793a6
Use ScalarValue::Null for unbounded
mustafasrepo 62ddc07
Merge branch 'apache:master' into feature/window_frame_init
mustafasrepo 9de3054
Resolve proto errors
mustafasrepo 30a5a08
combine functions under new
mustafasrepo 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -66,33 +66,51 @@ impl TryFrom<ast::WindowFrame> for WindowFrame { | |
None => WindowFrameBound::CurrentRow, | ||
}; | ||
|
||
if let WindowFrameBound::Following(ScalarValue::Utf8(None)) = start_bound { | ||
Err(DataFusionError::Execution( | ||
"Invalid window frame: start bound cannot be unbounded following" | ||
.to_owned(), | ||
)) | ||
} else if let WindowFrameBound::Preceding(ScalarValue::Utf8(None)) = end_bound { | ||
Err(DataFusionError::Execution( | ||
"Invalid window frame: end bound cannot be unbounded preceding" | ||
.to_owned(), | ||
)) | ||
} else { | ||
let units = value.units.into(); | ||
Ok(Self { | ||
units, | ||
start_bound, | ||
end_bound, | ||
}) | ||
} | ||
if let WindowFrameBound::Following(val) = &start_bound { | ||
if val.is_null() { | ||
return Err(DataFusionError::Execution( | ||
"Invalid window frame: start bound cannot be unbounded following" | ||
.to_owned(), | ||
)); | ||
} | ||
} else if let WindowFrameBound::Preceding(val) = &end_bound { | ||
if val.is_null() { | ||
return Err(DataFusionError::Execution( | ||
"Invalid window frame: end bound cannot be unbounded preceding" | ||
.to_owned(), | ||
)); | ||
} | ||
}; | ||
Ok(Self { | ||
units: value.units.into(), | ||
start_bound, | ||
end_bound, | ||
}) | ||
} | ||
} | ||
|
||
impl Default for WindowFrame { | ||
fn default() -> Self { | ||
WindowFrame { | ||
units: WindowFrameUnits::Range, | ||
start_bound: WindowFrameBound::Preceding(ScalarValue::Utf8(None)), | ||
end_bound: WindowFrameBound::CurrentRow, | ||
impl WindowFrame { | ||
/// Creates a new, default window frame (with the meaning of default depending on whether the | ||
/// frame contains an `ORDER BY` clause. | ||
pub fn new(has_order_by: bool) -> Self { | ||
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. Thanks for this fix, i also want to change this default behavior. |
||
if has_order_by { | ||
// This window frame covers the table (or partition if `PARTITION BY` is used) | ||
// from beginning to the `CURRENT ROW` (with same rank). It is used when the `OVER` | ||
// clause contains an `ORDER BY` clause but no frame. | ||
WindowFrame { | ||
units: WindowFrameUnits::Range, | ||
start_bound: WindowFrameBound::Preceding(ScalarValue::Null), | ||
end_bound: WindowFrameBound::CurrentRow, | ||
} | ||
} else { | ||
// This window frame covers the whole table (or partition if `PARTITION BY` is used). | ||
// It is used when the `OVER` clause does not contain an `ORDER BY` clause and there is | ||
// no frame. | ||
WindowFrame { | ||
units: WindowFrameUnits::Rows, | ||
start_bound: WindowFrameBound::Preceding(ScalarValue::UInt64(None)), | ||
end_bound: WindowFrameBound::Following(ScalarValue::UInt64(None)), | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -137,15 +155,11 @@ impl TryFrom<ast::WindowFrameBound> for WindowFrameBound { | |
ast::WindowFrameBound::Preceding(Some(v)) => { | ||
Self::Preceding(convert_frame_bound_to_scalar_value(*v)?) | ||
} | ||
ast::WindowFrameBound::Preceding(None) => { | ||
Self::Preceding(ScalarValue::Utf8(None)) | ||
} | ||
ast::WindowFrameBound::Preceding(None) => Self::Preceding(ScalarValue::Null), | ||
ast::WindowFrameBound::Following(Some(v)) => { | ||
Self::Following(convert_frame_bound_to_scalar_value(*v)?) | ||
} | ||
ast::WindowFrameBound::Following(None) => { | ||
Self::Following(ScalarValue::Utf8(None)) | ||
} | ||
ast::WindowFrameBound::Following(None) => Self::Following(ScalarValue::Null), | ||
ast::WindowFrameBound::CurrentRow => Self::CurrentRow, | ||
}) | ||
} | ||
|
@@ -183,15 +197,21 @@ pub fn convert_frame_bound_to_scalar_value(v: ast::Expr) -> Result<ScalarValue> | |
impl fmt::Display for WindowFrameBound { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
WindowFrameBound::Preceding(ScalarValue::Utf8(None)) => { | ||
f.write_str("UNBOUNDED PRECEDING") | ||
WindowFrameBound::Preceding(n) => { | ||
if n.is_null() { | ||
f.write_str("UNBOUNDED PRECEDING") | ||
} else { | ||
write!(f, "{} PRECEDING", n) | ||
} | ||
} | ||
WindowFrameBound::Preceding(n) => write!(f, "{} PRECEDING", n), | ||
WindowFrameBound::CurrentRow => f.write_str("CURRENT ROW"), | ||
WindowFrameBound::Following(ScalarValue::Utf8(None)) => { | ||
f.write_str("UNBOUNDED FOLLOWING") | ||
WindowFrameBound::Following(n) => { | ||
if n.is_null() { | ||
f.write_str("UNBOUNDED FOLLOWING") | ||
} else { | ||
write!(f, "{} FOLLOWING", n) | ||
} | ||
} | ||
WindowFrameBound::Following(n) => write!(f, "{} FOLLOWING", n), | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
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.
Thank you for the clear comments 👍