Skip to content

Commit c1c892c

Browse files
authored
Fix(parser): parse column ops after no-paren type casting (#5025)
1 parent f5358d8 commit c1c892c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

sqlglot/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5041,6 +5041,8 @@ def _parse_type(
50415041
this = self._parse_primary()
50425042

50435043
if isinstance(this, exp.Literal):
5044+
this = self._parse_column_ops(this)
5045+
50445046
parser = self.TYPE_LITERAL_PARSERS.get(data_type.this)
50455047
if parser:
50465048
return parser(self, this, data_type)

tests/dialects/test_databricks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_databricks(self):
3535
self.validate_identity("SELECT ${x} FROM ${y} WHERE ${z} > 1")
3636
self.validate_identity("CREATE TABLE foo (x DATE GENERATED ALWAYS AS (CAST(y AS DATE)))")
3737
self.validate_identity("TRUNCATE TABLE t1 PARTITION(age = 10, name = 'test', address)")
38+
self.validate_identity("SELECT PARSE_JSON('{}')")
3839
self.validate_identity(
3940
"CREATE TABLE IF NOT EXISTS db.table (a TIMESTAMP, b BOOLEAN GENERATED ALWAYS AS (NOT a IS NULL)) USING DELTA"
4041
)
@@ -56,7 +57,10 @@ def test_databricks(self):
5657
self.validate_identity(
5758
"COPY INTO target FROM `s3://link` FILEFORMAT = AVRO VALIDATE = ALL FILES = ('file1', 'file2') FORMAT_OPTIONS ('opt1'='true', 'opt2'='test') COPY_OPTIONS ('mergeSchema'='true')"
5859
)
59-
self.validate_identity("SELECT PARSE_JSON('{}')")
60+
self.validate_identity(
61+
"SELECT TIMESTAMP '2025-04-29 18.47.18'::DATE",
62+
"SELECT CAST(CAST('2025-04-29 18.47.18' AS DATE) AS TIMESTAMP)",
63+
)
6064
self.validate_identity(
6165
"SELECT DATE_FORMAT(CAST(FROM_UTC_TIMESTAMP(foo, 'America/Los_Angeles') AS TIMESTAMP), 'yyyy-MM-dd HH:mm:ss') AS foo FROM t",
6266
"SELECT DATE_FORMAT(CAST(FROM_UTC_TIMESTAMP(CAST(foo AS TIMESTAMP), 'America/Los_Angeles') AS TIMESTAMP), 'yyyy-MM-dd HH:mm:ss') AS foo FROM t",

0 commit comments

Comments
 (0)