Skip to content

Conversation

@nmahadevuni
Copy link
Member

@nmahadevuni nmahadevuni commented Jun 16, 2025

Description

This change allows functions registered via Plugin->getFunctions() SPI to use a different namespace.

Motivation and Context

At present, functions registered via getFunctions() SPI are registered in "presto.default" namespace which is restrictive. Iceberg's DAY(), MONTH(), YEAR() functions would conflict with the builtin functions with the same name. We want to support functions specific to connectors in a custom namespace. Example: Iceberg partition transform functions as described in #25166

Impact

No impact

Test Plan

Added new tests in TestScalarFunctions.java

== NO RELEASE NOTE ==

@nmahadevuni nmahadevuni requested a review from hantangwangd June 16, 2025 06:00
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jun 16, 2025
@prestodb-ci prestodb-ci requested review from a team, NivinCS and infvg and removed request for a team June 16, 2025 06:00
Copy link
Contributor

@yingsu00 yingsu00 left a comment

Choose a reason for hiding this comment

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

Thanks @nmahadevuni . It mostly look good. Could you please update the PR message to explain that without the namespace Iceberg's DAY(), YEAR(), MONTH() functions would conflict with Presto builtin ones. Add the same message to the commit itself too. Thanks!

}
}

public void assertFunction(String expr, Type type, Object value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not used

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

assertQuery("SELECT " + expr, Column.of(type, value));
}

public void assertInvalidFunction(String expr, String exceptionPattern)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not used. Can you please add some tests with invalide function name and namespace?

if (scalarFunction != null) {
String baseName = scalarFunction.value().isEmpty() ? camelToSnake(annotatedName(annotated)) : scalarFunction.value();
builder.add(new ScalarImplementationHeader(baseName, new ScalarHeader(description, scalarFunction.visibility(), scalarFunction.deterministic(), scalarFunction.calledOnNullInput(), descriptor)));
String functionNamespace;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just put the declaration of type to the line 99

return Optional.empty();
}

public static class Column
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be private?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unused. Removed it.

@nmahadevuni
Copy link
Member Author

Thanks @yingsu00 . I have addressed your comments. Please review.

Copy link
Contributor

@tdcmeehan tdcmeehan left a comment

Choose a reason for hiding this comment

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

I don't think it's a good idea to hard-code the function's namespace in the function definition itself.

  1. The catalog and schema are runtime properties. They are not known in advance (in code).
  2. We already have a catalog and schema used to determine the function namespace manager. Overloading it will be confusing (for example, if I have dynamic function namespace manager, it is confusing that a change to the schema can mean that overwrites the built-in function).

Let's think of a better design.

@tdcmeehan tdcmeehan self-assigned this Jun 16, 2025
@yingsu00
Copy link
Contributor

@tdcmeehan What approach would you recommend here? Do you already have something in mind or have you started working on it? If so, we're happy to close this PR and leave it in your capable hands.

@nmahadevuni
Copy link
Member Author

@tdcmeehan What approach would you recommend here? Do you already have something in mind or have you started working on it? If so, we're happy to close this PR and leave it in your capable hands.

I had a chat with Tim. We decided to have a new interface getSystemFunctions() in the Connector SPI which will register the functions supplied by this method in a new BuiltInPluginFunctionNameSpaceManager. Any connector which supplies functions with this method will have functions registered in the namespace <catalog-name>.system.

@yingsu00
Copy link
Contributor

I had a chat with Tim. We decided to have a new interface getSystemFunctions() in the Connector SPI which will register the functions supplied by this method in a new BuiltInPluginFunctionNameSpaceManager. Any connector which supplies functions with this method will have functions registered in the namespace .system.

That sounds good.

@nmahadevuni
Copy link
Member Author

Closing this as its addressed in #25594

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

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants