@@ -4,15 +4,15 @@ use partiql_ast::ast::{
4
4
} ;
5
5
use partiql_ast:: visit:: { Traverse , Visit , Visitor } ;
6
6
use partiql_catalog:: Catalog ;
7
- use partiql_types:: { ArrayType , BagType , StaticType , StaticTypeKind , StructType } ;
7
+ use partiql_types:: { ArrayType , BagType , PartiqlType , StructType , TypeKind } ;
8
8
9
9
#[ derive( Debug , Clone ) ]
10
10
#[ allow( dead_code) ]
11
11
pub struct AstStaticTyper < ' c > {
12
12
id_stack : Vec < NodeId > ,
13
- container_stack : Vec < Vec < StaticType > > ,
13
+ container_stack : Vec < Vec < PartiqlType > > ,
14
14
errors : Vec < AstTransformError > ,
15
- type_map : AstTypeMap < StaticType > ,
15
+ type_map : AstTypeMap < PartiqlType > ,
16
16
catalog : & ' c dyn Catalog ,
17
17
}
18
18
@@ -30,7 +30,7 @@ impl<'c> AstStaticTyper<'c> {
30
30
pub fn type_nodes (
31
31
mut self ,
32
32
query : & AstNode < Query > ,
33
- ) -> Result < AstTypeMap < StaticType > , AstTransformationError > {
33
+ ) -> Result < AstTypeMap < PartiqlType > , AstTransformationError > {
34
34
query. visit ( & mut self ) ;
35
35
if self . errors . is_empty ( ) {
36
36
Ok ( self . type_map )
@@ -99,30 +99,30 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
99
99
// Currently we're assuming no-schema, hence typing to arbitrary sized scalars.
100
100
// TODO type to the corresponding scalar with the introduction of schema
101
101
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 ,
114
114
Lit :: IonStringLit ( _) => todo ! ( ) ,
115
- Lit :: CharStringLit ( _) => StaticTypeKind :: String ,
116
- Lit :: NationalCharStringLit ( _) => StaticTypeKind :: String ,
115
+ Lit :: CharStringLit ( _) => TypeKind :: String ,
116
+ Lit :: NationalCharStringLit ( _) => TypeKind :: String ,
117
117
Lit :: BitStringLit ( _) => todo ! ( ) ,
118
118
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 ( ) ) ,
122
122
Lit :: TypedLit ( _, _) => todo ! ( ) ,
123
123
} ;
124
124
125
- let ty = StaticType :: new ( kind) ;
125
+ let ty = PartiqlType :: new ( kind) ;
126
126
let id = * self . current_node ( ) ;
127
127
if let Some ( c) = self . container_stack . last_mut ( ) {
128
128
c. push ( ty. clone ( ) )
@@ -161,7 +161,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
161
161
}
162
162
}
163
163
164
- let ty = StaticType :: new_struct ( StructType :: unconstrained ( ) ) ;
164
+ let ty = PartiqlType :: new_struct ( StructType :: unconstrained ( ) ) ;
165
165
self . type_map . insert ( id, ty. clone ( ) ) ;
166
166
167
167
if let Some ( c) = self . container_stack . last_mut ( ) {
@@ -184,7 +184,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
184
184
self . container_stack . pop ( ) ;
185
185
186
186
let id = * self . current_node ( ) ;
187
- let ty = StaticType :: new_bag ( BagType :: bag ( ) ) ;
187
+ let ty = PartiqlType :: new_bag ( BagType :: bag ( ) ) ;
188
188
189
189
self . type_map . insert ( id, ty. clone ( ) ) ;
190
190
if let Some ( s) = self . container_stack . last_mut ( ) {
@@ -206,7 +206,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
206
206
self . container_stack . pop ( ) ;
207
207
208
208
let id = * self . current_node ( ) ;
209
- let ty = StaticType :: new_array ( ArrayType :: array ( ) ) ;
209
+ let ty = PartiqlType :: new_array ( ArrayType :: array ( ) ) ;
210
210
211
211
self . type_map . insert ( id, ty. clone ( ) ) ;
212
212
if let Some ( s) = self . container_stack . last_mut ( ) {
@@ -222,29 +222,23 @@ mod tests {
222
222
use assert_matches:: assert_matches;
223
223
use partiql_ast:: ast;
224
224
use partiql_catalog:: PartiqlCatalog ;
225
- use partiql_types:: { StaticType , StaticTypeKind } ;
225
+ use partiql_types:: { PartiqlType , TypeKind } ;
226
226
227
227
#[ test]
228
228
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 ( _) ) ;
245
239
assert_matches ! (
246
240
run_literal_test( "{'a': 1, 'b': 3, 'c': [1, 2]}" ) ,
247
- StaticTypeKind :: Struct ( _)
241
+ TypeKind :: Struct ( _)
248
242
) ;
249
243
}
250
244
@@ -253,13 +247,13 @@ mod tests {
253
247
assert ! ( type_statement( "{'a': 1, a.b: 3}" ) . is_err( ) ) ;
254
248
}
255
249
256
- fn run_literal_test ( q : & str ) -> StaticTypeKind {
250
+ fn run_literal_test ( q : & str ) -> TypeKind {
257
251
let out = type_statement ( q) . expect ( "type map" ) ;
258
- let values: Vec < & StaticType > = out. values ( ) . collect ( ) ;
252
+ let values: Vec < & PartiqlType > = out. values ( ) . collect ( ) ;
259
253
values. last ( ) . unwrap ( ) . kind ( ) . clone ( )
260
254
}
261
255
262
- fn type_statement ( q : & str ) -> Result < AstTypeMap < StaticType > , AstTransformationError > {
256
+ fn type_statement ( q : & str ) -> Result < AstTypeMap < PartiqlType > , AstTransformationError > {
263
257
let parsed = partiql_parser:: Parser :: default ( )
264
258
. parse ( q)
265
259
. expect ( "Expect successful parse" ) ;
0 commit comments