-
Notifications
You must be signed in to change notification settings - Fork 32
Add RFC for new SPI for SQL invoked functions #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
907c330 to
d753255
Compare
d753255 to
2becbfe
Compare
|
|
||
| Users would need to load the newly introduced plugin modules if they wish to use the inlined SQL functions that Presto currently supports. | ||
| This change applies to both Java-based and native sidecar-enabled/non-enabled Presto clusters. | ||
| - In Java-only/ non-sidecar enabled native clusters, users can load the `presto-sql-invoked-functions-plugin` plugin module containing all the inlined SQL invoked functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong, but strictly speaking Java users may continue to use the getFunctions() SPI, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, getFunctions() SPI can still be used by Java users.
The key difference is when the new getSqlInvokedFunctions() SPI is used in a plugin, the sql invoked functions under that plugin returned by the getSqlInvokedFunctions() SPI will be loaded under a new plugin-based namespace manager BuiltInPluginFunctionNamespaceManager.
In theory, you could also have a getFunctions() SPI for the same plugin and all those functions will be registered as built-in functions under the BuiltInTypeAndFunctionNamespaceManager as is the current behavior.
I will add a test case testing this behaviour.
feilong-liu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Add one more comment on extensions of the design to better support Java/Cpp/SQL functions.
| To address this, the proposed change moves all inlined SQL invoked functions into a plugin-based namespace manager `BuiltInPluginFunctionNamespaceManager` which serves whatever the current default function namespace is. | ||
| This ensures: | ||
| - All inlined SQL invoked functions are grouped together cleanly and loaded via a plugin. | ||
| - Overridden native implementations of inlined SQL invoked functions are excluded from plugin registration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will SQL invoked functions having native implementations be skipped? I am asking because I see in the current PR https://github.com/prestodb/presto/pull/25597/files it will throw error for duplicates.
I am wondering if we can skip if getting name conflicts, as it will not need manually removal of existing functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, SQL invoked functions having native implementations will be skipped provided we load the presto-native-sql-invoked-functions-plugin, this is only supported for sidecar-enabled clusters.
I am wondering if we can skip if getting name conflicts, as it will not need manually removal of existing functions.
Yes, this could be done but it makes sense only in the case of overridden native implementations because we prioritize those over the sql invoked fns. In other cases/ plugins loaded , there isn't a priority assigned to the Fns loaded via the plugin so I thought it's better to fail at duplicate signatures instead of silently skipping them. What do you think?
Also the functions loaded via the plugin will be available before the functions from the sidecar(as its a lazy fetch call), so you will need to remove that overridden plugin loaded sql invoked fn from BuiltInPluginFunctionNamespaceManager which isn't ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If name conflicts will lead to failure, does this mean that we need to make sure that functions registered does not have functions with the same name?
As shared in #41, we are trying to register all functions, java, native, SQL into the same namespace, and there are overlap between these functions. If we are to fail for conflict names, it means that we need to manually removing some functions from registration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we check for conflict mismatches only against the plugins and the default serving namespace manager. The code block where we do the conflict check.
private synchronized FunctionMap checkForNamingConflicts()
{
Optional<FunctionNamespaceManager<?>> functionNamespaceManager =
functionAndTypeManager.getServingFunctionNamespaceManager(functionAndTypeManager.getDefaultNamespace());
checkArgument(functionNamespaceManager.isPresent(), "Cannot find function namespace for catalog '%s'", functionAndTypeManager.getDefaultNamespace().getCatalogName());
checkForNamingConflicts(functionNamespaceManager.get().listFunctions(Optional.empty(), Optional.empty()));
return functions;
}
private synchronized void checkForNamingConflicts(Collection<? extends SqlFunction> functions)
{
for (SqlFunction function : functions) {
for (SqlFunction existingFunction : this.functions.list()) {
checkArgument(!function.getSignature().equals(existingFunction.getSignature()), "Function already registered: %s", function.getSignature());
}
}
}
We would need to add code here to check signature conflicts for functions residing in the BuiltInNativeFunctionNamespaceManager.
To clarify, the checks are:
- Plugins with other plugins
- Plugins with
BuiltInNativeFunctionNamespaceManager - Plugins with current serving namespace manager
Note that we aren't checking for conflicts with BuiltInNativeFunctionNamespaceManager against the current serving namespace manager, but we still wanna enforce failing on duplicate signatures in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In short, the specific use case shared in #41 should work, but we might need some modifications in #resolveFunctionInternal
| ### Non-goals | ||
| - This RFC does not Change the execution model for inlined SQL invoked functions - they are still evaluated in Java as earlier. | ||
| - It does not modify function resolution rules outside of registration-time separation (i.e., no new prioritization logic is added). | ||
| - It does not impact native (functions pulled from sidecar) or Java built-in function registration, which remains handled by the `NativeFunctionNamespaceManager` and `BuiltInTypeAndFunctionNamespaceManager` respectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevintang2022 has a proposal which use this design to support native functions in Prestissimo https://docs.google.com/document/d/13tv1NYKWfy3v54kV1fyXFOYMHpCUkcEd6w8XSTyd2d0/edit?usp=sharing
which needs some extensions for this design.
I wonder if we can have one more built-in function plugin for native functions, so that native functions will also be under presto.default namespace, which will lead to seamless support for evaluation of functions of Java/Cpp/SQL at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented on that RFC, had one doubt, will come back to this question.
2becbfe to
8f5ce35
Compare
8f5ce35 to
8a5c844
Compare
|
Thanks for the review @tdcmeehan @feilong-liu . Can you please have another look? |
|
@rschlussel Do you have any comments on this? |
No description provided.