Skip to content

Commit 0555006

Browse files
Update sqlglot/schema.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 464d349 commit 0555006

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

sqlglot/schema.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,21 @@ def _normalize_udf(
572572

573573
if isinstance(udf, str):
574574
parsed: exp.Expression = exp.maybe_parse(udf, dialect=dialect)
575-
udf = parsed if isinstance(parsed, exp.Anonymous) else parsed.this
575+
# When parsing qualified UDF strings (e.g. "db.my_func()"), the root
576+
# expression may be a Dot, with the Anonymous function call nested
577+
# inside. Find the actual Anonymous node instead of blindly taking
578+
# the left-hand side.
579+
if isinstance(parsed, exp.Anonymous):
580+
udf_expr = parsed
581+
elif isinstance(parsed, exp.Expression):
582+
udf_expr = parsed.find(exp.Anonymous)
583+
else:
584+
udf_expr = None
585+
586+
if not isinstance(udf_expr, exp.Anonymous):
587+
raise SchemaError(f"Unable to parse UDF from: {udf!r}")
576588

589+
udf = udf_expr
577590
parts = self.udf_parts(udf)
578591

579592
if normalize:

0 commit comments

Comments
 (0)