@@ -202,18 +202,13 @@ impl<'c> PlanTyper<'c> {
202
202
}
203
203
}
204
204
BindingsOp :: Project ( partiql_logical:: Project { exprs } ) => {
205
- let mut fields = vec ! [ ] ;
206
- for ( k, v) in exprs {
205
+ let fields = exprs. iter ( ) . map ( |( k, v) | {
207
206
self . type_vexpr ( v, LookupOrder :: LocalGlobal ) ;
208
-
209
- fields. push ( StructField :: new (
210
- k. as_str ( ) ,
211
- self . get_singleton_type_from_env ( ) ,
212
- ) ) ;
213
- }
207
+ StructField :: new ( k. as_str ( ) , self . get_singleton_type_from_env ( ) )
208
+ } ) ;
214
209
215
210
let ty = PartiqlType :: new_struct ( StructType :: new ( BTreeSet :: from ( [
216
- StructConstraint :: Fields ( fields) ,
211
+ StructConstraint :: Fields ( fields. collect ( ) ) ,
217
212
] ) ) ) ;
218
213
219
214
let derived_type_ctx = self . local_type_ctx ( ) ;
@@ -598,11 +593,12 @@ mod tests {
598
593
"SELECT customers.id, customers.name FROM customers" ,
599
594
create_customer_schema (
600
595
false ,
601
- vec ! [
596
+ [
602
597
StructField :: new ( "id" , int ! ( ) ) ,
603
598
StructField :: new ( "name" , str !( ) ) ,
604
599
StructField :: new ( "age" , any ! ( ) ) ,
605
- ] ,
600
+ ]
601
+ . into ( ) ,
606
602
) ,
607
603
vec ! [
608
604
StructField :: new( "id" , int!( ) ) ,
@@ -617,11 +613,12 @@ mod tests {
617
613
"SELECT id, customers.name FROM customers" ,
618
614
create_customer_schema (
619
615
false ,
620
- vec ! [
616
+ [
621
617
StructField :: new ( "id" , int ! ( ) ) ,
622
618
StructField :: new ( "name" , str !( ) ) ,
623
619
StructField :: new ( "age" , any ! ( ) ) ,
624
- ] ,
620
+ ]
621
+ . into ( ) ,
625
622
) ,
626
623
vec ! [
627
624
StructField :: new( "id" , int!( ) ) ,
@@ -636,11 +633,12 @@ mod tests {
636
633
"SELECT customers.id, customers.name, customers.age FROM customers" ,
637
634
create_customer_schema (
638
635
true ,
639
- vec ! [
636
+ [
640
637
StructField :: new ( "id" , int ! ( ) ) ,
641
638
StructField :: new ( "name" , str !( ) ) ,
642
639
StructField :: new ( "age" , any ! ( ) ) ,
643
- ] ,
640
+ ]
641
+ . into ( ) ,
644
642
) ,
645
643
vec ! [
646
644
StructField :: new( "id" , int!( ) ) ,
@@ -655,10 +653,11 @@ mod tests {
655
653
"SELECT customers.id, customers.name, customers.age FROM customers" ,
656
654
create_customer_schema (
657
655
false ,
658
- vec ! [
656
+ [
659
657
StructField :: new ( "id" , int ! ( ) ) ,
660
658
StructField :: new ( "name" , str !( ) ) ,
661
- ] ,
659
+ ]
660
+ . into ( ) ,
662
661
) ,
663
662
vec ! [
664
663
StructField :: new( "id" , int!( ) ) ,
@@ -677,11 +676,12 @@ mod tests {
677
676
"SELECT customers.id, customers.name, customers.details.age FROM customers" ,
678
677
create_customer_schema (
679
678
true ,
680
- vec ! [
679
+ [
681
680
StructField :: new ( "id" , int ! ( ) ) ,
682
681
StructField :: new ( "name" , str !( ) ) ,
683
682
StructField :: new ( "details" , details. clone ( ) ) ,
684
- ] ,
683
+ ]
684
+ . into ( ) ,
685
685
) ,
686
686
vec ! [
687
687
StructField :: new( "id" , int!( ) ) ,
@@ -695,19 +695,19 @@ mod tests {
695
695
assert_query_typing (
696
696
TypingMode :: Strict ,
697
697
"SELECT customers.id, customers.name, customers.details.age, customers.details.foo.bar FROM customers" ,
698
- create_customer_schema ( true , vec ! [
698
+ create_customer_schema ( true , [
699
699
StructField :: new ( "id" , int ! ( ) ) ,
700
700
StructField :: new ( "name" , str !( ) ) ,
701
701
StructField :: new ( "details" , details. clone ( ) ) ,
702
- ] ) ,
702
+ ] . into ( ) ) ,
703
703
vec ! [
704
704
StructField :: new( "id" , int!( ) ) ,
705
705
StructField :: new( "name" , str !( ) ) ,
706
706
StructField :: new( "age" , int!( ) ) ,
707
707
StructField :: new( "bar" , any!( ) ) ,
708
708
] ,
709
709
)
710
- . expect ( "Type" ) ;
710
+ . expect ( "Type" ) ;
711
711
}
712
712
713
713
#[ test]
@@ -723,11 +723,12 @@ mod tests {
723
723
"SELECT d.age FROM customers.details AS d" ,
724
724
create_customer_schema (
725
725
true ,
726
- vec ! [
726
+ [
727
727
StructField :: new ( "id" , int ! ( ) ) ,
728
728
StructField :: new ( "name" , str !( ) ) ,
729
729
StructField :: new ( "details" , details. clone ( ) ) ,
730
- ] ,
730
+ ]
731
+ . into ( ) ,
731
732
) ,
732
733
vec ! [ StructField :: new( "age" , int!( ) ) ] ,
733
734
)
@@ -739,11 +740,12 @@ mod tests {
739
740
"SELECT c.id AS my_id, customers.name AS my_name FROM customers AS c" ,
740
741
create_customer_schema (
741
742
false ,
742
- vec ! [
743
+ [
743
744
StructField :: new ( "id" , int ! ( ) ) ,
744
745
StructField :: new ( "name" , str !( ) ) ,
745
746
StructField :: new ( "age" , any ! ( ) ) ,
746
- ] ,
747
+ ]
748
+ . into ( ) ,
747
749
) ,
748
750
vec ! [
749
751
StructField :: new( "my_id" , int!( ) ) ,
@@ -756,18 +758,19 @@ mod tests {
756
758
#[ test]
757
759
fn simple_sfw_err ( ) {
758
760
// Closed Schema with `Strict` typing mode and `age` non-existent projection.
759
- let err1 = r#"No Typing Information for SymbolPrimitive { value: "age", case: CaseInsensitive } in closed Schema PartiqlType(Struct(StructType { constraints: {Open(false), Fields([ StructField { name: "id", ty: PartiqlType(Int) }, StructField { name: "name", ty: PartiqlType(String) }] )} }))"# ;
761
+ let err1 = r#"No Typing Information for SymbolPrimitive { value: "age", case: CaseInsensitive } in closed Schema PartiqlType(Struct(StructType { constraints: {Open(false), Fields({ StructField { name: "id", ty: PartiqlType(Int) }, StructField { name: "name", ty: PartiqlType(String) }} )} }))"# ;
760
762
761
763
assert_err (
762
764
assert_query_typing (
763
765
TypingMode :: Strict ,
764
766
"SELECT customers.id, customers.name, customers.age FROM customers" ,
765
767
create_customer_schema (
766
768
false ,
767
- vec ! [
769
+ [
768
770
StructField :: new ( "id" , int ! ( ) ) ,
769
771
StructField :: new ( "name" , str !( ) ) ,
770
- ] ,
772
+ ]
773
+ . into ( ) ,
771
774
) ,
772
775
vec ! [ ] ,
773
776
) ,
@@ -776,11 +779,12 @@ mod tests {
776
779
// TypingError::IllegalState(err2.to_string()),
777
780
] ,
778
781
Some ( bag ! [ r#struct![ BTreeSet :: from( [ StructConstraint :: Fields (
779
- vec! [
782
+ [
780
783
StructField :: new( "id" , int!( ) ) ,
781
784
StructField :: new( "name" , str !( ) ) ,
782
785
StructField :: new( "age" , undefined!( ) ) ,
783
786
]
787
+ . into( )
784
788
) , ] ) ] ] ) ,
785
789
) ;
786
790
@@ -791,7 +795,7 @@ mod tests {
791
795
StructConstraint :: Open ( false )
792
796
] ) ] ;
793
797
794
- let err1 = r#"No Typing Information for SymbolPrimitive { value: "details", case: CaseInsensitive } in closed Schema PartiqlType(Struct(StructType { constraints: {Open(false), Fields([ StructField { name: "age", ty: PartiqlType(Int) }] )} }))"# ;
798
+ let err1 = r#"No Typing Information for SymbolPrimitive { value: "details", case: CaseInsensitive } in closed Schema PartiqlType(Struct(StructType { constraints: {Open(false), Fields({ StructField { name: "age", ty: PartiqlType(Int) }} )} }))"# ;
795
799
let err2 = r"Illegal Derive Type PartiqlType(Undefined)" ;
796
800
797
801
assert_err (
@@ -800,11 +804,12 @@ mod tests {
800
804
"SELECT customers.id, customers.name, customers.details.bar FROM customers" ,
801
805
create_customer_schema (
802
806
false ,
803
- vec ! [
807
+ [
804
808
StructField :: new ( "id" , int ! ( ) ) ,
805
809
StructField :: new ( "name" , str !( ) ) ,
806
810
StructField :: new ( "details" , details) ,
807
- ] ,
811
+ ]
812
+ . into ( ) ,
808
813
) ,
809
814
vec ! [ ] ,
810
815
) ,
@@ -813,11 +818,12 @@ mod tests {
813
818
TypingError :: IllegalState ( err2. to_string( ) ) ,
814
819
] ,
815
820
Some ( bag ! [ r#struct![ BTreeSet :: from( [ StructConstraint :: Fields (
816
- vec! [
821
+ [
817
822
StructField :: new( "id" , int!( ) ) ,
818
823
StructField :: new( "name" , str !( ) ) ,
819
824
StructField :: new( "bar" , undefined!( ) ) ,
820
825
]
826
+ . into( )
821
827
) , ] ) ] ] ) ,
822
828
) ;
823
829
}
@@ -836,14 +842,14 @@ mod tests {
836
842
e,
837
843
TypeErr {
838
844
errors: expected_errors,
839
- output
845
+ output,
840
846
}
841
847
) ;
842
848
}
843
849
} ;
844
850
}
845
851
846
- fn create_customer_schema ( is_open : bool , fields : Vec < StructField > ) -> PartiqlType {
852
+ fn create_customer_schema ( is_open : bool , fields : BTreeSet < StructField > ) -> PartiqlType {
847
853
bag ! [ r#struct![ BTreeSet :: from( [
848
854
StructConstraint :: Fields ( fields) ,
849
855
StructConstraint :: Open ( is_open)
@@ -856,6 +862,7 @@ mod tests {
856
862
schema : PartiqlType ,
857
863
expected_fields : Vec < StructField > ,
858
864
) -> Result < ( ) , TypeErr > {
865
+ let expected_fields: BTreeSet < _ > = expected_fields. into_iter ( ) . collect ( ) ;
859
866
let actual = type_query ( mode, query, TypeEnvEntry :: new ( "customers" , & [ ] , schema) ) ;
860
867
861
868
match actual {
0 commit comments