-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow marking arguments as constant in the function signature #4204
Conversation
✅ Deploy Preview for meta-velox canceled.
|
velox/expression/FunctionSignature.h
Outdated
return isConstant_; | ||
} | ||
|
||
void setIsConstant(bool isConstant) { |
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 would be nice to keep this class immutable. Since is-constant is not a property of the type, consider, adding a list of boolean is-constant flags to the FunctionSignature class.
const TypeSignature returnType_;
const std::vector<TypeSignature> argumentTypes_;
const std::vector<bool> constantArguments_;
const bool variableArity_;
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.
Fixed
.argumentType("array(boolean)") | ||
.build(); | ||
|
||
testFuzzingSuccess(signature, BIGINT(), {VARCHAR(), ARRAY(BOOLEAN())}); | ||
testFuzzingSuccess( |
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 change here should not affect ArgumentTypeFuzzer, hence, I'm surprised to see changes to ArgumentTypeFuzzerTest.cpp. Let's remove these. Let's add tests to velox/exec/tests/FunctionSignatureBuilderTest.cpp instead.
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.
Fixed
@duanmeng Should we also update FunctionSignature::toString() to include "const" qualified for the arguments? |
@mbasmanova This may be confused with the const in C++, or should we use constant as close to the semantics of velox constant vector? |
@duanmeng I don't have a strong preference here. Here are some options.
|
@mbasmanova I've resolved all the comments and updated the toString method, could you help to take a 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.
@duanmeng Looks great. Let's add tests for variadic and generic arguments and then merge.
VELOX_USER_CHECK_EQ( | ||
argumentTypes.size(), | ||
constantArguments.size(), | ||
"Argument types size is not equal to constant flags"); |
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.
Nice check.
@@ -177,3 +177,30 @@ TEST_F(FunctionSignatureBuilderTest, anyInReturn) { | |||
}, | |||
"Type 'Any' cannot appear in return type"); | |||
} | |||
|
|||
TEST_F(FunctionSignatureBuilderTest, constFalgs) { |
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: constFalgs -> constantFlags
EXPECT_TRUE(signature->constantArguments().at(1)); | ||
EXPECT_FALSE(signature->constantArguments().at(2)); | ||
EXPECT_EQ( | ||
"(double,constant boolean,bigint) -> bigint", signature->toString()); |
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.
Nice test. Would you also add tests for constant variadic argument and constant generic argument?
EXPECT_EQ( | ||
"(double,constant boolean,bigint) -> bigint", signature->toString()); | ||
|
||
auto aggSignature = AggregateFunctionSignatureBuilder() |
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.
Consider moving this into a separate test and renaming to 'signature'.
TEST_F(FunctionSignatureBuilderTest, scalarConstantFlags) {
TEST_F(FunctionSignatureBuilderTest, aggregateConstantFlags) {
EXPECT_FALSE(signature->constantArguments().at(0)); | ||
EXPECT_TRUE(signature->constantArguments().at(1)); | ||
EXPECT_FALSE(signature->constantArguments().at(2)); | ||
std::cout << signature->toString() << std::endl; |
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.
Accidental?
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.
Removed, sorry not to check and remove it before the push.
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.
@duanmeng Looks great. Thank you for implementing this enhancement. Looking forward to a follow-up PR that leverages this functionality in the fuzzer.
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
If an argument is marked const in the signature, is the expression compiler allowed to compile such a function if the input is not literal? I do not see changes related to that ? could you also add a summary explaining the functionalities. |
@laithsakka It would nice to add a check for 'const' arguments to the ExprCompiler. Let's do that in a follow-up PR though to keep PRs small and easy to review. |
@mbasmanova merged this pull request in 09bd177. |
Details in #4140