Skip to content

Commit

Permalink
Feat: reparse bigquery nested identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed May 14, 2023
1 parent 2f7473b commit a973113
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sqlglot/dialects/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ class Parser(parser.Parser):
"OPTIONS": lambda self: exp.Properties(expressions=self._parse_with_property()),
}

def _parse_table_parts(self, schema: bool = False) -> exp.Expression:
table = super()._parse_table_parts(schema=schema)
if isinstance(table.this, exp.Identifier) and "." in table.name:
table = exp.to_table(table.name, dialect="bigquery")
return table

class Generator(generator.Generator):
EXPLICIT_UNION = True
INTERVAL_ALLOWS_PLURAL_FORM = False
Expand Down
4 changes: 4 additions & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def test_bigquery(self):
"CREATE TEMP TABLE foo AS SELECT 1",
write={"bigquery": "CREATE TEMPORARY TABLE foo AS SELECT 1"},
)
self.validate_all(
"SELECT * FROM `my-project.my-dataset.my-table`",
write={"bigquery": "SELECT * FROM `my-project`.`my-dataset`.`my-table`"},
)
self.validate_all("LEAST(x, y)", read={"sqlite": "MIN(x, y)"})
self.validate_all("CAST(x AS CHAR)", write={"bigquery": "CAST(x AS STRING)"})
self.validate_all("CAST(x AS NCHAR)", write={"bigquery": "CAST(x AS STRING)"})
Expand Down

0 comments on commit a973113

Please sign in to comment.