@@ -208,6 +208,8 @@ class TimeplusSqlglotDialect(Dialect):
208
208
exp .Union : None ,
209
209
}
210
210
211
+
212
+
211
213
class Tokenizer (tokens .Tokenizer ):
212
214
COMMENTS = ["--" , "#" , "#!" , ("/*" , "*/" )]
213
215
IDENTIFIERS = ['"' , "`" ]
@@ -226,11 +228,11 @@ class Tokenizer(tokens.Tokenizer):
226
228
"ENUM8" : TokenType .ENUM8 ,
227
229
"ENUM16" : TokenType .ENUM16 ,
228
230
"FINAL" : TokenType .FINAL ,
229
- "FIXEDSTRING " : TokenType .FIXEDSTRING ,
231
+ "FIXED_STRING " : TokenType .FIXEDSTRING ,
230
232
"FLOAT32" : TokenType .FLOAT ,
231
233
"FLOAT64" : TokenType .DOUBLE ,
232
234
"GLOBAL" : TokenType .GLOBAL ,
233
- "LOWCARDINALITY " : TokenType .LOWCARDINALITY ,
235
+ "LOW_CARDINALITY " : TokenType .LOWCARDINALITY ,
234
236
"MAP" : TokenType .MAP ,
235
237
"NESTED" : TokenType .NESTED ,
236
238
"SAMPLE" : TokenType .TABLE_SAMPLE ,
@@ -393,7 +395,7 @@ class Parser(parser.Parser):
393
395
394
396
AGG_FUNCTIONS_SUFFIXES = [
395
397
"if" ,
396
- "aary " ,
398
+ "array " ,
397
399
"array_if" ,
398
400
"map" ,
399
401
"simple_state" ,
@@ -524,9 +526,9 @@ def _parse_types(
524
526
if isinstance (dtype , exp .DataType ) and dtype .args .get ("nullable" ) is not True :
525
527
# Mark every type as non-nullable which is Timeplus's default, unless it's
526
528
# already marked as nullable. This marker helps us transpile types from other
527
- # dialects to Timeplus, so that we can e.g. produce `CAST(x AS nullabe (String))`
529
+ # dialects to Timeplus, so that we can e.g. produce `CAST(x AS nullable (String))`
528
530
# from `CAST(x AS TEXT)`. If there is a `NULL` value in `x`, the former would
529
- # fail in Timeplus without the `nullabe ` type constructor.
531
+ # fail in Timeplus without the `nullable ` type constructor.
530
532
dtype .set ("nullable" , False )
531
533
532
534
return dtype
@@ -563,7 +565,7 @@ def _parse_assignment(self) -> t.Optional[exp.Expression]:
563
565
564
566
def _parse_query_parameter (self ) -> t .Optional [exp .Expression ]:
565
567
"""
566
- Parse a placeholder expression like SELECT {abc: UInt32 } or FROM {table: Identifier}
568
+ Parse a placeholder expression like SELECT {abc: uint32 } or FROM {table: Identifier}
567
569
"""
568
570
index = self ._index
569
571
@@ -958,7 +960,7 @@ class Generator(generator.Generator):
958
960
exp .ArgMax : arg_max_or_min_no_count ("arg_max" ),
959
961
exp .ArgMin : arg_max_or_min_no_count ("arg_min" ),
960
962
exp .Array : inline_array_sql ,
961
- exp .CastToStrType : rename_func ("cast " ),
963
+ exp .CastToStrType : rename_func ("CAST " ),
962
964
exp .CountIf : rename_func ("count_if" ),
963
965
exp .CompressColumnConstraint : lambda self ,
964
966
e : f"CODEC({ self .expressions (e , key = 'this' , flat = True )} )" ,
@@ -1062,7 +1064,7 @@ def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) ->
1062
1064
def trycast_sql (self , expression : exp .TryCast ) -> str :
1063
1065
dtype = expression .to
1064
1066
if not dtype .is_type (* self .NON_NULLABLE_TYPES , check_nullable = True ):
1065
- # Casting x into nullabe (T) appears to behave similarly to TRY_CAST(x AS T)
1067
+ # Casting x into nullable (T) appears to behave similarly to TRY_CAST(x AS T)
1066
1068
dtype .set ("nullable" , True )
1067
1069
1068
1070
return super ().cast_sql (expression )
@@ -1110,13 +1112,13 @@ def datatype_sql(self, expression: exp.DataType) -> str:
1110
1112
else :
1111
1113
dtype = super ().datatype_sql (expression )
1112
1114
1113
- # This section changes the type to `nullabe (...)` if the following conditions hold:
1114
- # - It's marked as nullable - this ensures we won't wrap Timeplus types with `nullabe `
1115
+ # This section changes the type to `nullable (...)` if the following conditions hold:
1116
+ # - It's marked as nullable - this ensures we won't wrap Timeplus types with `nullable `
1115
1117
# and change their semantics
1116
1118
# - It's not the key type of a `Map`. This is because Timeplus enforces the following
1117
1119
# constraint: "Type of Map key must be a type, that can be represented by integer or
1118
1120
# String or FixedString (possibly LowCardinality) or UUID or IPv6"
1119
- # - It's not a composite type, e.g. `nullabe (array(...))` is not a valid type
1121
+ # - It's not a composite type, e.g. `nullable (array(...))` is not a valid type
1120
1122
parent = expression .parent
1121
1123
nullable = expression .args .get ("nullable" )
1122
1124
if nullable is True or (
@@ -1128,7 +1130,7 @@ def datatype_sql(self, expression: exp.DataType) -> str:
1128
1130
)
1129
1131
and not expression .is_type (* self .NON_NULLABLE_TYPES , check_nullable = True )
1130
1132
):
1131
- dtype = f"nullabe ({ dtype } )"
1133
+ dtype = f"nullable ({ dtype } )"
1132
1134
1133
1135
return dtype
1134
1136
@@ -1247,3 +1249,7 @@ def is_sql(self, expression: exp.Is) -> str:
1247
1249
is_sql = self .wrap (is_sql )
1248
1250
1249
1251
return is_sql
1252
+
1253
+ tokenizer_class = Tokenizer
1254
+ parser_class = Parser
1255
+ generator_class = Generator
0 commit comments