@@ -4,15 +4,15 @@ use partiql_ast::ast::{
44} ;
55use partiql_ast:: visit:: { Traverse , Visit , Visitor } ;
66use partiql_catalog:: Catalog ;
7- use partiql_types:: { ArrayType , BagType , StaticType , StaticTypeKind , StructType } ;
7+ use partiql_types:: { ArrayType , BagType , PartiqlType , StructType , TypeKind } ;
88
99#[ derive( Debug , Clone ) ]
1010#[ allow( dead_code) ]
1111pub struct AstStaticTyper < ' c > {
1212 id_stack : Vec < NodeId > ,
13- container_stack : Vec < Vec < StaticType > > ,
13+ container_stack : Vec < Vec < PartiqlType > > ,
1414 errors : Vec < AstTransformError > ,
15- type_map : AstTypeMap < StaticType > ,
15+ type_map : AstTypeMap < PartiqlType > ,
1616 catalog : & ' c dyn Catalog ,
1717}
1818
@@ -30,7 +30,7 @@ impl<'c> AstStaticTyper<'c> {
3030 pub fn type_nodes (
3131 mut self ,
3232 query : & AstNode < Query > ,
33- ) -> Result < AstTypeMap < StaticType > , AstTransformationError > {
33+ ) -> Result < AstTypeMap < PartiqlType > , AstTransformationError > {
3434 query. visit ( & mut self ) ;
3535 if self . errors . is_empty ( ) {
3636 Ok ( self . type_map )
@@ -99,30 +99,30 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
9999 // Currently we're assuming no-schema, hence typing to arbitrary sized scalars.
100100 // TODO type to the corresponding scalar with the introduction of schema
101101 let kind = match _lit {
102- Lit :: Null => StaticTypeKind :: Null ,
103- Lit :: Missing => StaticTypeKind :: Missing ,
104- Lit :: Int8Lit ( _) => StaticTypeKind :: Int ,
105- Lit :: Int16Lit ( _) => StaticTypeKind :: Int ,
106- Lit :: Int32Lit ( _) => StaticTypeKind :: Int ,
107- Lit :: Int64Lit ( _) => StaticTypeKind :: Int ,
108- Lit :: DecimalLit ( _) => StaticTypeKind :: Decimal ,
109- Lit :: NumericLit ( _) => StaticTypeKind :: Decimal ,
110- Lit :: RealLit ( _) => StaticTypeKind :: Float64 ,
111- Lit :: FloatLit ( _) => StaticTypeKind :: Float64 ,
112- Lit :: DoubleLit ( _) => StaticTypeKind :: Float64 ,
113- Lit :: BoolLit ( _) => StaticTypeKind :: Bool ,
102+ Lit :: Null => TypeKind :: Null ,
103+ Lit :: Missing => TypeKind :: Missing ,
104+ Lit :: Int8Lit ( _) => TypeKind :: Int ,
105+ Lit :: Int16Lit ( _) => TypeKind :: Int ,
106+ Lit :: Int32Lit ( _) => TypeKind :: Int ,
107+ Lit :: Int64Lit ( _) => TypeKind :: Int ,
108+ Lit :: DecimalLit ( _) => TypeKind :: Decimal ,
109+ Lit :: NumericLit ( _) => TypeKind :: Decimal ,
110+ Lit :: RealLit ( _) => TypeKind :: Float64 ,
111+ Lit :: FloatLit ( _) => TypeKind :: Float64 ,
112+ Lit :: DoubleLit ( _) => TypeKind :: Float64 ,
113+ Lit :: BoolLit ( _) => TypeKind :: Bool ,
114114 Lit :: IonStringLit ( _) => todo ! ( ) ,
115- Lit :: CharStringLit ( _) => StaticTypeKind :: String ,
116- Lit :: NationalCharStringLit ( _) => StaticTypeKind :: String ,
115+ Lit :: CharStringLit ( _) => TypeKind :: String ,
116+ Lit :: NationalCharStringLit ( _) => TypeKind :: String ,
117117 Lit :: BitStringLit ( _) => todo ! ( ) ,
118118 Lit :: HexStringLit ( _) => todo ! ( ) ,
119- Lit :: StructLit ( _) => StaticTypeKind :: Struct ( StructType :: unconstrained ( ) ) ,
120- Lit :: ListLit ( _) => StaticTypeKind :: Array ( ArrayType :: array ( ) ) ,
121- Lit :: BagLit ( _) => StaticTypeKind :: Bag ( BagType :: bag ( ) ) ,
119+ Lit :: StructLit ( _) => TypeKind :: Struct ( StructType :: unconstrained ( ) ) ,
120+ Lit :: ListLit ( _) => TypeKind :: Array ( ArrayType :: array ( ) ) ,
121+ Lit :: BagLit ( _) => TypeKind :: Bag ( BagType :: bag ( ) ) ,
122122 Lit :: TypedLit ( _, _) => todo ! ( ) ,
123123 } ;
124124
125- let ty = StaticType :: new ( kind) ;
125+ let ty = PartiqlType :: new ( kind) ;
126126 let id = * self . current_node ( ) ;
127127 if let Some ( c) = self . container_stack . last_mut ( ) {
128128 c. push ( ty. clone ( ) )
@@ -161,7 +161,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
161161 }
162162 }
163163
164- let ty = StaticType :: new_struct ( StructType :: unconstrained ( ) ) ;
164+ let ty = PartiqlType :: new_struct ( StructType :: unconstrained ( ) ) ;
165165 self . type_map . insert ( id, ty. clone ( ) ) ;
166166
167167 if let Some ( c) = self . container_stack . last_mut ( ) {
@@ -184,7 +184,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
184184 self . container_stack . pop ( ) ;
185185
186186 let id = * self . current_node ( ) ;
187- let ty = StaticType :: new_bag ( BagType :: bag ( ) ) ;
187+ let ty = PartiqlType :: new_bag ( BagType :: bag ( ) ) ;
188188
189189 self . type_map . insert ( id, ty. clone ( ) ) ;
190190 if let Some ( s) = self . container_stack . last_mut ( ) {
@@ -206,7 +206,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
206206 self . container_stack . pop ( ) ;
207207
208208 let id = * self . current_node ( ) ;
209- let ty = StaticType :: new_array ( ArrayType :: array ( ) ) ;
209+ let ty = PartiqlType :: new_array ( ArrayType :: array ( ) ) ;
210210
211211 self . type_map . insert ( id, ty. clone ( ) ) ;
212212 if let Some ( s) = self . container_stack . last_mut ( ) {
@@ -222,29 +222,23 @@ mod tests {
222222 use assert_matches:: assert_matches;
223223 use partiql_ast:: ast;
224224 use partiql_catalog:: PartiqlCatalog ;
225- use partiql_types:: { StaticType , StaticTypeKind } ;
225+ use partiql_types:: { PartiqlType , TypeKind } ;
226226
227227 #[ test]
228228 fn simple_test ( ) {
229- assert_matches ! ( run_literal_test( "NULL" ) , StaticTypeKind :: Null ) ;
230- assert_matches ! ( run_literal_test( "MISSING" ) , StaticTypeKind :: Missing ) ;
231- assert_matches ! ( run_literal_test( "Missing" ) , StaticTypeKind :: Missing ) ;
232- assert_matches ! ( run_literal_test( "true" ) , StaticTypeKind :: Bool ) ;
233- assert_matches ! ( run_literal_test( "false" ) , StaticTypeKind :: Bool ) ;
234- assert_matches ! ( run_literal_test( "1" ) , StaticTypeKind :: Int ) ;
235- assert_matches ! ( run_literal_test( "1.5" ) , StaticTypeKind :: Decimal ) ;
236- assert_matches ! ( run_literal_test( "'hello world!'" ) , StaticTypeKind :: String ) ;
237- assert_matches ! (
238- run_literal_test( "[1, 2 , {'a': 2}]" ) ,
239- StaticTypeKind :: Array ( _)
240- ) ;
241- assert_matches ! (
242- run_literal_test( "<<'1', {'a': 11}>>" ) ,
243- StaticTypeKind :: Bag ( _)
244- ) ;
229+ assert_matches ! ( run_literal_test( "NULL" ) , TypeKind :: Null ) ;
230+ assert_matches ! ( run_literal_test( "MISSING" ) , TypeKind :: Missing ) ;
231+ assert_matches ! ( run_literal_test( "Missing" ) , TypeKind :: Missing ) ;
232+ assert_matches ! ( run_literal_test( "true" ) , TypeKind :: Bool ) ;
233+ assert_matches ! ( run_literal_test( "false" ) , TypeKind :: Bool ) ;
234+ assert_matches ! ( run_literal_test( "1" ) , TypeKind :: Int ) ;
235+ assert_matches ! ( run_literal_test( "1.5" ) , TypeKind :: Decimal ) ;
236+ assert_matches ! ( run_literal_test( "'hello world!'" ) , TypeKind :: String ) ;
237+ assert_matches ! ( run_literal_test( "[1, 2 , {'a': 2}]" ) , TypeKind :: Array ( _) ) ;
238+ assert_matches ! ( run_literal_test( "<<'1', {'a': 11}>>" ) , TypeKind :: Bag ( _) ) ;
245239 assert_matches ! (
246240 run_literal_test( "{'a': 1, 'b': 3, 'c': [1, 2]}" ) ,
247- StaticTypeKind :: Struct ( _)
241+ TypeKind :: Struct ( _)
248242 ) ;
249243 }
250244
@@ -253,13 +247,13 @@ mod tests {
253247 assert ! ( type_statement( "{'a': 1, a.b: 3}" ) . is_err( ) ) ;
254248 }
255249
256- fn run_literal_test ( q : & str ) -> StaticTypeKind {
250+ fn run_literal_test ( q : & str ) -> TypeKind {
257251 let out = type_statement ( q) . expect ( "type map" ) ;
258- let values: Vec < & StaticType > = out. values ( ) . collect ( ) ;
252+ let values: Vec < & PartiqlType > = out. values ( ) . collect ( ) ;
259253 values. last ( ) . unwrap ( ) . kind ( ) . clone ( )
260254 }
261255
262- fn type_statement ( q : & str ) -> Result < AstTypeMap < StaticType > , AstTransformationError > {
256+ fn type_statement ( q : & str ) -> Result < AstTypeMap < PartiqlType > , AstTransformationError > {
263257 let parsed = partiql_parser:: Parser :: default ( )
264258 . parse ( q)
265259 . expect ( "Expect successful parse" ) ;
0 commit comments