-
Notifications
You must be signed in to change notification settings - Fork 131
[SQL] Support for range aggregates sorting on intervals, booleans #6310
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
Changes from all 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 |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| //! Boolean operations | ||
|
|
||
| use crate::some_function1; | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn wrap_bool(b: Option<bool>) -> bool { | ||
| b.unwrap_or_default() | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn or_b_b<F>(left: bool, right: F) -> bool | ||
| where | ||
| F: Fn() -> bool, | ||
| { | ||
| left || right() | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn or_bN_b<F>(left: Option<bool>, right: F) -> Option<bool> | ||
| where | ||
| F: Fn() -> bool, | ||
| { | ||
| match left { | ||
| Some(l) => Some(l || right()), | ||
| None => match right() { | ||
| true => Some(true), | ||
| _ => None, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn or_b_bN<F>(left: bool, right: F) -> Option<bool> | ||
| where | ||
| F: Fn() -> Option<bool>, | ||
| { | ||
| match left { | ||
| false => right(), | ||
| true => Some(true), | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn or_bN_bN<F>(left: Option<bool>, right: F) -> Option<bool> | ||
| where | ||
| F: Fn() -> Option<bool>, | ||
| { | ||
| match left { | ||
| None => match right() { | ||
| Some(true) => Some(true), | ||
| _ => None, | ||
| }, | ||
| Some(false) => right(), | ||
| Some(true) => Some(true), | ||
| } | ||
| } | ||
|
|
||
| // OR and AND are special, they can't be generated by rules | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn and_b_b<F>(left: bool, right: F) -> bool | ||
| where | ||
| F: Fn() -> bool, | ||
| { | ||
| left && right() | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn and_bN_b<F>(left: Option<bool>, right: F) -> Option<bool> | ||
| where | ||
| F: Fn() -> bool, | ||
| { | ||
| match left { | ||
| Some(false) => Some(false), | ||
| Some(true) => Some(right()), | ||
| None => match right() { | ||
| false => Some(false), | ||
| _ => None, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn and_b_bN<F>(left: bool, right: F) -> Option<bool> | ||
| where | ||
| F: Fn() -> Option<bool>, | ||
| { | ||
| match left { | ||
| false => Some(false), | ||
| true => right(), | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn and_bN_bN<F>(left: Option<bool>, right: F) -> Option<bool> | ||
| where | ||
| F: Fn() -> Option<bool>, | ||
| { | ||
| match left { | ||
| Some(false) => Some(false), | ||
| Some(true) => right(), | ||
| None => match right() { | ||
| Some(false) => Some(false), | ||
| _ => None, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn is_true_b_(left: bool) -> bool { | ||
| left | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn is_true_bN_(left: Option<bool>) -> bool { | ||
| matches!(left, Some(true)) | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub fn is_false_b_(left: bool) -> bool { | ||
| !left | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn is_false_bN_(left: Option<bool>) -> bool { | ||
| matches!(left, Some(false)) | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn is_not_true_b_(left: bool) -> bool { | ||
| !left | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn is_not_true_bN_(left: Option<bool>) -> bool { | ||
| match left { | ||
| Some(true) => false, | ||
| Some(false) => true, | ||
| _ => true, | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn is_not_false_b_(left: bool) -> bool { | ||
| left | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn is_not_false_bN_(left: Option<bool>) -> bool { | ||
| match left { | ||
| Some(true) => true, | ||
| Some(false) => false, | ||
| _ => true, | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn bool_to_i8_(value: bool) -> i8 { | ||
| if value { 1 } else { 0 } | ||
| } | ||
|
|
||
| some_function1!(bool_to_i8, bool, i8); | ||
|
|
||
| #[doc(hidden)] | ||
| #[inline(always)] | ||
| pub const fn i8_to_bool_(value: i8) -> bool { | ||
| value != 0 | ||
| } | ||
|
|
||
| some_function1!(i8_to_bool, i8, bool); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,3 +41,18 @@ where | |
| Err(e) => Err(SqlRuntimeError::from_string(e.to_string())), | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| // If the data is Ok(None), convert it to Err, otherwise leave it unchanged | ||
| pub fn unwrap_sql_result<T>(data: SqlResult<Option<T>>) -> SqlResult<T> { | ||
| match data { | ||
| Err(e) => Err(e), | ||
| Ok(None) => Err(SqlRuntimeError::from_strng("NULL result produced")), | ||
|
mihaibudiu marked this conversation as resolved.
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. Re-flagging from last round (not a blocker): |
||
| Ok(Some(data)) => Ok(data), | ||
| } | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| pub fn wrap_sql_result<T>(data: T) -> SqlResult<T> { | ||
| Ok(data) | ||
| } | ||
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.
many of these functions were moved from lib.rs