Skip to content

Commit

Permalink
Feat struct field optionality (#465)
Browse files Browse the repository at this point in the history
Add Struct Field Optionality
  • Loading branch information
am357 authored Jun 19, 2024
1 parent ee13dee commit d491cb0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions partiql-logical-planner/src/typer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ mod tests {
#[test]
fn simple_sfw_err() {
// Closed Schema with `Strict` typing mode and `age` non-existent projection.
let err1 = r#"No Typing Information for SymbolPrimitive { value: "age", case: CaseInsensitive } in closed Schema Static(StaticType { ty: Struct(StructType { constraints: {Open(false), Fields({StructField { name: "id", ty: Static(StaticType { ty: Int, nullable: true }) }, StructField { name: "name", ty: Static(StaticType { ty: String, nullable: true }) }})} }), nullable: true })"#;
let err1 = r#"No Typing Information for SymbolPrimitive { value: "age", case: CaseInsensitive } in closed Schema Static(StaticType { ty: Struct(StructType { constraints: {Open(false), Fields({StructField { optional: false, name: "id", ty: Static(StaticType { ty: Int, nullable: true }) }, StructField { optional: false, name: "name", ty: Static(StaticType { ty: String, nullable: true }) }})} }), nullable: true })"#;

assert_err(
assert_query_typing(
Expand Down Expand Up @@ -813,7 +813,7 @@ mod tests {
StructConstraint::Open(false)
])];

let err1 = r#"No Typing Information for SymbolPrimitive { value: "details", case: CaseInsensitive } in closed Schema Static(StaticType { ty: Struct(StructType { constraints: {Open(false), Fields({StructField { name: "age", ty: Static(StaticType { ty: Int, nullable: true }) }})} }), nullable: true })"#;
let err1 = r#"No Typing Information for SymbolPrimitive { value: "details", case: CaseInsensitive } in closed Schema Static(StaticType { ty: Struct(StructType { constraints: {Open(false), Fields({StructField { optional: false, name: "age", ty: Static(StaticType { ty: Int, nullable: true }) }})} }), nullable: true })"#;
let err2 = r"Illegal Derive Type Undefined";

assert_err(
Expand Down
27 changes: 27 additions & 0 deletions partiql-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ pub enum StructConstraint {
#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
#[allow(dead_code)]
pub struct StructField {
optional: bool,
name: String,
ty: PartiqlShape,
}
Expand All @@ -582,6 +583,16 @@ impl StructField {
StructField {
name: name.to_string(),
ty,
optional: false,
}
}

#[must_use]
pub fn new_optional(name: &str, ty: PartiqlShape) -> Self {
StructField {
name: name.to_string(),
ty,
optional: true,
}
}

Expand All @@ -594,13 +605,29 @@ impl StructField {
pub fn ty(&self) -> &PartiqlShape {
&self.ty
}

#[must_use]
pub fn is_optional(&self) -> &bool {
&self.optional
}
}

impl From<(&str, PartiqlShape)> for StructField {
fn from(value: (&str, PartiqlShape)) -> Self {
StructField {
name: value.0.to_string(),
ty: value.1,
optional: false,
}
}
}

impl From<(&str, PartiqlShape, bool)> for StructField {
fn from(value: (&str, PartiqlShape, bool)) -> Self {
StructField {
name: value.0.to_string(),
ty: value.1,
optional: value.2,
}
}
}
Expand Down

1 comment on commit d491cb0

@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: d491cb0 Previous: ee13dee Ratio
arith_agg-avg 771884 ns/iter (± 7796) 767717 ns/iter (± 11268) 1.01
arith_agg-avg_distinct 860865 ns/iter (± 3796) 851108 ns/iter (± 1835) 1.01
arith_agg-count 821507 ns/iter (± 17852) 813150 ns/iter (± 19464) 1.01
arith_agg-count_distinct 852909 ns/iter (± 2499) 843925 ns/iter (± 32715) 1.01
arith_agg-min 823532 ns/iter (± 18618) 817304 ns/iter (± 7430) 1.01
arith_agg-min_distinct 855922 ns/iter (± 2930) 846594 ns/iter (± 2351) 1.01
arith_agg-max 830631 ns/iter (± 2718) 826997 ns/iter (± 4265) 1.00
arith_agg-max_distinct 864029 ns/iter (± 8166) 858037 ns/iter (± 4935) 1.01
arith_agg-sum 825295 ns/iter (± 4211) 814499 ns/iter (± 2444) 1.01
arith_agg-sum_distinct 859280 ns/iter (± 2580) 848180 ns/iter (± 2724) 1.01
arith_agg-avg-count-min-max-sum 969580 ns/iter (± 5511) 956398 ns/iter (± 2582) 1.01
arith_agg-avg-count-min-max-sum-group_by 1270155 ns/iter (± 34240) 1235065 ns/iter (± 18090) 1.03
arith_agg-avg-count-min-max-sum-group_by-group_as 1851931 ns/iter (± 9176) 1869138 ns/iter (± 19298) 0.99
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct 1236749 ns/iter (± 18604) 1181105 ns/iter (± 9480) 1.05
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by 1558383 ns/iter (± 13185) 1527971 ns/iter (± 8624) 1.02
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as 2164143 ns/iter (± 13939) 2155595 ns/iter (± 9589) 1.00
parse-1 4257 ns/iter (± 29) 4146 ns/iter (± 24) 1.03
parse-15 38864 ns/iter (± 217) 37762 ns/iter (± 118) 1.03
parse-30 77167 ns/iter (± 392) 74801 ns/iter (± 225) 1.03
compile-1 4301 ns/iter (± 19) 4347 ns/iter (± 50) 0.99
compile-15 32700 ns/iter (± 246) 33151 ns/iter (± 182) 0.99
compile-30 66472 ns/iter (± 846) 67895 ns/iter (± 278) 0.98
plan-1 68040 ns/iter (± 207) 67680 ns/iter (± 766) 1.01
plan-15 1063654 ns/iter (± 23963) 1047469 ns/iter (± 8010) 1.02
plan-30 2126582 ns/iter (± 5275) 2100142 ns/iter (± 9448) 1.01
eval-1 13948729 ns/iter (± 104574) 12798017 ns/iter (± 187554) 1.09
eval-15 89737833 ns/iter (± 1061584) 88444199 ns/iter (± 1061763) 1.01
eval-30 172140198 ns/iter (± 542000) 168749431 ns/iter (± 536572) 1.02
join 9959 ns/iter (± 27) 10111 ns/iter (± 38) 0.98
simple 2519 ns/iter (± 32) 2522 ns/iter (± 15) 1.00
simple-no 425 ns/iter (± 9) 437 ns/iter (± 1) 0.97
numbers 57 ns/iter (± 0) 57 ns/iter (± 0) 1
parse-simple 545 ns/iter (± 3) 571 ns/iter (± 33) 0.95
parse-ion 1707 ns/iter (± 5) 1764 ns/iter (± 7) 0.97
parse-group 5768 ns/iter (± 112) 5764 ns/iter (± 21) 1.00
parse-complex 14629 ns/iter (± 57) 14759 ns/iter (± 159) 0.99
parse-complex-fexpr 21622 ns/iter (± 133) 21149 ns/iter (± 92) 1.02

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

Please sign in to comment.