-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: Add companionFunction to function metadata #9250
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for meta-velox canceled.
|
bfea9ca
to
3137659
Compare
@pramodsatya : How do we take care that we get only Prestissimo functions from the registry ? If there is a conflict between a Prestissimo and Spark function with the same name, then how do we disambiguate ? |
Thanks for the feedback @aditi-pandit, @czentgr. We are not checking that only Prestissimo functions are retrieved from the registry. Instead we rely on the Prestissimo worker to have registered only the presto functions, such as in this function, so there are no Spark functions in the registry. Please let me know if this is fine or whether we should have an additional way to distinguish between Presto and Spark functions in the registry. |
c2011b1
to
8a28ec9
Compare
8a28ec9
to
460e5db
Compare
460e5db
to
3eea7ab
Compare
Hi @aditi-pandit, @czentgr, could you please take another look at this PR? |
3eea7ab
to
29290d4
Compare
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.
Thanks for the feedback @aditi-pandit, addressed the comments. Could you please take another look?
29290d4
to
8b822aa
Compare
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.
Thanks @pramodsatya
8b822aa
to
4f11b42
Compare
4f11b42
to
3013349
Compare
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.
Thanks @aditi-pandit, addressed the comments. Could you please take another look?
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.
Thanks @pramodsatya. Changes look good.
8bdded7
to
2b18863
Compare
2b18863
to
f3b9781
Compare
Thanks for the feedback @aditi-pandit. @czentgr suggested that because this API modification is centered around detecting and removing companion functions, it would be better to include information about whether a function is a companion function in it's metadata. Since the concept of companion functions is specific to velox and not prestissimo, it would be better to get this information from the velox function metadata and detect companion functions from the function metadata in prestissimo (and handle them as per the requirement in prestissimo). This also helps avoid a dependency on I have updated the PR accordingly to include companion function information in the function metadata (in |
f3b9781
to
0b51694
Compare
0b51694
to
0dccd1c
Compare
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.
Thanks, looks good now.
@@ -413,10 +423,11 @@ bool CompanionFunctionsRegistrar::registerMergeExtractFunction( | |||
|
|||
auto mergeExtractFunctionName = | |||
CompanionSignatures::mergeExtractFunctionName(name); | |||
return registerAggregateFunction( | |||
return registerMergeExtractFunctionImpl( |
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.
Maybe rename to registerMergeExtractFunctionInternal
.
@pramodsatya. @czentgr : This is a reasonable solution as well, if we are okay exposing companion function concept to the services using Velox. With the other API to return all functions with a boolean parameter to say 'skipInternalFunctions' a single function could be used to skip all companion or any other internal functions added by the Velox framework. @mbasmanova : wdyt ? |
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.
@pramodsatya Pramod, would you update PR description to explain this change?
0dccd1c
to
64e6cc8
Compare
Apologies @mbasmanova, since this PR went through many iterations I had left it empty until the related discussion was concluded. I have updated the description now, could you please take another look? |
Can a window function be a companion function? I assume not. If so, let's remove isCompanion function from window function metadata. |
velox/expression/FunctionMetadata.h
Outdated
@@ -59,6 +62,11 @@ class VectorFunctionMetadataBuilder { | |||
return *this; | |||
} | |||
|
|||
VectorFunctionMetadataBuilder& isCompanionFunction(bool isCompanionFunction) { |
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.
naming: drop 'is';
builder.companionFunction(true)
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.
naming: drop 'is';
velox/exec/Aggregate.cpp
Outdated
if (auto func = getAggregateFunctionEntry(sanitizedName)) { | ||
return func->metadata; | ||
} else { | ||
VELOX_USER_FAIL("Metadata not found for aggregate function: {}", name); |
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.
The issue here is that aggregate function doesn't exist, not that it is missing metadata. Let's clarify.
VELOX_USER_FAIL("Aggregate function not found: {}", name);
velox/exec/Aggregate.cpp
Outdated
const auto sanitizedName = sanitizeName(name); | ||
if (auto func = getAggregateFunctionEntry(sanitizedName)) { | ||
return func->metadata; | ||
} else { |
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.
nit: drop else after return
velox/exec/WindowFunction.h
Outdated
@@ -43,14 +43,15 @@ class WindowFunction { | |||
kRows, | |||
}; | |||
|
|||
/// Indicates whether this is an aggregate window function and its process | |||
/// unit. | |||
/// Indicates whether this is an aggregate window function, whether it is a |
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.
nit:
...whether the corresponding aggregate function is a companion function....
velox/exec/WindowFunction.h
Outdated
struct Metadata { | ||
ProcessMode processMode; | ||
bool isAggregate; | ||
bool isCompanionFunction; |
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.
Perhaps, clarify that this can be true iff isAggregate is true.
velox/expression/FunctionMetadata.h
Outdated
@@ -40,6 +40,9 @@ struct VectorFunctionMetadata { | |||
/// In this case, 'rows' in VectorFunction::apply will point only to positions | |||
/// for which all arguments are not null. | |||
bool defaultNullBehavior{true}; | |||
|
|||
/// Indicates if this is a companion function. | |||
bool isCompanionFunction{false}; |
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.
consistency: drop 'is' to math other booleans here
velox/exec/Aggregate.h
Outdated
@@ -476,6 +476,9 @@ struct AggregateFunctionMetadata { | |||
/// True if results of the aggregation depend on the order of inputs. For | |||
/// example, array_agg is order sensitive while count is not. | |||
bool orderSensitive{true}; | |||
|
|||
/// Indicates if this is a companion function. | |||
bool isCompanionFunction{false}; |
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.
consistency: drop 'is' to math the other boolean
@@ -75,7 +75,7 @@ void registerRowNumber(const std::string& name, TypeKind resultTypeKind) { | |||
exec::registerWindowFunction( | |||
name, | |||
std::move(signatures), | |||
{exec::WindowFunction::ProcessMode::kRows, false}, | |||
{exec::WindowFunction::ProcessMode::kRows, false, false}, |
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.
It doesn't seem right to allow specifying isCompanion for a window function.
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.
Reverted, thanks.
@@ -142,7 +142,7 @@ void registerAverageAggregate( | |||
} | |||
} | |||
}, | |||
{false /*orderSensitive*/}, | |||
{false /*orderSensitive*/, false /*isCompanionFunction*/}, |
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.
It is strange to have an API that has both isCompanion and withCompanionFunctions
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 it seems a bit strange, but isCompanionFunction
is a part of the function metadata which indicates if the function being registered currently is a companion function, whereas withCompanionFunctions
indicates if the aggregate should be registered with companion functions. So both these fields would be needed.
Could you please share how this could be made more readable?
@@ -356,6 +357,23 @@ TEST_F(FunctionRegistryTest, isDeterministic) { | |||
ASSERT_FALSE(isDeterministic("not_found_function").has_value()); | |||
} | |||
|
|||
TEST_F(FunctionRegistryTest, isCompanionFunction) { | |||
functions::prestosql::registerAllScalarFunctions(); | |||
// extract aggregate companion functions are registered as vector 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.
typos
64e6cc8
to
6b91785
Compare
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.
Thanks for the feedback @mbasmanova. The companion function metadata added for window functions is now reverted and a check is added in registerAggregateFunction
to ensure aggregate companion functions are no longer registered as window functions.
Could you please take another look?
@@ -75,7 +75,7 @@ void registerRowNumber(const std::string& name, TypeKind resultTypeKind) { | |||
exec::registerWindowFunction( | |||
name, | |||
std::move(signatures), | |||
{exec::WindowFunction::ProcessMode::kRows, false}, | |||
{exec::WindowFunction::ProcessMode::kRows, false, false}, |
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.
Reverted, thanks.
@@ -142,7 +142,7 @@ void registerAverageAggregate( | |||
} | |||
} | |||
}, | |||
{false /*orderSensitive*/}, | |||
{false /*orderSensitive*/, false /*isCompanionFunction*/}, |
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 it seems a bit strange, but isCompanionFunction
is a part of the function metadata which indicates if the function being registered currently is a companion function, whereas withCompanionFunctions
indicates if the aggregate should be registered with companion functions. So both these fields would be needed.
Could you please share how this could be made more readable?
Adds a boolean field,
isCompanionFunction
, toVectorFunctionMetadata
,AggregateFunctionMetadata
, andWindowFunction::Metadata
, to indicatewhether the respective scalar, aggregate, and window functions are companion
functions in Velox.
This field would be used to check for and exclude companion functions from
the function metadata returned by the
v1/functions
endpoint in the PrestoC++ sidecar. Currently, this is being done by searching for specific suffixes in
the registered companion functions' names.
Related discussion: #11011 .