Skip to content

Conversation

kevintang2022
Copy link
Contributor

@kevintang2022 kevintang2022 commented Jul 30, 2025

This PR includes changes for Built in functions for different use cases

Since these use cases have a lot of overlap, we can introduce an abstract class in order to reduce duplicate logic.

Description

Motivation and Context

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* ... 
* ... 

Hive Connector Changes
* ... 
* ... 

If release note is NOT required, use:

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Jul 30, 2025
@facebook-github-bot
Copy link
Collaborator

@kevintang2022 has imported this pull request. If you are a Meta employee, you can view this in D79301760.

kevintang2022 pushed a commit to kevintang2022/presto that referenced this pull request Aug 8, 2025
Summary:
…ceManager for registering sql invoked functions

## Description


## Motivation and Context



## Impact


Test Plan:
<!---Please fill in how you tested your change-->

## Contributor checklist

- [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [ ] PR description addresses the issue accurately and concisely.  If the change is non-trivial, a GitHub Issue is referenced.
- [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality.
- [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [ ] Adequate tests were added if applicable.
- [ ] CI passed.

## Release Notes
Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* ...
* ...

Hive Connector Changes
* ...
* ...
```

If release note is NOT required, use:

```
== NO RELEASE NOTE ==
```

Rollback Plan:

Differential Revision: D79301760

Pulled By: kevintang2022
@kevintang2022 kevintang2022 force-pushed the kevin-sql-invoked-functions-SPI branch from 8825888 to 9cf57f9 Compare August 8, 2025 21:52
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D79301760

kevintang2022 pushed a commit to kevintang2022/presto that referenced this pull request Aug 8, 2025
Summary:
…ceManager for registering sql invoked functions

## Description


## Motivation and Context



## Impact


Test Plan:
<!---Please fill in how you tested your change-->

## Contributor checklist

- [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [ ] PR description addresses the issue accurately and concisely.  If the change is non-trivial, a GitHub Issue is referenced.
- [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality.
- [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [ ] Adequate tests were added if applicable.
- [ ] CI passed.

## Release Notes
Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* ...
* ...

Hive Connector Changes
* ...
* ...
```

If release note is NOT required, use:

```
== NO RELEASE NOTE ==
```

Rollback Plan:

Differential Revision: D79301760

Pulled By: kevintang2022
@kevintang2022 kevintang2022 force-pushed the kevin-sql-invoked-functions-SPI branch from 9cf57f9 to 1bdb396 Compare August 8, 2025 22:42
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D79301760

@kevintang2022 kevintang2022 changed the title Introduce getSqlInvokedFunctions SPI and BuiltInPluginFunctionNamespa… Native built in functions demo 1 Aug 11, 2025
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D79301760

@kevintang2022 kevintang2022 force-pushed the kevin-sql-invoked-functions-SPI branch from 1bdb396 to 464830f Compare August 11, 2025 03:13
Comment on lines +492 to +501
functions.addAll(builtInNativeFunctionNamespaceManager.listFunctions().stream().collect(toImmutableList()));
functions.addAll(builtInPluginFunctionNamespaceManager.listFunctions().stream().collect(toImmutableList()));
}
else {
functions.addAll(SessionFunctionUtils.listFunctions(session.getSessionFunctions()));
functions.addAll(functionNamespaceManagers.values().stream()
.flatMap(manager -> manager.listFunctions(likePattern, escape).stream())
.collect(toImmutableList()));
functions.addAll(builtInNativeFunctionNamespaceManager.listFunctions().stream().collect(toImmutableList()));
functions.addAll(builtInPluginFunctionNamespaceManager.listFunctions().stream().collect(toImmutableList()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: list functions may not work properly. Need to figure out the deduplication logic for this functions list

@facebook-github-bot
Copy link
Collaborator

@kevintang2022 has imported this pull request. If you are a Meta employee, you can view this in D79301760.

@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D79301760

kevintang2022 added a commit to kevintang2022/presto that referenced this pull request Aug 11, 2025
Summary:
This PR includes changes for Built in functions for different use cases
- Register SQL invoked function in built in namespace when they come from plugins (prestodb#25597)
- Register Native functions in built in namespace when they come from sidecar (prestodb/rfcs#41)

Since these use cases have a lot of overlap, we can introduce an abstract class in order to reduce duplicate logic.

## Description

## Motivation and Context

## Impact

Pull Request resolved: prestodb#25661

Test Plan:
<!---Please fill in how you tested your change-->

## Contributor checklist

- [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [ ] PR description addresses the issue accurately and concisely.  If the change is non-trivial, a GitHub Issue is referenced.
- [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality.
- [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [ ] Adequate tests were added if applicable.
- [ ] CI passed.

## Release Notes
Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* ...
* ...

Hive Connector Changes
* ...
* ...
```

If release note is NOT required, use:

```
== NO RELEASE NOTE ==
```

Rollback Plan:

Differential Revision: D79301760

Pulled By: kevintang2022
@kevintang2022 kevintang2022 force-pushed the kevin-sql-invoked-functions-SPI branch from c61f5b8 to b4d7062 Compare August 11, 2025 22:35
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D79301760

kevintang2022 added a commit to kevintang2022/presto that referenced this pull request Aug 11, 2025
Summary:
This PR includes changes for Built in functions for different use cases
- Register SQL invoked function in built in namespace when they come from plugins (prestodb#25597)
- Register Native functions in built in namespace when they come from sidecar (prestodb/rfcs#41)

Since these use cases have a lot of overlap, we can introduce an abstract class in order to reduce duplicate logic.

## Description

## Motivation and Context

## Impact

Pull Request resolved: prestodb#25661

Test Plan:
<!---Please fill in how you tested your change-->

## Contributor checklist

- [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [ ] PR description addresses the issue accurately and concisely.  If the change is non-trivial, a GitHub Issue is referenced.
- [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality.
- [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [ ] Adequate tests were added if applicable.
- [ ] CI passed.

## Release Notes
Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* ...
* ...

Hive Connector Changes
* ...
* ...
```

If release note is NOT required, use:

```
== NO RELEASE NOTE ==
```

Rollback Plan:

Differential Revision: D79301760

Pulled By: kevintang2022
@kevintang2022 kevintang2022 force-pushed the kevin-sql-invoked-functions-SPI branch from b4d7062 to df7df56 Compare August 11, 2025 22:54
*
* @throws PrestoException if there are no matches or multiple matches
*/
private FunctionHandle getMatchingFunctionHandle(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logic here for handling conflicts:

  1. Plugin and Default: throw an error
  2. Plugin but no default: use plugin
  3. native and default: use native if default has a SQL language, but use default in default is a Java language
  4. otherwise, use default or native (whichever one is available)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the abstract class that will be used by the native and plugin BuiltInSpecialFunctionNamespaceManager

Copy link
Contributor

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 required anymore as I changed BuiltInPluginFunctionNamespaceManager in #25597 to inherit from FunctionNamespaceManager.

Copy link
Contributor

@pdabre12 pdabre12 Aug 12, 2025

Choose a reason for hiding this comment

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

I think we could still benefit from a helper class though since there's a decent amount of overlap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sounds good. I can do that deduplication in my followup PR once you merge yours in


private URI getSidecarLocationOnStartup()
{
Node sidecarNode = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Retry logic here is needed to ensure that a worker sidecar node is available to read the function registry from

@@ -197,6 +198,7 @@ public void run()
NodeInfo nodeInfo = injector.getInstance(NodeInfo.class);
PluginNodeManager pluginNodeManager = new PluginNodeManager(nodeManager, nodeInfo.getEnvironment());
planCheckerProviderManager.loadPlanCheckerProviders(pluginNodeManager);
injector.getInstance(FunctionAndTypeManager.class).registerNativeFunctions();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to happen after NodeManger is ready, so it is called here

@@ -2296,6 +2297,19 @@ public boolean isNativeExecutionEnabled()
return this.nativeExecutionEnabled;
}

@Config("built-in-sidecar-functions-enabled")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feature is controlled by server property

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using this enum type instead of isBuiltInPluginFunction and isBuiltInNativeFunction

@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D79301760

kevintang2022 added a commit to kevintang2022/presto that referenced this pull request Aug 12, 2025
Summary:
This PR includes changes for Built in functions for different use cases
- Register SQL invoked function in built in namespace when they come from plugins (prestodb#25597)
- Register Native functions in built in namespace when they come from sidecar (prestodb/rfcs#41)

Since these use cases have a lot of overlap, we can introduce an abstract class in order to reduce duplicate logic.

## Description

## Motivation and Context

## Impact

Pull Request resolved: prestodb#25661

Test Plan:
<!---Please fill in how you tested your change-->

## Contributor checklist

- [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [ ] PR description addresses the issue accurately and concisely.  If the change is non-trivial, a GitHub Issue is referenced.
- [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality.
- [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [ ] Adequate tests were added if applicable.
- [ ] CI passed.

## Release Notes
Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* ...
* ...

Hive Connector Changes
* ...
* ...
```

If release note is NOT required, use:

```
== NO RELEASE NOTE ==
```

Rollback Plan:

Differential Revision: D79301760

Pulled By: kevintang2022
@kevintang2022 kevintang2022 force-pushed the kevin-sql-invoked-functions-SPI branch from df7df56 to 5a2be22 Compare August 12, 2025 20:21
@kevintang2022 kevintang2022 force-pushed the kevin-sql-invoked-functions-SPI branch from 5a2be22 to f31b05d Compare August 13, 2025 02:25
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.

4 participants