Skip to content

Commit

Permalink
Fix!: bigquery udfs are case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 28, 2023
1 parent e3c43f2 commit d72caf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions sqlglot/dialects/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class BigQuery(Dialect):
# https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#case_sensitivity
RESOLVES_IDENTIFIERS_AS_UPPERCASE = None

# bigquery udfs are case sensitive
NORMALIZE_FUNCTIONS = False

TIME_MAPPING = {
"%D": "%m/%d/%y",
}
Expand All @@ -135,13 +138,15 @@ def normalize_identifier(cls, expression: E) -> E:
# In BigQuery, CTEs aren't case-sensitive, but table names are (by default, at least).
# The following check is essentially a heuristic to detect tables based on whether or
# not they're qualified.
if isinstance(expression, exp.Identifier) and not expression.meta.get("is_table"):
if isinstance(expression, exp.Identifier):
parent = expression.parent

while isinstance(parent, exp.Dot):
parent = parent.parent

if not (isinstance(parent, exp.Table) and parent.db):
if not (isinstance(parent, exp.Table) and parent.db) and not expression.meta.get(
"is_table"
):
expression.set("this", expression.this.lower())

return expression
Expand Down
2 changes: 1 addition & 1 deletion tests/dialects/test_redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_redshift(self):
"SELECT ST_AsEWKT(ST_GeomFromEWKT('SRID=4326;POINT(10 20)')::geography)",
write={
"redshift": "SELECT ST_ASEWKT(CAST(ST_GEOMFROMEWKT('SRID=4326;POINT(10 20)') AS GEOGRAPHY))",
"bigquery": "SELECT ST_ASEWKT(SAFE_CAST(ST_GEOMFROMEWKT('SRID=4326;POINT(10 20)') AS GEOGRAPHY))",
"bigquery": "SELECT ST_AsEWKT(SAFE_CAST(ST_GeomFromEWKT('SRID=4326;POINT(10 20)') AS GEOGRAPHY))",
},
)
self.validate_all(
Expand Down

0 comments on commit d72caf4

Please sign in to comment.