Skip to content

Commit

Permalink
Make it more ergonmic to use PartiqlShapeBuilder and type macros (#490
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jpschorr authored Aug 22, 2024
1 parent 298a7ac commit deff7a8
Showing 1 changed file with 68 additions and 15 deletions.
83 changes: 68 additions & 15 deletions partiql-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,60 @@ macro_rules! type_dynamic {
#[macro_export]
macro_rules! type_int {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Int)
type_int!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Int)
};
}

#[macro_export]
macro_rules! type_int8 {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Int8)
type_int8!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Int8)
};
}

#[macro_export]
macro_rules! type_int16 {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Int16)
type_int16!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Int16)
};
}

#[macro_export]
macro_rules! type_int32 {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Int32)
type_int32!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Int32)
};
}

#[macro_export]
macro_rules! type_int64 {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Int64)
type_int64!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Int64)
};
}

#[macro_export]
macro_rules! type_decimal {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Decimal)
type_decimal!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Decimal)
};
}

Expand All @@ -90,28 +108,40 @@ macro_rules! type_decimal {
#[macro_export]
macro_rules! type_float32 {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Float32)
type_float32!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Float32)
};
}

#[macro_export]
macro_rules! type_float64 {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Float64)
type_float64!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Float64)
};
}

#[macro_export]
macro_rules! type_string {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::String)
type_string!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::String)
};
}

#[macro_export]
macro_rules! type_bool {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::Bool)
type_bool!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::Bool)
};
}

Expand All @@ -130,7 +160,10 @@ macro_rules! type_numeric {
#[macro_export]
macro_rules! type_datetime {
() => {
$crate::PartiqlShapeBuilder::init_or_get().new_static($crate::Static::DateTime)
type_datetime!($crate::PartiqlShapeBuilder::init_or_get())
};
($bld:expr) => {
$bld.new_static($crate::Static::DateTime)
};
}

Expand Down Expand Up @@ -505,6 +538,14 @@ impl PartiqlShapeBuilder {
self.new_static(Static::Bag(b))
}

#[must_use]
pub fn new_bag_of<E>(&self, element_type: E) -> PartiqlShape
where
E: Into<PartiqlShape>,
{
self.new_bag(BagType::new_of(element_type))
}

#[must_use]
pub fn new_array(&self, a: ArrayType) -> PartiqlShape {
self.new_static(Static::Array(a))
Expand Down Expand Up @@ -610,6 +651,12 @@ impl StaticType {
}
}

impl From<StaticType> for PartiqlShape {
fn from(value: StaticType) -> Self {
PartiqlShape::Static(value)
}
}

impl Display for StaticType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let ty = &self.ty;
Expand Down Expand Up @@ -862,17 +909,23 @@ pub struct BagType {
}

impl BagType {
#[must_use]
#[inline]
pub fn new_any() -> Self {
BagType::new(Box::new(PartiqlShape::Dynamic))
Self::new_of(PartiqlShape::Dynamic)
}

#[must_use]
#[inline]
pub fn new(typ: Box<PartiqlShape>) -> Self {
BagType { element_type: typ }
}

#[must_use]
pub fn new_of<E>(element_type: E) -> Self
where
E: Into<PartiqlShape>,
{
Self::new(Box::new(element_type.into()))
}

pub fn element_type(&self) -> &PartiqlShape {
&self.element_type
}
Expand Down

1 comment on commit deff7a8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartiQL (rust) Benchmark

Benchmark suite Current: deff7a8 Previous: 298a7ac Ratio
arith_agg-avg 767418 ns/iter (± 16285) 765347 ns/iter (± 8513) 1.00
arith_agg-avg_distinct 903823 ns/iter (± 3287) 847222 ns/iter (± 7986) 1.07
arith_agg-count 819135 ns/iter (± 12531) 812823 ns/iter (± 30152) 1.01
arith_agg-count_distinct 854689 ns/iter (± 1651) 842512 ns/iter (± 7959) 1.01
arith_agg-min 823294 ns/iter (± 3249) 817310 ns/iter (± 5161) 1.01
arith_agg-min_distinct 857361 ns/iter (± 2573) 847133 ns/iter (± 3064) 1.01
arith_agg-max 827553 ns/iter (± 2598) 819427 ns/iter (± 31464) 1.01
arith_agg-max_distinct 867044 ns/iter (± 28154) 855923 ns/iter (± 5014) 1.01
arith_agg-sum 822303 ns/iter (± 5920) 817783 ns/iter (± 5423) 1.01
arith_agg-sum_distinct 855984 ns/iter (± 2631) 848903 ns/iter (± 1816) 1.01
arith_agg-avg-count-min-max-sum 971203 ns/iter (± 6498) 960199 ns/iter (± 3322) 1.01
arith_agg-avg-count-min-max-sum-group_by 1196258 ns/iter (± 5932) 1201753 ns/iter (± 77040) 1.00
arith_agg-avg-count-min-max-sum-group_by-group_as 1797637 ns/iter (± 8280) 1810218 ns/iter (± 23349) 0.99
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct 1246192 ns/iter (± 18158) 1230609 ns/iter (± 44102) 1.01
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by 1525246 ns/iter (± 14601) 1506612 ns/iter (± 11262) 1.01
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as 2113403 ns/iter (± 18021) 2107345 ns/iter (± 18120) 1.00
parse-1 6086 ns/iter (± 42) 5893 ns/iter (± 9) 1.03
parse-15 52508 ns/iter (± 220) 49753 ns/iter (± 1552) 1.06
parse-30 99616 ns/iter (± 183) 97644 ns/iter (± 352) 1.02
compile-1 4306 ns/iter (± 21) 4357 ns/iter (± 13) 0.99
compile-15 33549 ns/iter (± 283) 33633 ns/iter (± 149) 1.00
compile-30 69303 ns/iter (± 361) 69764 ns/iter (± 674) 0.99
plan-1 67083 ns/iter (± 2328) 69164 ns/iter (± 565) 0.97
plan-15 1055829 ns/iter (± 17751) 1086857 ns/iter (± 29617) 0.97
plan-30 2106298 ns/iter (± 4583) 2177362 ns/iter (± 5766) 0.97
eval-1 12855153 ns/iter (± 122205) 12823198 ns/iter (± 139262) 1.00
eval-15 86807072 ns/iter (± 282541) 86529718 ns/iter (± 867525) 1.00
eval-30 167598895 ns/iter (± 2277227) 165759829 ns/iter (± 439741) 1.01
join 10468 ns/iter (± 20) 9835 ns/iter (± 100) 1.06
simple 2481 ns/iter (± 11) 2518 ns/iter (± 38) 0.99
simple-no 418 ns/iter (± 1) 416 ns/iter (± 16) 1.00
numbers 57 ns/iter (± 0) 57 ns/iter (± 0) 1
parse-simple 838 ns/iter (± 8) 940 ns/iter (± 11) 0.89
parse-ion 2827 ns/iter (± 14) 2513 ns/iter (± 82) 1.12
parse-group 7932 ns/iter (± 38) 7478 ns/iter (± 67) 1.06
parse-complex 20368 ns/iter (± 171) 19843 ns/iter (± 101) 1.03
parse-complex-fexpr 27608 ns/iter (± 138) 27436 ns/iter (± 176) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.