Skip to content
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

Add a native function namespace manager #23358

Merged

Conversation

pdabre12
Copy link
Contributor

@pdabre12 pdabre12 commented Aug 1, 2024

Description

Adds a native function namespace manager

Motivation and Context

To help resolve : #23000

Impact

Test Plan

Unit and end-to-end tests. More comprehensive end-to-end tests will be written in the future.

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • 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 ==

General C++ changes
* Add a native function namespace manager :pr:`23358`

Depends on : #23671

Copy link

linux-foundation-easycla bot commented Aug 1, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from 49d3b9d to 5ed5a18 Compare August 13, 2024 23:37
@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch 2 times, most recently from bcb09bc to ce7ca4b Compare August 17, 2024 00:06
steveburnett
steveburnett previously approved these changes Sep 10, 2024
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

LGTM! (docs)

Pull branch, new local doc build, the doc looks good. Thanks!

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from 4d00991 to c3ed29f Compare September 13, 2024 23:03
@pdabre12 pdabre12 changed the title [WIP] Native function namespace manager [WIP] Add a native function namespace manager Sep 13, 2024
steveburnett
steveburnett previously approved these changes Sep 25, 2024
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

LGTM! (docs)

Pull updated branch, new local doc build, doc looks good. Thanks!

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch 2 times, most recently from 3fde055 to ebfa361 Compare September 27, 2024 05:55
@pdabre12 pdabre12 changed the title [WIP] Add a native function namespace manager Add a native function namespace manager Sep 27, 2024
@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from f203d25 to 88e1152 Compare November 1, 2024 01:09
@pdabre12 pdabre12 marked this pull request as ready for review November 1, 2024 16:40
@pdabre12 pdabre12 requested a review from presto-oss November 1, 2024 16:40
@tdcmeehan tdcmeehan self-assigned this Nov 11, 2024
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.

Just some initial comments

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.

Refactored qualifyObjectName from static to instance method

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.

Add utility functions to resolve intermediate type in aggregate funct…

Thank you for the really extensive tests for this utility. I think the tests should be broken down to the various different types, because the tests are rather large.

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.

[native] Fix bug when handling multiple params and no params aggregat…

Can you help me understand when this bug manifests? Is there any way to add a unit test for it?

@@ -361,15 +379,18 @@ public void registerBuiltInFunctions(List<? extends SqlFunction> functions)
public List<SqlFunction> listFunctions(Session session, Optional<String> likePattern, Optional<String> escape)
{
ImmutableList.Builder<SqlFunction> functions = new ImmutableList.Builder<>();
if (!isListBuiltInFunctionsOnly(session)) {
if (isListBuiltInFunctionsOnly(session)) {
functions.addAll(functionNamespaceManagers.entrySet().stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

the point of listing built in functions only is to not pay the cost of listing from some functionNamespaceManagers that are more geared to point lookups and very expensive to list all functions. can we instead only list from the functionNamespaceManager that is the default one?

Copy link
Contributor

Choose a reason for hiding this comment

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

why stream the map and filter instead of getting the functionNamespacemanager directly?

functions.addAll(functionNamespaceManagers.get(
     defaultNamespace.getCatalogName().listFunctions(likePattern,escape).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.

We are configuring function namespaces using .properties files located under etc/function-namespace.
The name of the .properties file without the .properties extension corresponds to the catalogName, which is passed to the FunctionNamespaceManager factories. These factories then create the respective function namespaces.
This catalogName is subsequently registered as a ServingCatalog within its corresponding FunctionNamespaceManager.

In FunctionAndTypeManager, we maintain a map of the FunctionNamespaceManager instances, where:
• The key is the catalogName.
• The value is the corresponding FunctionNamespaceManager.
For example: {"native": NativeFunctionNamespaceManager}

To retrieve builtiin functions from the defaultNamespace,
We use defaultNamespace.getCatalogName() to get the catalogName. If the catalogName exists in the map, we fetch the corresponding FunctionNamespaceManager (e.g., NativeFunctionNamespaceManager) and call getFunctions() on it.

The only requirement for users to ensure is that the name of the file ({catalogName}.properties) file used to load the functionNamespaces must match the catalog name of the presto.default-namespace configuration property for the defaultNamespace, but its not a new requirement, even with the current implementation that is enforced.
Let me know if that works for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, thanks for catching that. Changed it.

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch 2 times, most recently from b0b9ddf to 764b364 Compare January 29, 2025 16:53
rschlussel
rschlussel previously approved these changes Jan 29, 2025
@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch 2 times, most recently from 33ff47b to d7dec93 Compare January 30, 2025 21:09
@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from d7dec93 to c4fe9ec Compare January 31, 2025 17:18
@pdabre12 pdabre12 requested a review from tdcmeehan January 31, 2025 17:21
@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from c4fe9ec to 38edeb3 Compare January 31, 2025 18:25
tdcmeehan
tdcmeehan previously approved these changes Jan 31, 2025
folly::split(
'.',
prestoDefaultNamespacePrefix,
prestoDefaultNamespacePrefixParts,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add CHECK that prestoDefaultNamespacePrefixParts has only 2 parts.

Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

@pdabre12 : Have 2 minor comments.


std::vector<std::string> parts;
folly::split('.', functionName, parts, true);
if ((parts.size() != 3) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a check instead ? Are there functions that don't follow since (since you added all the built-ins with prefixes) ?

Copy link
Contributor Author

@pdabre12 pdabre12 Jan 31, 2025

Choose a reason for hiding this comment

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

All the functions should have a prefix. Added the check, thanks.

#include "presto_cpp/main/types/TypeParser.h"
#include "presto_cpp/presto_protocol/core/presto_protocol_core.h"
#include "velox/core/Expressions.h"

namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving this to presto_cpp/main/common/Utils.h

Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @pdabre12

@pdabre12 pdabre12 merged commit e4be876 into prestodb:master Feb 1, 2025
62 checks passed
@pdabre12 pdabre12 deleted the native-function-namespace-manager branch February 1, 2025 03:32
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.

Add fail-fast function validation support for Presto C++
5 participants