File tree Expand file tree Collapse file tree 4 files changed +21
-0
lines changed
Expand file tree Collapse file tree 4 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ class Databricks(Spark):
2727 class JSONPathTokenizer (jsonpath .JSONPathTokenizer ):
2828 IDENTIFIERS = ["`" , '"' ]
2929
30+ class Tokenizer (Spark .Tokenizer ):
31+ KEYWORDS = {
32+ ** Spark .Tokenizer .KEYWORDS ,
33+ "VOID" : TokenType .VOID ,
34+ }
35+
3036 class Parser (Spark .Parser ):
3137 LOG_DEFAULTS_TO_LN = True
3238 STRICT_CAST = True
@@ -83,6 +89,11 @@ class Generator(Spark.Generator):
8389
8490 TRANSFORMS .pop (exp .TryCast )
8591
92+ TYPE_MAPPING = {
93+ ** Spark .Generator .TYPE_MAPPING ,
94+ exp .DataType .Type .NULL : "VOID" ,
95+ }
96+
8697 def columndef_sql (self , expression : exp .ColumnDef , sep : str = " " ) -> str :
8798 constraint = expression .find (exp .GeneratedAsIdentityColumnConstraint )
8899 kind = expression .kind
Original file line number Diff line number Diff line change @@ -397,6 +397,7 @@ class Parser(metaclass=_Parser):
397397 TokenType .IMAGE ,
398398 TokenType .VARIANT ,
399399 TokenType .VECTOR ,
400+ TokenType .VOID ,
400401 TokenType .OBJECT ,
401402 TokenType .OBJECT_IDENTIFIER ,
402403 TokenType .INET ,
@@ -5238,6 +5239,8 @@ def _parse_types(
52385239 this = self .expression (exp .DataType , this = self .expression (exp .Interval , unit = unit ))
52395240 else :
52405241 this = self .expression (exp .DataType , this = exp .DataType .Type .INTERVAL )
5242+ elif type_token == TokenType .VOID :
5243+ this = exp .DataType (this = exp .DataType .Type .NULL )
52415244
52425245 if maybe_func and check_func :
52435246 index2 = self ._index
Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ class TokenType(AutoName):
222222 UNKNOWN = auto ()
223223 VECTOR = auto ()
224224 DYNAMIC = auto ()
225+ VOID = auto ()
225226
226227 # keywords
227228 ALIAS = auto ()
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ class TestDatabricks(Validator):
77 dialect = "databricks"
88
99 def test_databricks (self ):
10+ null_type = exp .DataType .build ("VOID" , dialect = "databricks" )
11+ self .assertEqual (null_type .sql (), "NULL" )
12+ self .assertEqual (null_type .sql ("databricks" ), "VOID" )
13+
14+ self .validate_identity ("SELECT CAST(NULL AS VOID)" )
15+ self .validate_identity ("SELECT void FROM t" )
1016 self .validate_identity ("SELECT * FROM stream" )
1117 self .validate_identity ("SELECT t.current_time FROM t" )
1218 self .validate_identity ("ALTER TABLE labels ADD COLUMN label_score FLOAT" )
You can’t perform that action at this time.
0 commit comments