Skip to content
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

feat(over window): window function RANGE frame support in frontend #14648

Merged
merged 16 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,11 @@ message AggCall {
message WindowFrame {
enum Type {
TYPE_UNSPECIFIED = 0;
// RANGE = 1;
TYPE_ROWS = 2;
// GROUPS = 3;

TYPE_ROWS_LEGACY = 2 [deprecated = true]; // Deprecated since we introduced `RANGE` frame.

TYPE_ROWS = 5;
TYPE_RANGE = 10;
}
enum BoundType {
BOUND_TYPE_UNSPECIFIED = 0;
Expand All @@ -430,7 +432,9 @@ message WindowFrame {
BOUND_TYPE_FOLLOWING = 4;
BOUND_TYPE_UNBOUNDED_FOLLOWING = 5;
}
// Deprecated since we introduced `RANGE` frame.
message Bound {
option deprecated = true;
BoundType type = 1;
oneof offset {
uint64 integer = 2;
Expand All @@ -444,11 +448,38 @@ message WindowFrame {
// EXCLUSION_TIES = 3;
EXCLUSION_NO_OTHERS = 4;
}
message RowsFrameBounds {
RowsFrameBound start = 1;
RowsFrameBound end = 2;
}
message RowsFrameBound {
BoundType type = 1;
optional uint64 offset = 3;
}
message RangeFrameBounds {
RangeFrameBound start = 1;
RangeFrameBound end = 2;

data.DataType order_data_type = 10;
common.OrderType order_type = 15;
data.DataType offset_data_type = 20;
}
message RangeFrameBound {
BoundType type = 1;
optional data.Datum offset = 3;
}

Type type = 1;
Bound start = 2;
Bound end = 3;

Bound start = 2 [deprecated = true]; // Deprecated since we introduced `RANGE` frame.
Bound end = 3 [deprecated = true]; // Deprecated since we introduced `RANGE` frame.

Exclusion exclusion = 4;

oneof bounds {
RowsFrameBounds rows = 10;
RangeFrameBounds range = 15;
}
}

message WindowFunction {
Expand Down
5 changes: 5 additions & 0 deletions src/common/src/types/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ impl Interval {
self > &Self::from_month_day_usec(0, 0, 0)
}

/// Checks if all fields of [`Interval`] are all non-negative.
pub fn is_never_negative(&self) -> bool {
self.months >= 0 && self.days >= 0 && self.usecs >= 0
}

/// Truncate the interval to the precision of milliseconds.
///
/// # Example
Expand Down
32 changes: 31 additions & 1 deletion src/common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,36 @@ impl From<DataTypeName> for PbTypeName {
}
}

/// Convenient macros to generate match arms for [`DataType`](crate::types::DataType).
pub mod data_types {
/// Numeric [`DataType`](crate::types::DataType)s supported to be `offset` of `RANGE` frame.
#[macro_export]
macro_rules! range_frame_numeric {
() => {
DataType::Int16
| DataType::Int32
| DataType::Int64
| DataType::Float32
| DataType::Float64
| DataType::Decimal
};
}
pub use range_frame_numeric;

/// Date/time [`DataType`](crate::types::DataType)s supported to be `offset` of `RANGE` frame.
#[macro_export]
macro_rules! range_frame_datetime {
() => {
DataType::Date
| DataType::Time
| DataType::Timestamp
| DataType::Timestamptz
| DataType::Interval
};
}
pub use range_frame_datetime;
}

impl DataType {
pub fn create_array_builder(&self, capacity: usize) -> ArrayBuilderImpl {
use crate::array::*;
Expand Down Expand Up @@ -374,7 +404,7 @@ impl DataType {
matches!(self, DataType::Int16 | DataType::Int32 | DataType::Int64)
}

/// Returns the output type of window function on a given input type.
/// Returns the output type of time window function on a given input type.
pub fn window_of(input: &DataType) -> Option<DataType> {
match input {
DataType::Timestamptz => Some(DataType::Timestamptz),
Expand Down
Loading
Loading