Skip to content

Commit 6aacf26

Browse files
authored
PartiQL types rename (#469)
Renames StaticTypeVariant to Static to make it shorter and the usage easier—it is behavioral preserving.
1 parent 0ff57fe commit 6aacf26

File tree

7 files changed

+116
-140
lines changed

7 files changed

+116
-140
lines changed

extension/partiql-extension-ddl/src/ddl.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use ion_rs::IonError;
22
use miette::Diagnostic;
33
use partiql_types::{
4-
AnyOf, ArrayType, BagType, PartiqlShape, ShapeResultError, StaticType, StaticTypeVariant,
5-
StructType,
4+
AnyOf, ArrayType, BagType, PartiqlShape, ShapeResultError, Static, StaticType, StructType,
65
};
76
use std::fmt::{Display, Formatter};
87
use std::string::ToString;
@@ -111,22 +110,21 @@ impl PartiqlBasicDdlEncoder {
111110
let mut out = String::new();
112111

113112
match ty.ty() {
114-
StaticTypeVariant::Int => out.push_str("INT"),
115-
StaticTypeVariant::Int8 => out.push_str("TINYINT"),
116-
StaticTypeVariant::Int16 => out.push_str("SMALLINT"),
117-
StaticTypeVariant::Int32 => out.push_str("INTEGER"),
118-
StaticTypeVariant::Int64 => out.push_str("INT8"),
119-
StaticTypeVariant::Bool => out.push_str("BOOL"),
120-
StaticTypeVariant::Decimal => out.push_str("DECIMAL"),
121-
StaticTypeVariant::DecimalP(p, s) => out.push_str(&format!("DECIMAL({p}, {s})")),
122-
StaticTypeVariant::DateTime => out.push_str("TIMESTAMP"),
123-
StaticTypeVariant::Float32 => out.push_str("REAL"),
124-
StaticTypeVariant::Float64 => out.push_str("DOUBLE"),
125-
StaticTypeVariant::String => out.push_str("VARCHAR"),
126-
StaticTypeVariant::Struct(s) => out.push_str(&self.write_struct(&s)?),
127-
StaticTypeVariant::Bag(b) => out.push_str(&self.write_bag(&b)?),
128-
StaticTypeVariant::Array(a) => out.push_str(&self.write_array(&a)?),
129-
113+
Static::Int => out.push_str("INT"),
114+
Static::Int8 => out.push_str("TINYINT"),
115+
Static::Int16 => out.push_str("SMALLINT"),
116+
Static::Int32 => out.push_str("INTEGER"),
117+
Static::Int64 => out.push_str("INT8"),
118+
Static::Bool => out.push_str("BOOL"),
119+
Static::Decimal => out.push_str("DECIMAL"),
120+
Static::DecimalP(p, s) => out.push_str(&format!("DECIMAL({p}, {s})")),
121+
Static::DateTime => out.push_str("TIMESTAMP"),
122+
Static::Float32 => out.push_str("REAL"),
123+
Static::Float64 => out.push_str("DOUBLE"),
124+
Static::String => out.push_str("VARCHAR"),
125+
Static::Struct(s) => out.push_str(&self.write_struct(&s)?),
126+
Static::Bag(b) => out.push_str(&self.write_bag(&b)?),
127+
Static::Array(a) => out.push_str(&self.write_array(&a)?),
130128
// non-exhaustive catch-all
131129
_ => todo!("handle type for {}", ty),
132130
}
@@ -192,7 +190,7 @@ impl PartiqlDdlEncoder for PartiqlBasicDdlEncoder {
192190
let mut output = String::new();
193191
let ty = ty.expect_static()?;
194192

195-
if let StaticTypeVariant::Bag(bag) = ty.ty() {
193+
if let Static::Bag(bag) = ty.ty() {
196194
let s = bag.element_type().expect_struct()?;
197195
let fields = s.fields();
198196
let mut fields = fields.iter().peekable();
@@ -235,8 +233,8 @@ mod tests {
235233
(
236234
"a",
237235
PartiqlShape::any_of(vec![
238-
PartiqlShape::new(StaticTypeVariant::DecimalP(5, 4)),
239-
PartiqlShape::new(StaticTypeVariant::Int8),
236+
PartiqlShape::new(Static::DecimalP(5, 4)),
237+
PartiqlShape::new(Static::Int8),
240238
])
241239
),
242240
("b", array![str![]]),
@@ -247,10 +245,7 @@ mod tests {
247245
let fields = struct_fields![
248246
("employee_id", int8![]),
249247
("full_name", str![]),
250-
(
251-
"salary",
252-
PartiqlShape::new(StaticTypeVariant::DecimalP(8, 2))
253-
),
248+
("salary", PartiqlShape::new(Static::DecimalP(8, 2))),
254249
("details", details),
255250
("dependents", array![str![]])
256251
];

extension/partiql-extension-ddl/tests/ddl-tests.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use partiql_extension_ddl::ddl::{DdlFormat, PartiqlBasicDdlEncoder, PartiqlDdlEncoder};
22
use partiql_types::{bag, int, r#struct, str, struct_fields, StructConstraint, StructField};
3-
use partiql_types::{BagType, PartiqlShape, StaticTypeVariant, StructType};
3+
use partiql_types::{BagType, PartiqlShape, Static, StructType};
44
use std::collections::BTreeSet;
55

66
#[test]
@@ -10,10 +10,7 @@ fn basic_ddl_test() {
1010
let fields = [
1111
StructField::new("id", int!()),
1212
StructField::new("name", str!()),
13-
StructField::new(
14-
"address",
15-
PartiqlShape::new_non_nullable(StaticTypeVariant::String),
16-
),
13+
StructField::new("address", PartiqlShape::new_non_nullable(Static::String)),
1714
StructField::new_optional("details", details.clone()),
1815
]
1916
.into();

partiql-eval/src/eval/eval_expr_wrapper.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::eval::expr::{BindError, EvalExpr};
44
use crate::eval::EvalContext;
55
use itertools::Itertools;
66

7-
use partiql_types::{PartiqlShape, StaticTypeVariant, TYPE_DYNAMIC};
7+
use partiql_types::{PartiqlShape, Static, TYPE_DYNAMIC};
88
use partiql_value::Value::{Missing, Null};
99
use partiql_value::{Tuple, Value};
1010

@@ -26,33 +26,25 @@ pub(crate) fn subsumes(typ: &PartiqlShape, value: &Value) -> bool {
2626
(PartiqlShape::AnyOf(anyof), val) => anyof.types().any(|typ| subsumes(typ, val)),
2727
(PartiqlShape::Static(s), val) => match (s.ty(), val) {
2828
(
29-
StaticTypeVariant::Int
30-
| StaticTypeVariant::Int8
31-
| StaticTypeVariant::Int16
32-
| StaticTypeVariant::Int32
33-
| StaticTypeVariant::Int64,
29+
Static::Int | Static::Int8 | Static::Int16 | Static::Int32 | Static::Int64,
3430
Value::Integer(_),
3531
) => true,
36-
(StaticTypeVariant::Bool, Value::Boolean(_)) => true,
37-
(StaticTypeVariant::Decimal | StaticTypeVariant::DecimalP(_, _), Value::Decimal(_)) => {
38-
true
39-
}
40-
(StaticTypeVariant::Float32 | StaticTypeVariant::Float64, Value::Real(_)) => true,
32+
(Static::Bool, Value::Boolean(_)) => true,
33+
(Static::Decimal | Static::DecimalP(_, _), Value::Decimal(_)) => true,
34+
(Static::Float32 | Static::Float64, Value::Real(_)) => true,
4135
(
42-
StaticTypeVariant::String
43-
| StaticTypeVariant::StringFixed(_)
44-
| StaticTypeVariant::StringVarying(_),
36+
Static::String | Static::StringFixed(_) | Static::StringVarying(_),
4537
Value::String(_),
4638
) => true,
47-
(StaticTypeVariant::Struct(_), Value::Tuple(_)) => true,
48-
(StaticTypeVariant::Bag(b_type), Value::Bag(b_values)) => {
39+
(Static::Struct(_), Value::Tuple(_)) => true,
40+
(Static::Bag(b_type), Value::Bag(b_values)) => {
4941
let bag_element_type = b_type.element_type();
5042
let mut b_values = b_values.iter();
5143
b_values.all(|b_value| subsumes(bag_element_type, b_value))
5244
}
53-
(StaticTypeVariant::DateTime, Value::DateTime(_)) => true,
45+
(Static::DateTime, Value::DateTime(_)) => true,
5446

55-
(StaticTypeVariant::Array(a_type), Value::List(l_values)) => {
47+
(Static::Array(a_type), Value::List(l_values)) => {
5648
let array_element_type = a_type.element_type();
5749
let mut l_values = l_values.iter();
5850
l_values.all(|l_value| subsumes(array_element_type, l_value))

partiql-eval/src/eval/expr/coll.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::eval::expr::{BindError, BindEvalExpr, EvalExpr};
44

55
use itertools::{Itertools, Unique};
66

7-
use partiql_types::{
8-
ArrayType, BagType, PartiqlShape, StaticTypeVariant, TYPE_BOOL, TYPE_NUMERIC_TYPES,
9-
};
7+
use partiql_types::{ArrayType, BagType, PartiqlShape, Static, TYPE_BOOL, TYPE_NUMERIC_TYPES};
108
use partiql_value::Value::{Missing, Null};
119
use partiql_value::{BinaryAnd, BinaryOr, Value, ValueIter};
1210

@@ -52,22 +50,20 @@ impl BindEvalExpr for EvalCollFn {
5250
})
5351
}
5452
let boolean_elems = [PartiqlShape::any_of([
55-
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new(Box::new(
56-
TYPE_BOOL,
57-
)))),
58-
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new(Box::new(TYPE_BOOL)))),
53+
PartiqlShape::new(Static::Array(ArrayType::new(Box::new(TYPE_BOOL)))),
54+
PartiqlShape::new(Static::Bag(BagType::new(Box::new(TYPE_BOOL)))),
5955
])];
6056
let numeric_elems = [PartiqlShape::any_of([
61-
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new(Box::new(
62-
PartiqlShape::any_of(TYPE_NUMERIC_TYPES),
63-
)))),
64-
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new(Box::new(
57+
PartiqlShape::new(Static::Array(ArrayType::new(Box::new(
6558
PartiqlShape::any_of(TYPE_NUMERIC_TYPES),
6659
)))),
60+
PartiqlShape::new(Static::Bag(BagType::new(Box::new(PartiqlShape::any_of(
61+
TYPE_NUMERIC_TYPES,
62+
))))),
6763
])];
6864
let any_elems = [PartiqlShape::any_of([
69-
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any())),
70-
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
65+
PartiqlShape::new(Static::Array(ArrayType::new_any())),
66+
PartiqlShape::new(Static::Bag(BagType::new_any())),
7167
])];
7268

7369
match *self {

partiql-eval/src/eval/expr/operators.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::eval::expr::{BindError, BindEvalExpr, EvalExpr};
88
use crate::eval::EvalContext;
99

1010
use partiql_types::{
11-
ArrayType, BagType, PartiqlShape, StaticTypeVariant, StructType, TYPE_BOOL, TYPE_DYNAMIC,
11+
ArrayType, BagType, PartiqlShape, Static, StructType, TYPE_BOOL, TYPE_DYNAMIC,
1212
TYPE_NUMERIC_TYPES,
1313
};
1414
use partiql_value::Value::{Boolean, Missing, Null};
@@ -211,8 +211,8 @@ impl BindEvalExpr for EvalOpBinary {
211211
[
212212
TYPE_DYNAMIC,
213213
PartiqlShape::any_of([
214-
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any())),
215-
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
214+
PartiqlShape::new(Static::Array(ArrayType::new_any())),
215+
PartiqlShape::new(Static::Bag(BagType::new_any())),
216216
])
217217
],
218218
|lhs, rhs| {
@@ -338,9 +338,9 @@ impl BindEvalExpr for EvalFnCardinality {
338338
args: Vec<Box<dyn EvalExpr>>,
339339
) -> Result<Box<dyn EvalExpr>, BindError> {
340340
let collections = PartiqlShape::any_of([
341-
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any())),
342-
PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
343-
PartiqlShape::new(StaticTypeVariant::Struct(StructType::new_any())),
341+
PartiqlShape::new(Static::Array(ArrayType::new_any())),
342+
PartiqlShape::new(Static::Bag(BagType::new_any())),
343+
PartiqlShape::new(Static::Struct(StructType::new_any())),
344344
]);
345345

346346
UnaryValueExpr::create_typed::<{ STRICT }, _>([collections], args, |v| match v {

partiql-logical-planner/src/typer.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use partiql_ast::ast::{CaseSensitivity, SymbolPrimitive};
44
use partiql_catalog::Catalog;
55
use partiql_logical::{BindingsOp, LogicalPlan, OpId, PathComponent, ValueExpr, VarRefType};
66
use partiql_types::{
7-
dynamic, undefined, ArrayType, BagType, PartiqlShape, ShapeResultError, StaticTypeVariant,
7+
dynamic, undefined, ArrayType, BagType, PartiqlShape, ShapeResultError, Static,
88
StructConstraint, StructField, StructType,
99
};
1010
use partiql_value::{BindingsName, Value};
@@ -331,17 +331,13 @@ impl<'c> PlanTyper<'c> {
331331
let ty = match **v {
332332
Value::Null => PartiqlShape::Undefined,
333333
Value::Missing => PartiqlShape::Undefined,
334-
Value::Integer(_) => PartiqlShape::new(StaticTypeVariant::Int),
335-
Value::Decimal(_) => PartiqlShape::new(StaticTypeVariant::Decimal),
336-
Value::Boolean(_) => PartiqlShape::new(StaticTypeVariant::Bool),
337-
Value::String(_) => PartiqlShape::new(StaticTypeVariant::String),
338-
Value::Tuple(_) => {
339-
PartiqlShape::new(StaticTypeVariant::Struct(StructType::new_any()))
340-
}
341-
Value::List(_) => {
342-
PartiqlShape::new(StaticTypeVariant::Array(ArrayType::new_any()))
343-
}
344-
Value::Bag(_) => PartiqlShape::new(StaticTypeVariant::Bag(BagType::new_any())),
334+
Value::Integer(_) => PartiqlShape::new(Static::Int),
335+
Value::Decimal(_) => PartiqlShape::new(Static::Decimal),
336+
Value::Boolean(_) => PartiqlShape::new(Static::Bool),
337+
Value::String(_) => PartiqlShape::new(Static::String),
338+
Value::Tuple(_) => PartiqlShape::new(Static::Struct(StructType::new_any())),
339+
Value::List(_) => PartiqlShape::new(Static::Array(ArrayType::new_any())),
340+
Value::Bag(_) => PartiqlShape::new(Static::Bag(BagType::new_any())),
345341
_ => {
346342
self.errors.push(TypingError::NotYetImplemented(
347343
"Unsupported Literal".to_string(),
@@ -416,8 +412,8 @@ impl<'c> PlanTyper<'c> {
416412
match ty {
417413
PartiqlShape::Dynamic => dynamic!(),
418414
PartiqlShape::Static(s) => match s.ty() {
419-
StaticTypeVariant::Bag(b) => b.element_type().clone(),
420-
StaticTypeVariant::Array(a) => a.element_type().clone(),
415+
Static::Bag(b) => b.element_type().clone(),
416+
Static::Array(a) => a.element_type().clone(),
421417
_ => ty.clone(),
422418
},
423419
undefined!() => {
@@ -885,7 +881,7 @@ mod tests {
885881
.expect_static()?;
886882

887883
match &actual.ty() {
888-
StaticTypeVariant::Bag(b) => {
884+
Static::Bag(b) => {
889885
if let Ok(s) = b.element_type().expect_struct() {
890886
let fields = s.fields();
891887

0 commit comments

Comments
 (0)