Skip to content

Commit

Permalink
PartiQL types rename (#469)
Browse files Browse the repository at this point in the history
Renames StaticTypeVariant to Static to make it shorter and the usage easier—it is behavioral preserving.
  • Loading branch information
am357 committed Jun 24, 2024
1 parent 0ff57fe commit 6aacf26
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 140 deletions.
45 changes: 20 additions & 25 deletions extension/partiql-extension-ddl/src/ddl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use ion_rs::IonError;
use miette::Diagnostic;
use partiql_types::{
AnyOf, ArrayType, BagType, PartiqlShape, ShapeResultError, StaticType, StaticTypeVariant,
StructType,
AnyOf, ArrayType, BagType, PartiqlShape, ShapeResultError, Static, StaticType, StructType,
};
use std::fmt::{Display, Formatter};
use std::string::ToString;
Expand Down Expand Up @@ -111,22 +110,21 @@ impl PartiqlBasicDdlEncoder {
let mut out = String::new();

match ty.ty() {
StaticTypeVariant::Int => out.push_str("INT"),
StaticTypeVariant::Int8 => out.push_str("TINYINT"),
StaticTypeVariant::Int16 => out.push_str("SMALLINT"),
StaticTypeVariant::Int32 => out.push_str("INTEGER"),
StaticTypeVariant::Int64 => out.push_str("INT8"),
StaticTypeVariant::Bool => out.push_str("BOOL"),
StaticTypeVariant::Decimal => out.push_str("DECIMAL"),
StaticTypeVariant::DecimalP(p, s) => out.push_str(&format!("DECIMAL({p}, {s})")),
StaticTypeVariant::DateTime => out.push_str("TIMESTAMP"),
StaticTypeVariant::Float32 => out.push_str("REAL"),
StaticTypeVariant::Float64 => out.push_str("DOUBLE"),
StaticTypeVariant::String => out.push_str("VARCHAR"),
StaticTypeVariant::Struct(s) => out.push_str(&self.write_struct(&s)?),
StaticTypeVariant::Bag(b) => out.push_str(&self.write_bag(&b)?),
StaticTypeVariant::Array(a) => out.push_str(&self.write_array(&a)?),

Static::Int => out.push_str("INT"),
Static::Int8 => out.push_str("TINYINT"),
Static::Int16 => out.push_str("SMALLINT"),
Static::Int32 => out.push_str("INTEGER"),
Static::Int64 => out.push_str("INT8"),
Static::Bool => out.push_str("BOOL"),
Static::Decimal => out.push_str("DECIMAL"),
Static::DecimalP(p, s) => out.push_str(&format!("DECIMAL({p}, {s})")),
Static::DateTime => out.push_str("TIMESTAMP"),
Static::Float32 => out.push_str("REAL"),
Static::Float64 => out.push_str("DOUBLE"),
Static::String => out.push_str("VARCHAR"),
Static::Struct(s) => out.push_str(&self.write_struct(&s)?),
Static::Bag(b) => out.push_str(&self.write_bag(&b)?),
Static::Array(a) => out.push_str(&self.write_array(&a)?),
// non-exhaustive catch-all
_ => todo!("handle type for {}", ty),
}
Expand Down Expand Up @@ -192,7 +190,7 @@ impl PartiqlDdlEncoder for PartiqlBasicDdlEncoder {
let mut output = String::new();
let ty = ty.expect_static()?;

if let StaticTypeVariant::Bag(bag) = ty.ty() {
if let Static::Bag(bag) = ty.ty() {
let s = bag.element_type().expect_struct()?;
let fields = s.fields();
let mut fields = fields.iter().peekable();
Expand Down Expand Up @@ -235,8 +233,8 @@ mod tests {
(
"a",
PartiqlShape::any_of(vec![
PartiqlShape::new(StaticTypeVariant::DecimalP(5, 4)),
PartiqlShape::new(StaticTypeVariant::Int8),
PartiqlShape::new(Static::DecimalP(5, 4)),
PartiqlShape::new(Static::Int8),
])
),
("b", array![str![]]),
Expand All @@ -247,10 +245,7 @@ mod tests {
let fields = struct_fields![
("employee_id", int8![]),
("full_name", str![]),
(
"salary",
PartiqlShape::new(StaticTypeVariant::DecimalP(8, 2))
),
("salary", PartiqlShape::new(Static::DecimalP(8, 2))),
("details", details),
("dependents", array![str![]])
];
Expand Down
7 changes: 2 additions & 5 deletions extension/partiql-extension-ddl/tests/ddl-tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use partiql_extension_ddl::ddl::{DdlFormat, PartiqlBasicDdlEncoder, PartiqlDdlEncoder};
use partiql_types::{bag, int, r#struct, str, struct_fields, StructConstraint, StructField};
use partiql_types::{BagType, PartiqlShape, StaticTypeVariant, StructType};
use partiql_types::{BagType, PartiqlShape, Static, StructType};
use std::collections::BTreeSet;

#[test]
Expand All @@ -10,10 +10,7 @@ fn basic_ddl_test() {
let fields = [
StructField::new("id", int!()),
StructField::new("name", str!()),
StructField::new(
"address",
PartiqlShape::new_non_nullable(StaticTypeVariant::String),
),
StructField::new("address", PartiqlShape::new_non_nullable(Static::String)),
StructField::new_optional("details", details.clone()),
]
.into();
Expand Down
28 changes: 10 additions & 18 deletions partiql-eval/src/eval/eval_expr_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::eval::expr::{BindError, EvalExpr};
use crate::eval::EvalContext;
use itertools::Itertools;

use partiql_types::{PartiqlShape, StaticTypeVariant, TYPE_DYNAMIC};
use partiql_types::{PartiqlShape, Static, TYPE_DYNAMIC};
use partiql_value::Value::{Missing, Null};
use partiql_value::{Tuple, Value};

Expand All @@ -26,33 +26,25 @@ pub(crate) fn subsumes(typ: &PartiqlShape, value: &Value) -> bool {
(PartiqlShape::AnyOf(anyof), val) => anyof.types().any(|typ| subsumes(typ, val)),
(PartiqlShape::Static(s), val) => match (s.ty(), val) {
(
StaticTypeVariant::Int
| StaticTypeVariant::Int8
| StaticTypeVariant::Int16
| StaticTypeVariant::Int32
| StaticTypeVariant::Int64,
Static::Int | Static::Int8 | Static::Int16 | Static::Int32 | Static::Int64,
Value::Integer(_),
) => true,
(StaticTypeVariant::Bool, Value::Boolean(_)) => true,
(StaticTypeVariant::Decimal | StaticTypeVariant::DecimalP(_, _), Value::Decimal(_)) => {
true
}
(StaticTypeVariant::Float32 | StaticTypeVariant::Float64, Value::Real(_)) => true,
(Static::Bool, Value::Boolean(_)) => true,
(Static::Decimal | Static::DecimalP(_, _), Value::Decimal(_)) => true,
(Static::Float32 | Static::Float64, Value::Real(_)) => true,
(
StaticTypeVariant::String
| StaticTypeVariant::StringFixed(_)
| StaticTypeVariant::StringVarying(_),
Static::String | Static::StringFixed(_) | Static::StringVarying(_),
Value::String(_),
) => true,
(StaticTypeVariant::Struct(_), Value::Tuple(_)) => true,
(StaticTypeVariant::Bag(b_type), Value::Bag(b_values)) => {
(Static::Struct(_), Value::Tuple(_)) => true,
(Static::Bag(b_type), Value::Bag(b_values)) => {
let bag_element_type = b_type.element_type();
let mut b_values = b_values.iter();
b_values.all(|b_value| subsumes(bag_element_type, b_value))
}
(StaticTypeVariant::DateTime, Value::DateTime(_)) => true,
(Static::DateTime, Value::DateTime(_)) => true,

(StaticTypeVariant::Array(a_type), Value::List(l_values)) => {
(Static::Array(a_type), Value::List(l_values)) => {
let array_element_type = a_type.element_type();
let mut l_values = l_values.iter();
l_values.all(|l_value| subsumes(array_element_type, l_value))
Expand Down
22 changes: 9 additions & 13 deletions partiql-eval/src/eval/expr/coll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use crate::eval::expr::{BindError, BindEvalExpr, EvalExpr};

use itertools::{Itertools, Unique};

use partiql_types::{
ArrayType, BagType, PartiqlShape, StaticTypeVariant, TYPE_BOOL, TYPE_NUMERIC_TYPES,
};
use partiql_types::{ArrayType, BagType, PartiqlShape, Static, TYPE_BOOL, TYPE_NUMERIC_TYPES};
use partiql_value::Value::{Missing, Null};
use partiql_value::{BinaryAnd, BinaryOr, Value, ValueIter};

Expand Down Expand Up @@ -52,22 +50,20 @@ impl BindEvalExpr for EvalCollFn {
})
}
let boolean_elems = [PartiqlShape::any_of([
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new(Box::new(
TYPE_BOOL,
)))),
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new(Box::new(TYPE_BOOL)))),
PartiqlShape::new(Static::Array(ArrayType::new(Box::new(TYPE_BOOL)))),
PartiqlShape::new(Static::Bag(BagType::new(Box::new(TYPE_BOOL)))),
])];
let numeric_elems = [PartiqlShape::any_of([
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new(Box::new(
PartiqlShape::any_of(TYPE_NUMERIC_TYPES),
)))),
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new(Box::new(
PartiqlShape::new(Static::Array(ArrayType::new(Box::new(
PartiqlShape::any_of(TYPE_NUMERIC_TYPES),
)))),
PartiqlShape::new(Static::Bag(BagType::new(Box::new(PartiqlShape::any_of(
TYPE_NUMERIC_TYPES,
))))),
])];
let any_elems = [PartiqlShape::any_of([
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any())),
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
PartiqlShape::new(Static::Array(ArrayType::new_any())),
PartiqlShape::new(Static::Bag(BagType::new_any())),
])];

match *self {
Expand Down
12 changes: 6 additions & 6 deletions partiql-eval/src/eval/expr/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::eval::expr::{BindError, BindEvalExpr, EvalExpr};
use crate::eval::EvalContext;

use partiql_types::{
ArrayType, BagType, PartiqlShape, StaticTypeVariant, StructType, TYPE_BOOL, TYPE_DYNAMIC,
ArrayType, BagType, PartiqlShape, Static, StructType, TYPE_BOOL, TYPE_DYNAMIC,
TYPE_NUMERIC_TYPES,
};
use partiql_value::Value::{Boolean, Missing, Null};
Expand Down Expand Up @@ -211,8 +211,8 @@ impl BindEvalExpr for EvalOpBinary {
[
TYPE_DYNAMIC,
PartiqlShape::any_of([
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any())),
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
PartiqlShape::new(Static::Array(ArrayType::new_any())),
PartiqlShape::new(Static::Bag(BagType::new_any())),
])
],
|lhs, rhs| {
Expand Down Expand Up @@ -338,9 +338,9 @@ impl BindEvalExpr for EvalFnCardinality {
args: Vec<Box<dyn EvalExpr>>,
) -> Result<Box<dyn EvalExpr>, BindError> {
let collections = PartiqlShape::any_of([
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any())),
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
PartiqlShape::new(StaticTypeVariant::Struct(StructType::new_any())),
PartiqlShape::new(Static::Array(ArrayType::new_any())),
PartiqlShape::new(Static::Bag(BagType::new_any())),
PartiqlShape::new(Static::Struct(StructType::new_any())),
]);

UnaryValueExpr::create_typed::<{ STRICT }, _>([collections], args, |v| match v {
Expand Down
26 changes: 11 additions & 15 deletions partiql-logical-planner/src/typer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use partiql_ast::ast::{CaseSensitivity, SymbolPrimitive};
use partiql_catalog::Catalog;
use partiql_logical::{BindingsOp, LogicalPlan, OpId, PathComponent, ValueExpr, VarRefType};
use partiql_types::{
dynamic, undefined, ArrayType, BagType, PartiqlShape, ShapeResultError, StaticTypeVariant,
dynamic, undefined, ArrayType, BagType, PartiqlShape, ShapeResultError, Static,
StructConstraint, StructField, StructType,
};
use partiql_value::{BindingsName, Value};
Expand Down Expand Up @@ -331,17 +331,13 @@ impl<'c> PlanTyper<'c> {
let ty = match **v {
Value::Null => PartiqlShape::Undefined,
Value::Missing => PartiqlShape::Undefined,
Value::Integer(_) => PartiqlShape::new(StaticTypeVariant::Int),
Value::Decimal(_) => PartiqlShape::new(StaticTypeVariant::Decimal),
Value::Boolean(_) => PartiqlShape::new(StaticTypeVariant::Bool),
Value::String(_) => PartiqlShape::new(StaticTypeVariant::String),
Value::Tuple(_) => {
PartiqlShape::new(StaticTypeVariant::Struct(StructType::new_any()))
}
Value::List(_) => {
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any()))
}
Value::Bag(_) => PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
Value::Integer(_) => PartiqlShape::new(Static::Int),
Value::Decimal(_) => PartiqlShape::new(Static::Decimal),
Value::Boolean(_) => PartiqlShape::new(Static::Bool),
Value::String(_) => PartiqlShape::new(Static::String),
Value::Tuple(_) => PartiqlShape::new(Static::Struct(StructType::new_any())),
Value::List(_) => PartiqlShape::new(Static::Array(ArrayType::new_any())),
Value::Bag(_) => PartiqlShape::new(Static::Bag(BagType::new_any())),
_ => {
self.errors.push(TypingError::NotYetImplemented(
"Unsupported Literal".to_string(),
Expand Down Expand Up @@ -416,8 +412,8 @@ impl<'c> PlanTyper<'c> {
match ty {
PartiqlShape::Dynamic => dynamic!(),
PartiqlShape::Static(s) => match s.ty() {
StaticTypeVariant::Bag(b) => b.element_type().clone(),
StaticTypeVariant::Array(a) => a.element_type().clone(),
Static::Bag(b) => b.element_type().clone(),
Static::Array(a) => a.element_type().clone(),
_ => ty.clone(),
},
undefined!() => {
Expand Down Expand Up @@ -885,7 +881,7 @@ mod tests {
.expect_static()?;

match &actual.ty() {
StaticTypeVariant::Bag(b) => {
Static::Bag(b) => {
if let Ok(s) = b.element_type().expect_struct() {
let fields = s.fields();

Expand Down
Loading

1 comment on commit 6aacf26

@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: 6aacf26 Previous: 0ff57fe Ratio
arith_agg-avg 763871 ns/iter (± 16021) 773116 ns/iter (± 2623) 0.99
arith_agg-avg_distinct 852943 ns/iter (± 3449) 865623 ns/iter (± 2549) 0.99
arith_agg-count 814660 ns/iter (± 33937) 823424 ns/iter (± 20776) 0.99
arith_agg-count_distinct 849958 ns/iter (± 19612) 858799 ns/iter (± 2523) 0.99
arith_agg-min 824840 ns/iter (± 9846) 833652 ns/iter (± 3931) 0.99
arith_agg-min_distinct 850504 ns/iter (± 2210) 860304 ns/iter (± 2109) 0.99
arith_agg-max 823622 ns/iter (± 4384) 833308 ns/iter (± 5201) 0.99
arith_agg-max_distinct 858951 ns/iter (± 43476) 870059 ns/iter (± 3095) 0.99
arith_agg-sum 819811 ns/iter (± 2761) 829368 ns/iter (± 6942) 0.99
arith_agg-sum_distinct 851693 ns/iter (± 1550) 863942 ns/iter (± 2698) 0.99
arith_agg-avg-count-min-max-sum 957278 ns/iter (± 2662) 966623 ns/iter (± 3124) 0.99
arith_agg-avg-count-min-max-sum-group_by 1248673 ns/iter (± 36672) 1236084 ns/iter (± 21254) 1.01
arith_agg-avg-count-min-max-sum-group_by-group_as 1806472 ns/iter (± 8763) 1810208 ns/iter (± 6165) 1.00
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct 1185526 ns/iter (± 19073) 1209188 ns/iter (± 21886) 0.98
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by 1550045 ns/iter (± 22776) 1547784 ns/iter (± 42181) 1.00
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as 2135610 ns/iter (± 8933) 2155021 ns/iter (± 9462) 0.99
parse-1 4291 ns/iter (± 28) 4355 ns/iter (± 214) 0.99
parse-15 39114 ns/iter (± 116) 39951 ns/iter (± 128) 0.98
parse-30 76826 ns/iter (± 685) 78256 ns/iter (± 373) 0.98
compile-1 4348 ns/iter (± 41) 4370 ns/iter (± 14) 0.99
compile-15 32854 ns/iter (± 158) 33576 ns/iter (± 152) 0.98
compile-30 68294 ns/iter (± 384) 68755 ns/iter (± 1872) 0.99
plan-1 67609 ns/iter (± 318) 67156 ns/iter (± 335) 1.01
plan-15 1052784 ns/iter (± 24201) 1046604 ns/iter (± 11680) 1.01
plan-30 2112743 ns/iter (± 10868) 2089167 ns/iter (± 8096) 1.01
eval-1 13547112 ns/iter (± 413645) 13269424 ns/iter (± 124609) 1.02
eval-15 88002637 ns/iter (± 810315) 87780096 ns/iter (± 416747) 1.00
eval-30 168873333 ns/iter (± 1558481) 168266854 ns/iter (± 12768738) 1.00
join 9770 ns/iter (± 22) 9838 ns/iter (± 53) 0.99
simple 2457 ns/iter (± 7) 2477 ns/iter (± 22) 0.99
simple-no 435 ns/iter (± 1) 425 ns/iter (± 1) 1.02
numbers 57 ns/iter (± 0) 57 ns/iter (± 0) 1
parse-simple 554 ns/iter (± 2) 580 ns/iter (± 2) 0.96
parse-ion 1749 ns/iter (± 11) 1776 ns/iter (± 3) 0.98
parse-group 5816 ns/iter (± 58) 5920 ns/iter (± 18) 0.98
parse-complex 15316 ns/iter (± 127) 15097 ns/iter (± 66) 1.01
parse-complex-fexpr 22632 ns/iter (± 439) 22184 ns/iter (± 274) 1.02

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

Please sign in to comment.