-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: error instead of panic when date_bin interval is 0 #6522
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -522,6 +522,13 @@ fn date_bin_impl( | |
|
||
let (stride, stride_fn) = stride.bin_fn(); | ||
|
||
// Return error if stride is 0 | ||
if stride == 0 { | ||
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. The error says the stride must be positive and non zero, but this check is only for It seems like the main branch supports negative intervals:
Thus, given what @comphead found in #6522 (review) I think we should either:
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. Since I do not know if the negative stride is therefor a specific purpose and someone may use it, I chose not to change its behavior. I go with the option 1 to only fix the panic and have change the error message to "DATE_BIN stride must be non-zero" 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. 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. |
||
return Err(DataFusionError::Execution( | ||
"DATE_BIN stride must be non-zero".to_string(), | ||
)); | ||
} | ||
|
||
let f_nanos = |x: Option<i64>| x.map(|x| stride_fn(stride, x, origin)); | ||
let f_micros = |x: Option<i64>| { | ||
let scale = 1_000; | ||
|
@@ -1029,6 +1036,17 @@ mod tests { | |
"Execution error: DATE_BIN expects stride argument to be an INTERVAL but got Interval(YearMonth)" | ||
); | ||
|
||
// stride: invalid value | ||
let res = date_bin(&[ | ||
ColumnarValue::Scalar(ScalarValue::IntervalDayTime(Some(0))), | ||
ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(Some(1), None)), | ||
ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(Some(1), None)), | ||
]); | ||
assert_eq!( | ||
res.err().unwrap().to_string(), | ||
"Execution error: DATE_BIN stride must be non-zero" | ||
); | ||
|
||
// stride: overflow of day-time interval | ||
let res = date_bin(&[ | ||
ColumnarValue::Scalar(ScalarValue::IntervalDayTime(Some(i64::MAX))), | ||
|
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.
I remember @alamb want just right number of tests, I think these 3 tests are good to capture 2 different forms of stride on constant (second --> nanosecond in the code, and month -> month) and an aggregate on data.