Skip to content

Commit

Permalink
Add more informational Display for Static types (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpschorr authored Aug 20, 2024
1 parent 843d3ee commit 298a7ac
Showing 1 changed file with 65 additions and 25 deletions.
90 changes: 65 additions & 25 deletions partiql-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl Display for PartiqlShape {
let x = match self {
PartiqlShape::Dynamic => "Dynamic".to_string(),
PartiqlShape::AnyOf(anyof) => {
format!("AnyOf({})", anyof.types.iter().cloned().join(","))
format!("AnyOf({})", anyof.types.iter().cloned().join(", "))
}
PartiqlShape::Static(s) => format!("{s}"),
PartiqlShape::Undefined => "Undefined".to_string(),
Expand Down Expand Up @@ -612,12 +612,12 @@ impl StaticType {

impl Display for StaticType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let nullable = if self.nullable {
"nullable"
let ty = &self.ty;
if self.nullable {
write!(f, "{ty}")
} else {
"non_nullable"
};
write!(f, "({}, {})", self.ty, nullable)
write!(f, "NOT NULL {ty}")
}
}
}

Expand Down Expand Up @@ -663,34 +663,34 @@ impl Static {
}
}

// TODO, this should probably be via a prettyprint...
impl Display for Static {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let x = match self {
Static::Int => "Int".to_string(),
Static::Int8 => "Int8".to_string(),
Static::Int16 => "Int16".to_string(),
Static::Int32 => "Int32".to_string(),
Static::Int64 => "Int64".to_string(),
Static::Bool => "Bool".to_string(),
Static::Decimal => "Decimal".to_string(),
Static::DecimalP(_, _) => {
todo!()
match self {
Static::Int => write!(f, "Int"),
Static::Int8 => write!(f, "Int8"),
Static::Int16 => write!(f, "Int16"),
Static::Int32 => write!(f, "Int32"),
Static::Int64 => write!(f, "Int64"),
Static::Bool => write!(f, "Bool"),
Static::Decimal => write!(f, "Decimal"),
Static::DecimalP(p, s) => {
write!(f, "Decimal({p},{s})")
}
Static::Float32 => "Float32".to_string(),
Static::Float64 => "Float64".to_string(),
Static::String => "String".to_string(),
Static::Float32 => write!(f, "Float32"),
Static::Float64 => write!(f, "Float64"),
Static::String => write!(f, "String"),
Static::StringFixed(_) => {
todo!()
}
Static::StringVarying(_) => {
todo!()
}
Static::DateTime => "DateTime".to_string(),
Static::Struct(_) => "Struct".to_string(),
Static::Bag(_) => "Bag".to_string(),
Static::Array(_) => "Array".to_string(),
};
write!(f, "{x}")
Static::DateTime => write!(f, "DateTime"),
Static::Struct(inner) => std::fmt::Display::fmt(inner, f),
Static::Bag(inner) => std::fmt::Display::fmt(inner, f),
Static::Array(inner) => std::fmt::Display::fmt(inner, f),
}
}
}

Expand Down Expand Up @@ -754,6 +754,32 @@ impl StructType {
}
}

impl Display for StructType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let partial = self.is_partial();
write!(f, "{{")?;
let mut first = true;
for StructField { name, ty, optional } in self.fields() {
if !first {
write!(f, ", ")?;
}
if *optional {
write!(f, "{name}?: {ty}")?;
} else {
write!(f, "{name}: {ty}")?;
}
first = false
}
if partial {
if !first {
write!(f, ", ")?;
}
write!(f, "...")?;
}
write!(f, "}}")
}
}

#[derive(Derivative, Eq, Debug, Clone)]
#[derivative(PartialEq, Hash)]
#[allow(dead_code)]
Expand Down Expand Up @@ -852,6 +878,13 @@ impl BagType {
}
}

impl Display for BagType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let ty = &self.element_type;
write!(f, "<<{ty}>>")
}
}

#[derive(Derivative, Eq, Debug, Clone)]
#[derivative(PartialEq, Hash)]
#[allow(dead_code)]
Expand All @@ -878,6 +911,13 @@ impl ArrayType {
}
}

impl Display for ArrayType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let ty = &self.element_type;
write!(f, "[{ty}]")
}
}

#[cfg(test)]
mod tests {
use crate::{
Expand Down

1 comment on commit 298a7ac

@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: 298a7ac Previous: 843d3ee Ratio
arith_agg-avg 765347 ns/iter (± 8513) 759774 ns/iter (± 16111) 1.01
arith_agg-avg_distinct 847222 ns/iter (± 7986) 851602 ns/iter (± 1675) 0.99
arith_agg-count 812823 ns/iter (± 30152) 809485 ns/iter (± 31348) 1.00
arith_agg-count_distinct 842512 ns/iter (± 7959) 850096 ns/iter (± 2714) 0.99
arith_agg-min 817310 ns/iter (± 5161) 813205 ns/iter (± 2203) 1.01
arith_agg-min_distinct 847133 ns/iter (± 3064) 851965 ns/iter (± 18121) 0.99
arith_agg-max 819427 ns/iter (± 31464) 832033 ns/iter (± 4653) 0.98
arith_agg-max_distinct 855923 ns/iter (± 5014) 861344 ns/iter (± 4073) 0.99
arith_agg-sum 817783 ns/iter (± 5423) 815417 ns/iter (± 2226) 1.00
arith_agg-sum_distinct 848903 ns/iter (± 1816) 855702 ns/iter (± 2666) 0.99
arith_agg-avg-count-min-max-sum 960199 ns/iter (± 3322) 957159 ns/iter (± 4904) 1.00
arith_agg-avg-count-min-max-sum-group_by 1201753 ns/iter (± 77040) 1213008 ns/iter (± 15351) 0.99
arith_agg-avg-count-min-max-sum-group_by-group_as 1810218 ns/iter (± 23349) 1814083 ns/iter (± 5194) 1.00
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct 1230609 ns/iter (± 44102) 1263534 ns/iter (± 15338) 0.97
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by 1506612 ns/iter (± 11262) 1528754 ns/iter (± 12065) 0.99
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as 2107345 ns/iter (± 18120) 2132246 ns/iter (± 21947) 0.99
parse-1 5893 ns/iter (± 9) 5994 ns/iter (± 90) 0.98
parse-15 49753 ns/iter (± 1552) 52257 ns/iter (± 560) 0.95
parse-30 97644 ns/iter (± 352) 101862 ns/iter (± 335) 0.96
compile-1 4357 ns/iter (± 13) 4264 ns/iter (± 14) 1.02
compile-15 33633 ns/iter (± 149) 32659 ns/iter (± 226) 1.03
compile-30 69764 ns/iter (± 674) 69444 ns/iter (± 1090) 1.00
plan-1 69164 ns/iter (± 565) 67184 ns/iter (± 484) 1.03
plan-15 1086857 ns/iter (± 29617) 1052870 ns/iter (± 8363) 1.03
plan-30 2177362 ns/iter (± 5766) 2111762 ns/iter (± 8350) 1.03
eval-1 12823198 ns/iter (± 139262) 12633251 ns/iter (± 38348) 1.02
eval-15 86529718 ns/iter (± 867525) 85671873 ns/iter (± 809621) 1.01
eval-30 165759829 ns/iter (± 439741) 164703537 ns/iter (± 499568) 1.01
join 9835 ns/iter (± 100) 9731 ns/iter (± 39) 1.01
simple 2518 ns/iter (± 38) 2489 ns/iter (± 7) 1.01
simple-no 416 ns/iter (± 16) 432 ns/iter (± 1) 0.96
numbers 57 ns/iter (± 0) 57 ns/iter (± 0) 1
parse-simple 940 ns/iter (± 11) 847 ns/iter (± 3) 1.11
parse-ion 2513 ns/iter (± 82) 2525 ns/iter (± 9) 1.00
parse-group 7478 ns/iter (± 67) 7762 ns/iter (± 504) 0.96
parse-complex 19843 ns/iter (± 101) 19915 ns/iter (± 679) 1.00
parse-complex-fexpr 27436 ns/iter (± 176) 27020 ns/iter (± 208) 1.02

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

Please sign in to comment.