Skip to content

Conversation

@cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

This PR adds loadPersistentScalarFunction method to SessionCatalog, to unify the scalar function lookup and resolution between v1 and v2 catalogs. The key difference between v1 and v2 catalogs about function is:

  • v1 catalog provides different APIs for describing function and invoking function to do function lookup: lookupPersistentFunction and resolvePersistentFunction.
  • v2 catalog only has one single lookup API: loadFunction. This API returns UnboundFunction, for invocation, it needs to enter the second phase and call UnboundFunction.bind.

The newly added loadPersistentScalarFunction method follows the v2 catalog style and handles function invocation (load resources and create function builder) in a second phase.

Why are the changes needed?

Code cleanup, also also avoid redundant function lookup from catalog introduced by #53531

Does this PR introduce any user-facing change?

No

How was this patch tested?

existing tests

Was this patch authored or co-authored using generative AI tooling?

cursor 2.2.44

@github-actions github-actions bot added the SQL label Dec 27, 2025
@cloud-fan
Copy link
Contributor Author

cc @pan3793

val funcName = qualifiedIdent.funcName
if (registry.functionExists(qualifiedIdent)) {
// This function has been already loaded into the function registry.
registry.lookupFunction(qualifiedIdent, arguments)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I previously assumed the second round would go here, seems not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2 function does not support table function yet, so scalar and table functions has different code paths:

* Create a metadata-only V1Function (for DESCRIBE FUNCTION).
* If invoke() is called, it will throw an error.
*/
def apply(info: ExpressionInfo): V1Function = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this change, calling V1Function(info) would go from the constructor to here, maybe it should use a different name to avoid abuse (especially by external plugins), or just remove it and require the caller to use metadataOnlyBuilder explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants