Skip to content

Commit adb1ece

Browse files
committed
[SQL] Support for TIME/DATE/TIMESTAMP constructors
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent d777534 commit adb1ece

11 files changed

Lines changed: 625 additions & 114 deletions

File tree

crates/sqllib/src/lib.rs

Lines changed: 168 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ pub type WSet<D> = OrdZSet<D>;
230230
#[doc(hidden)]
231231
pub type IndexedWSet<K, D> = OrdIndexedZSet<K, D>;
232232

233-
// Macro to create variants of a function with 1 argument
234-
// If there exists a function is f_(x: T) -> S, this creates a function
235-
// fN(x: Option<T>) -> Option<S>, defined as
236-
// fN(x) { let x = x?; Some(f_(x)) }.
233+
/// Macro to create variants of a function with 1 argument
234+
/// If there exists a function is f_(x: T) -> S, this creates a function
235+
/// fN(x: Option<T>) -> Option<S>, defined as
236+
/// fN(x) { let x = x?; Some(f_(x)) }.
237237
macro_rules! some_function1 {
238238
($func_name:ident, $arg_type:ty, $ret_type:ty) => {
239239
::paste::paste! {
@@ -248,10 +248,10 @@ macro_rules! some_function1 {
248248

249249
pub(crate) use some_function1;
250250

251-
// Macro to create variants of a function with 1 argument
252-
// If there exists a function is f_type(x: T) -> S, this creates a function
253-
// f_typeN(x: Option<T>) -> Option<S>
254-
// { let x = x?; Some(f_type(x)) }.
251+
/// Macro to create variants of a function with 1 argument
252+
/// If there exists a function is f_type(x: T) -> S, this creates a function
253+
/// f_typeN(x: Option<T>) -> Option<S>
254+
/// { let x = x?; Some(f_type(x)) }.
255255
macro_rules! some_polymorphic_function1 {
256256
($func_name:ident $(< $( const $var : ident : $ty: ty),* >)?, $type_name: ident, $arg_type:ty, $ret_type:ty) => {
257257
::paste::paste! {
@@ -266,13 +266,14 @@ macro_rules! some_polymorphic_function1 {
266266

267267
pub(crate) use some_polymorphic_function1;
268268

269-
// Macro to create variants of a function with 2 arguments
270-
// If there exists a function is f__(x: T, y: S) -> U, this creates
271-
// three functions:
272-
// - f_N(x: T, y: Option<S>) -> Option<U>
273-
// - fN_(x: Option<T>, y: S) -> Option<U>
274-
// - fNN(x: Option<T>, y: Option<S>) -> Option<U>
275-
// The resulting functions return Some only if all arguments are 'Some'.
269+
/// Macro to create variants of a function with 2 arguments
270+
/// If there exists a function is f__(x: T, y: S) -> U, this creates
271+
/// three functions:
272+
/// - f_N(x: T, y: Option<S>) -> Option<U>
273+
/// - fN_(x: Option<T>, y: S) -> Option<U>
274+
/// - fNN(x: Option<T>, y: Option<S>) -> Option<U>
275+
///
276+
/// The resulting functions return Some only if all arguments are 'Some'.
276277
macro_rules! some_function2 {
277278
($func_name:ident, $arg_type0:ty, $arg_type1:ty, $ret_type:ty) => {
278279
::paste::paste! {
@@ -300,13 +301,14 @@ macro_rules! some_function2 {
300301

301302
pub(crate) use some_function2;
302303

303-
// Macro to create variants of a polymorphic function with 2 arguments
304-
// If there exists a function is f_type1_type2(x: T, y: S) -> U, this
305-
// creates three functions:
306-
// - f_type1_type2N(x: T, y: Option<S>) -> Option<U>
307-
// - f_type1N_type2(x: Option<T>, y: S) -> Option<U>
308-
// - f_type1N_type2N(x: Option<T>, y: Option<S>) -> Option<U>
309-
// The resulting functions return Some only if all arguments are 'Some'.
304+
/// Macro to create variants of a polymorphic function with 2 arguments
305+
/// If there exists a function is f_type1_type2(x: T, y: S) -> U, this
306+
/// creates three functions:
307+
/// - f_type1_type2N(x: T, y: Option<S>) -> Option<U>
308+
/// - f_type1N_type2(x: Option<T>, y: S) -> Option<U>
309+
/// - f_type1N_type2N(x: Option<T>, y: Option<S>) -> Option<U>
310+
///
311+
/// The resulting functions return Some only if all arguments are 'Some'.
310312
macro_rules! some_polymorphic_function2 {
311313
($func_name:ident $(< $( const $var:ident : $ty: ty),* >)?, $type_name0: ident, $arg_type0:ty, $type_name1: ident, $arg_type1:ty, $ret_type:ty) => {
312314
::paste::paste! {
@@ -334,12 +336,13 @@ macro_rules! some_polymorphic_function2 {
334336

335337
pub(crate) use some_polymorphic_function2;
336338

337-
// If there exists a function is f_t1_t2_t3(x: T, y: S, z: V) -> U, this creates
338-
// seven functions:
339-
// - f_t1_t2_t3N(x: T, y: S, z: Option<V>) -> Option<U>
340-
// - f_t1_t2N_t2(x: T, y: Option<S>, z: V) -> Option<U>
341-
// - etc.
342-
// The resulting functions return Some only if all arguments are 'Some'.
339+
/// If there exists a function is f_t1_t2_t3(x: T, y: S, z: V) -> U, this creates
340+
/// seven functions:
341+
/// - f_t1_t2_t3N(x: T, y: S, z: Option<V>) -> Option<U>
342+
/// - f_t1_t2N_t2(x: T, y: Option<S>, z: V) -> Option<U>
343+
/// - etc.
344+
///
345+
/// The resulting functions return Some only if all arguments are 'Some'.
343346
macro_rules! some_polymorphic_function3 {
344347
($func_name:ident,
345348
$type_name0: ident, $arg_type0:ty,
@@ -427,12 +430,106 @@ macro_rules! some_polymorphic_function3 {
427430

428431
pub(crate) use some_polymorphic_function3;
429432

430-
// If there exists a function is f___(x: T, y: S, z: V) -> U, this creates
431-
// seven functions:
432-
// - f__N(x: T, y: S, z: Option<V>) -> Option<U>
433-
// - f_N_(x: T, y: Option<S>, z: V) -> Option<U>
434-
// - etc.
435-
// The resulting functions return Some only if all arguments are 'Some'.
433+
/// If there exists a function is f_t1_t2_t3(x: T, y: S, z: V) -> Option<U>, this creates
434+
/// seven functions:
435+
/// - f_t1_t2_t3N(x: T, y: S, z: Option<V>) -> Option<U>
436+
/// - f_t1_t2N_t2(x: T, y: Option<S>, z: V) -> Option<U>
437+
/// - etc.
438+
// This is like some_polymorphic_function3, but the result is always Option.
439+
macro_rules! some_polymorphic_null_function3 {
440+
($func_name:ident $(< $( const $var : ident : $ty: ty),* >)?,
441+
$type_name0: ident, $arg_type0:ty,
442+
$type_name1: ident, $arg_type1:ty,
443+
$type_name2: ident, $arg_type2: ty,
444+
$ret_type:ty) => {
445+
::paste::paste! {
446+
#[doc(hidden)]
447+
pub fn [<$func_name _ $type_name0 _ $type_name1 _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
448+
arg0: $arg_type0,
449+
arg1: $arg_type1,
450+
arg2: Option<$arg_type2>
451+
) -> Option<$ret_type> {
452+
let arg2 = arg2?;
453+
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
454+
}
455+
456+
#[doc(hidden)]
457+
pub fn [<$func_name _ $type_name0 _ $type_name1 N _ $type_name2>] $(< $( const $var : $ty ),* >)? (
458+
arg0: $arg_type0,
459+
arg1: Option<$arg_type1>,
460+
arg2: $arg_type2
461+
) -> Option<$ret_type> {
462+
let arg1 = arg1?;
463+
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
464+
}
465+
466+
#[doc(hidden)]
467+
pub fn [<$func_name _ $type_name0 _ $type_name1 N _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
468+
arg0: $arg_type0,
469+
arg1: Option<$arg_type1>,
470+
arg2: Option<$arg_type2>
471+
) -> Option<$ret_type> {
472+
let arg1 = arg1?;
473+
let arg2 = arg2?;
474+
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
475+
}
476+
477+
#[doc(hidden)]
478+
pub fn [<$func_name _ $type_name0 N _ $type_name1 _ $type_name2>] $(< $( const $var : $ty ),* >)? (
479+
arg0: Option<$arg_type0>,
480+
arg1: $arg_type1,
481+
arg2: $arg_type2
482+
) -> Option<$ret_type> {
483+
let arg0 = arg0?;
484+
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
485+
}
486+
487+
#[doc(hidden)]
488+
pub fn [<$func_name _ $type_name0 N _ $type_name1 _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
489+
arg0: Option<$arg_type0>,
490+
arg1: $arg_type1,
491+
arg2: Option<$arg_type2>
492+
) -> Option<$ret_type> {
493+
let arg0 = arg0?;
494+
let arg2 = arg2?;
495+
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
496+
}
497+
498+
#[doc(hidden)]
499+
pub fn [<$func_name _ $type_name0 N _ $type_name1 N _ $type_name2>] $(< $( const $var : $ty ),* >)? (
500+
arg0: Option<$arg_type0>,
501+
arg1: Option<$arg_type1>,
502+
arg2: $arg_type2
503+
) -> Option<$ret_type> {
504+
let arg0 = arg0?;
505+
let arg1 = arg1?;
506+
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
507+
}
508+
509+
#[doc(hidden)]
510+
pub fn [<$func_name _ $type_name0 N _ $type_name1 N _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
511+
arg0: Option<$arg_type0>,
512+
arg1: Option<$arg_type1>,
513+
arg2: Option<$arg_type2>
514+
) -> Option<$ret_type> {
515+
let arg0 = arg0?;
516+
let arg1 = arg1?;
517+
let arg2 = arg2?;
518+
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
519+
}
520+
}
521+
};
522+
}
523+
524+
pub(crate) use some_polymorphic_null_function3;
525+
526+
/// If there exists a function is f___(x: T, y: S, z: V) -> U, this creates
527+
/// seven functions:
528+
/// - f__N(x: T, y: S, z: Option<V>) -> Option<U>
529+
/// - f_N_(x: T, y: Option<S>, z: V) -> Option<U>
530+
/// - etc.
531+
///
532+
/// The resulting functions return Some only if all arguments are 'Some'.
436533
macro_rules! some_function3 {
437534
($func_name:ident, $arg_type0:ty, $arg_type1:ty, $arg_type2: ty, $ret_type:ty) => {
438535
::paste::paste! {
@@ -488,13 +585,14 @@ macro_rules! some_function3 {
488585

489586
pub(crate) use some_function3;
490587

491-
// Macro to create variants of a function with 4 arguments
492-
// If there exists a function is f____(x: T, y: S, z: V, w: W) -> U, this
493-
// creates fifteen functions:
494-
// - f___N(x: T, y: S, z: V, w: Option<W>) -> Option<U>
495-
// - f__N_(x: T, y: S, z: Option<V>, w: W) -> Option<U>
496-
// - etc.
497-
// The resulting functions return Some only if all arguments are 'Some'.
588+
/// Macro to create variants of a function with 4 arguments
589+
/// If there exists a function is f____(x: T, y: S, z: V, w: W) -> U, this
590+
/// creates fifteen functions:
591+
/// - f___N(x: T, y: S, z: V, w: Option<W>) -> Option<U>
592+
/// - f__N_(x: T, y: S, z: Option<V>, w: W) -> Option<U>
593+
/// - etc.
594+
///
595+
/// The resulting functions return Some only if all arguments are 'Some'.
498596
macro_rules! some_function4 {
499597
($func_name:ident, $arg_type0:ty, $arg_type1:ty, $arg_type2: ty, $arg_type3: ty, $ret_type:ty) => {
500598
::paste::paste! {
@@ -610,14 +708,15 @@ macro_rules! some_function4 {
610708

611709
pub(crate) use some_function4;
612710

613-
// Macro to create variants of a function with 2 arguments
614-
// optimized for the implementation of arithmetic operators.
615-
// Assuming there exists a function is f__(x: T, y: T) -> U, this creates
616-
// three functions:
617-
// - f_tN_t(x: T, y: Option<T>) -> Option<U>
618-
// - f_t_tN(x: Option<T>, y: T) -> Option<U>
619-
// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
620-
// The resulting functions return Some only if all arguments are 'Some'.
711+
/// Macro to create variants of a function with 2 arguments
712+
/// optimized for the implementation of arithmetic operators.
713+
/// Assuming there exists a function is f__(x: T, y: T) -> U, this creates
714+
/// three functions:
715+
/// - f_tN_t(x: T, y: Option<T>) -> Option<U>
716+
/// - f_t_tN(x: Option<T>, y: T) -> Option<U>
717+
/// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
718+
///
719+
/// The resulting functions return Some only if all arguments are 'Some'.
621720
macro_rules! some_existing_operator {
622721
($func_name: ident $(< $( const $var:ident : $ty: ty),* >)?, $short_name: ident, $arg_type: ty, $ret_type: ty) => {
623722
::paste::paste! {
@@ -648,21 +747,22 @@ macro_rules! some_existing_operator {
648747

649748
pub(crate) use some_existing_operator;
650749

651-
// Macro to create variants of a function with 2 arguments
652-
// optimized for the implementation of arithmetic operators.
653-
// Assuming there exists a function is f(x: T, y: T) -> U, this creates
654-
// four functions:
655-
// - f_t_t(x: T, y: T) -> U
656-
// - f_tN_t(x: T, y: Option<T>) -> Option<U>
657-
// - f_t_tN(x: Option<T>, y: T) -> Option<U>
658-
// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
659-
// The resulting functions return Some only if all arguments are 'Some'.
660-
//
661-
// Has two variants:
662-
// - Takes the name of the existing function, the generated functions will have
663-
// this prefix
664-
// - Takes the name of the existing function, and the prefix for the generated
665-
// functions
750+
/// Macro to create variants of a function with 2 arguments
751+
/// optimized for the implementation of arithmetic operators.
752+
/// Assuming there exists a function is f(x: T, y: T) -> U, this creates
753+
/// four functions:
754+
/// - f_t_t(x: T, y: T) -> U
755+
/// - f_tN_t(x: T, y: Option<T>) -> Option<U>
756+
/// - f_t_tN(x: Option<T>, y: T) -> Option<U>
757+
/// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
758+
///
759+
/// The resulting functions return Some only if all arguments are 'Some'.
760+
///
761+
/// Has two variants:
762+
/// - Takes the name of the existing function, the generated functions will have
763+
/// this prefix
764+
/// - Takes the name of the existing function, and the prefix for the generated
765+
/// functions
666766
macro_rules! some_operator {
667767
($func_name: ident $(< $( const $var:ident : $ty: ty),* >)?, $short_name: ident, $arg_type: ty, $ret_type: ty) => {
668768
::paste::paste! {
@@ -1414,10 +1514,10 @@ where
14141514
}
14151515
}
14161516

1417-
// Semigroup for the an aggregate which computes nothing
1418-
// Useful when the compiler removes all aggregates from an aggregate operator
1419-
// (This is currently never used, because the compiler generates a linear aggregate
1420-
// for this case)
1517+
/// Semigroup for the an aggregate which computes nothing
1518+
/// Useful when the compiler removes all aggregates from an aggregate operator
1519+
/// (This is currently never used, because the compiler generates a linear aggregate
1520+
/// for this case)
14211521
#[derive(Clone)]
14221522
#[doc(hidden)]
14231523
pub struct EmptySemigroup;

0 commit comments

Comments
 (0)