Skip to content

Commit

Permalink
Fix: don't normalize udf defs
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 30, 2023
1 parent 90463c5 commit 154ece5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sqlglot/dialects/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ def normalize_identifier(cls, expression: E) -> E:
while isinstance(parent, exp.Dot):
parent = parent.parent

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

Expand Down
11 changes: 11 additions & 0 deletions tests/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ def test_qualify_columns(self):
'WITH "x" AS (SELECT "y"."a" AS "a" FROM "DB"."Y" AS "y" CROSS JOIN "a"."b"."INFORMATION_SCHEMA"."COLUMNS" AS "columns") SELECT "x"."a" AS "a" FROM "x"',
)

self.assertEqual(
optimizer.qualify.qualify(
parse_one(
"CREATE FUNCTION udfs.`myTest`(`x` FLOAT64) AS (1)",
read="bigquery",
),
dialect="bigquery",
).sql(dialect="bigquery"),
"CREATE FUNCTION `udfs`.`myTest`(`x` FLOAT64) AS (1)",
)

self.check_file("qualify_columns", qualify_columns, execute=True, schema=self.schema)

def test_qualify_columns__with_invisible(self):
Expand Down

0 comments on commit 154ece5

Please sign in to comment.