Skip to content

Commit

Permalink
fix(bigquery): even more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Mar 5, 2024
1 parent 8c4400b commit d898f55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sqlglot/dialects/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,16 @@ def _parse_table_parts(
table.set("db", exp.Identifier(this=parts[0]))
table.set("this", exp.Identifier(this=parts[1]))

if isinstance(table.this, exp.Identifier) and "." in table.name:
if any("." in p.name for p in table.parts):
catalog, db, this, *rest = (
t.cast(t.Optional[exp.Expression], exp.to_identifier(x, quoted=True))
for x in split_num_words(table.name, ".", 3)
exp.to_identifier(p, quoted=True)
for p in split_num_words(".".join(p.name for p in table.parts), ".", 3)
)

if rest and this:
this = exp.Dot.build(t.cast(t.List[exp.Expression], [this, *rest]))
this = exp.Dot.build([this, *rest]) # type: ignore

table = exp.Table(this=this, db=db, catalog=catalog or table.args.get("db"))
table = exp.Table(this=this, db=db, catalog=catalog)
table.meta["quoted_table"] = True

return table
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_bigquery(self):
self.assertEqual(table.name, "_y")

self.validate_identity("SELECT * FROM x-0.y")
self.assertEqual(exp.to_table("`a.b`.`c.d`", dialect="bigquery").sql(), '"a"."b"."c"."d"')
self.assertEqual(exp.to_table("`x`.`y.z`", dialect="bigquery").sql(), '"x"."y"."z"')
self.assertEqual(exp.to_table("`x.y.z`", dialect="bigquery").sql(), '"x"."y"."z"')
self.assertEqual(exp.to_table("`x.y.z`", dialect="bigquery").sql("bigquery"), "`x.y.z`")
Expand Down

0 comments on commit d898f55

Please sign in to comment.