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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

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?

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from d5ccae3 to b229336 Compare December 6, 2024 00:44
#include "presto_cpp/main/types/TypeParser.h"
#include "presto_cpp/presto_protocol/core/presto_protocol_core.h"
#include "velox/core/Expressions.h"

namespace {
inline std::string formatDefaultNamespacePrefix(
Copy link
Contributor

Choose a reason for hiding this comment

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

Its bit odd this function has name formatDefaultNamespacePrefix and then takes the default namespace prefix as a parameter. Maybe you should call this addDefaultNamespace and pick up the default namespace in the function without passing it as a parameter everywhere.

Copy link
Contributor Author

@pdabre12 pdabre12 Dec 10, 2024

Choose a reason for hiding this comment

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

Yes, calling this addDefaultNamespace makes sense.
I am confused about the picking up of the default namespace from the functions part, the functions passed down to the formatDefaultNamespacePrefix function won't have any namespace attached.

For eg:
presto.default.$operator.$add should map to {namespace-prefix}.add , in this case native.default.add

The call to the formatDefaultNamespacePrefix() function will take in the default namespace prefix and the function name, add the default namespace prefix to the function name and return the string.

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from b229336 to c748230 Compare December 9, 2024 18:33
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.

A few nits

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch 3 times, most recently from f2c832d to d8a89d3 Compare December 10, 2024 21:29
@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from d8a89d3 to f73aca4 Compare December 16, 2024 21:59
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.

Almost there

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from f73aca4 to 5567990 Compare December 17, 2024 21:16
@pdabre12 pdabre12 requested a review from tdcmeehan December 17, 2024 21:17
@pdabre12
Copy link
Contributor Author

@rschlussel Can you please have another look? Thanks.

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.

Only one minor thing.

@rschlussel would you like to have a look as well?

@@ -129,6 +131,7 @@ public class FunctionAndTypeManager
private final LoadingCache<FunctionResolutionCacheKey, FunctionHandle> functionCache;
private final CacheStatsMBean cacheStatsMBean;
private final boolean nativeExecution;
private CatalogSchemaName currentDefaultNamespace = DEFAULT_NAMESPACE;
Copy link
Contributor

Choose a reason for hiding this comment

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

this class isn't really thread safe anymore because this field is mutable, and there are no guards on how it is read/written. It might be better to set the default namespace in FunctionsConfig instead of in the config for any particular function namespace. Then we also wouldn't need to check that there is only one.
Downside is that we will only fail later (at runtime?) if the default namespace doesn't exist (never gets loaded).

Copy link
Contributor

Choose a reason for hiding this comment

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

also, let's change this name to defaultNamespace, as this isn't something that we expect to be updated. and change the static variable DEFAULT_NAMESPACE to something that's clearer now, e.g. JAVA_BUILTIN_NAMESPACE.

Copy link
Contributor

Choose a reason for hiding this comment

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

Last comment about default_namespace, but have you checked all the things that are using DEFAULT_NAMESPACE right now? Is it still correct for them to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a config in FunctionsConfig, the default value is going to be JAVA_BUILTIN_NAMESPACE so we always have a default namespace configured.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I went over usages of DEFAULT_NAMESPACE (now JAVA_BUILTIN_NAMESPACE), they are used in the right places.

@@ -698,7 +728,8 @@ private FunctionHandle resolveFunctionInternal(Optional<TransactionId> transacti

private FunctionHandle resolveBuiltInFunction(QualifiedObjectName functionName, List<TypeSignatureProvider> parameterTypes)
{
checkArgument(functionName.getCatalogSchemaName().equals(DEFAULT_NAMESPACE), "Expect built-in functions");
checkArgument(functionName.getCatalogSchemaName().equals(currentDefaultNamespace) ||
Copy link
Contributor

@rschlussel rschlussel Dec 19, 2024

Choose a reason for hiding this comment

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

why do we use both DEFAULT_NAMESPACE and currentDefaultNamespace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There might be some functions an eg: key_sampling_percent function

sampledArg = call(
functionAndTypeManager,
QualifiedObjectName.valueOf(JAVA_BUILTIN_NAMESPACE, getKeyBasedSamplingFunction(session)),
DOUBLE,
ImmutableList.of(arg));
, which would always be under the JAVA_BUILTIN_NAMESPACE.

@pdabre12
Copy link
Contributor Author

I will get back to this soon.

@pdabre12 pdabre12 force-pushed the native-function-namespace-manager branch from 5567990 to 2d7cbe0 Compare January 22, 2025 16:47
@pdabre12
Copy link
Contributor Author

@rschlussel
Thank you for the review.
Addressed your comments. Can you please have another look?

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