Skip to content

fix(convert): resolve qualified calls to project functions - #343

Merged
kvlonge merged 4 commits into
mainfrom
fix/qualified-project-functions
Nov 30, 2026
Merged

kvlonge merged 4 commits into
mainfrom
fix/qualified-project-functions

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Why

Snowflake resolves a two- or three-part function call, such as analytics.udfs.normalize_email(email), against the functions declared in the schema. Conversion treated these calls as method calls and refused them as METHOD CALL, so SQL calling a project's Python functions by their qualified name could not run through register_functions.

Changes

  • Qualified calls resolve against schema.functions: an exact match on the written parts, otherwise the one declared name with more parts that ends in them. A two-part name takes the session's DATABASE.
  • A call to an undeclared function refuses with a message naming it. A name that matches functions in several databases refuses and asks for the full name or a session DATABASE; it never picks one.
  • A resolved call converts like an unqualified project function call. Volatility checks treat it the same way: a subquery calling a volatile one refuses inside a lambda, and the repeated-call count folds quoted names as conversion does.
  • A three-part name matches only its own key. An unresolved function's help says to declare it among the project's functions, not in sources/*.yml.
  • The runtime extra pins the DuckDB version register_functions needs (pip install "sqlbabel[runtime]"). The Python docs cover the extra and qualified names.

Verification

  • Python tests (74): a three-part call with a NULL row, with the bind check on; a same-name function in another schema; a two-part call with a session DATABASE; a quoted schema under QUOTED_IDENTIFIERS_IGNORE_CASE; an undeclared call and an ambiguous call refused; the extra's pin.
  • CLI cases: a qualified volatile call in a subquery under a lambda refuses; an undeclared qualified call prints the functions help.
  • Name resolution unit tests (including a longer key never matching), diagnostics, analysis and CLI tests pass.
  • cargo fmt --check, clippy -D warnings on the changed crates, fensu check, ruff and ty are clean.

Snowflake resolves a two- or three-part function call against the
functions declared in the schema. Conversion now does the same: a
qualified call to a declared function converts to the registered
function, an undeclared one refuses with a message naming it, and a
name that matches functions in several databases refuses and asks for
the full name or a session DATABASE.

The runtime extra pins the duckdb version register_functions needs.
A subquery calling a volatile function by its qualified name now
refuses inside a lambda, and the volatile-call count folds quoted
names as conversion does. A three-part name matches only its own key,
and a qualified call to an unknown function says to declare it among
the project's functions.
@kvlonge
kvlonge enabled auto-merge November 30, 2026 12:17
…aseline

Refusals of SNOWFLAKE.NOTIFICATION.TEXT_HTML, TEXT_PLAIN and SANITIZE_WEBHOOK_CONTENT now name the function, so those forms measure as refused and OBJECT_KEYS beside them as matching.
@kvlonge
kvlonge added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 156d4a2 Nov 30, 2026
15 checks passed
@kvlonge
kvlonge deleted the fix/qualified-project-functions branch November 30, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant