Skip to content

Commit

Permalink
Fix: array<unknown>
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Aug 22, 2023
1 parent 075849f commit e474aa0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
24 changes: 9 additions & 15 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3532,11 +3532,6 @@ class Type(AutoName):
Type.DATETIME64,
}

META_TYPES = {
"UNKNOWN",
"NULL",
}

@classmethod
def build(
cls,
Expand All @@ -3561,16 +3556,15 @@ def build(
from sqlglot import parse_one

if isinstance(dtype, str):
upper = dtype.upper()
if upper in DataType.META_TYPES:
data_type_exp = DataType(this=DataType.Type[upper])
else:
try:
data_type_exp = parse_one(dtype, read=dialect, into=DataType)
except ParseError:
if udt:
return DataType(this=DataType.Type.USERDEFINED, kind=dtype, **kwargs)
raise
if dtype.upper() == "UNKNOWN":
return DataType(this=DataType.Type.UNKNOWN, **kwargs)

try:
data_type_exp = parse_one(dtype, read=dialect, into=DataType)
except ParseError:
if udt:
return DataType(this=DataType.Type.USERDEFINED, kind=dtype, **kwargs)
raise
elif isinstance(dtype, DataType.Type):
data_type_exp = DataType(this=dtype)
elif isinstance(dtype, DataType):
Expand Down
2 changes: 2 additions & 0 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class Parser(metaclass=_Parser):
TokenType.INET,
TokenType.IPADDRESS,
TokenType.IPPREFIX,
TokenType.UNKNOWN,
TokenType.NULL,
*ENUM_TYPE_TOKENS,
*NESTED_TYPE_TOKENS,
}
Expand Down
2 changes: 2 additions & 0 deletions sqlglot/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class TokenType(AutoName):
FIXEDSTRING = auto()
LOWCARDINALITY = auto()
NESTED = auto()
UNKNOWN = auto()

# keywords
ALIAS = auto()
Expand Down Expand Up @@ -644,6 +645,7 @@ class Tokenizer(metaclass=_Tokenizer):
"THEN": TokenType.THEN,
"TRUE": TokenType.TRUE,
"UNION": TokenType.UNION,
"UNKNOWN": TokenType.UNKNOWN,
"UNNEST": TokenType.UNNEST,
"UNPIVOT": TokenType.UNPIVOT,
"UPDATE": TokenType.UPDATE,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@ def test_data_type_builder(self):
)
self.assertEqual(exp.DataType.build("USER-DEFINED").sql(), "USER-DEFINED")

self.assertEqual(exp.DataType.build("ARRAY<UNKNOWN>").sql(), "ARRAY<UNKNOWN>")
self.assertEqual(exp.DataType.build("ARRAY<NULL>").sql(), "ARRAY<NULL>")

def test_rename_table(self):
self.assertEqual(
exp.rename_table("t1", "t2").sql(),
Expand Down

0 comments on commit e474aa0

Please sign in to comment.