diff --git a/velox/exec/tests/FunctionSignatureBuilderTest.cpp b/velox/exec/tests/FunctionSignatureBuilderTest.cpp index 2d97decad0522..00563a3e6a3ca 100644 --- a/velox/exec/tests/FunctionSignatureBuilderTest.cpp +++ b/velox/exec/tests/FunctionSignatureBuilderTest.cpp @@ -177,8 +177,7 @@ TEST_F(FunctionSignatureBuilderTest, scalarConstantFlags) { .argumentType("double") .constantArgumentType("T") .argumentType("bigint") - .constantArgumentType("boolean") - .variableArity() + .constantVariableArity("boolean") .build(); EXPECT_FALSE(signature->constantArguments().at(0)); EXPECT_TRUE(signature->constantArguments().at(1)); @@ -214,8 +213,7 @@ TEST_F(FunctionSignatureBuilderTest, aggregateConstantFlags) { .argumentType("bigint") .constantArgumentType("T") .argumentType("T") - .constantArgumentType("double") - .variableArity() + .constantVariableArity("double") .build(); EXPECT_FALSE(aggSignature->constantArguments().at(0)); EXPECT_TRUE(aggSignature->constantArguments().at(1)); diff --git a/velox/expression/FunctionSignature.h b/velox/expression/FunctionSignature.h index ca410a9a4aae3..1ea46c2625992 100644 --- a/velox/expression/FunctionSignature.h +++ b/velox/expression/FunctionSignature.h @@ -314,6 +314,24 @@ class FunctionSignatureBuilder { return *this; } + /// Variable arity arguments can appear only at the end of the argument list + /// and can appear zero or more times. + FunctionSignatureBuilder& variableArity(const std::string& type) { + argumentTypes_.emplace_back(parseTypeSignature(type)); + constantArguments_.push_back(false); + variableArity_ = true; + return *this; + } + + /// Variable arity arguments can appear only at the end of the argument list + /// and can appear zero or more times. + FunctionSignatureBuilder& constantVariableArity(const std::string& type) { + argumentTypes_.emplace_back(parseTypeSignature(type)); + constantArguments_.push_back(true); + variableArity_ = true; + return *this; + } + FunctionSignaturePtr build(); private: @@ -391,6 +409,25 @@ class AggregateFunctionSignatureBuilder { return *this; } + /// Variable arity arguments can appear only at the end of the argument list + /// and can appear zero or more times. + AggregateFunctionSignatureBuilder& variableArity(const std::string& type) { + argumentTypes_.emplace_back(parseTypeSignature(type)); + constantArguments_.push_back(false); + variableArity_ = true; + return *this; + } + + /// Variable arity arguments can appear only at the end of the argument list + /// and can appear zero or more times. + AggregateFunctionSignatureBuilder& constantVariableArity( + const std::string& type) { + argumentTypes_.emplace_back(parseTypeSignature(type)); + constantArguments_.push_back(true); + variableArity_ = true; + return *this; + } + std::shared_ptr build(); private: diff --git a/velox/expression/fuzzer/ExpressionFuzzer.cpp b/velox/expression/fuzzer/ExpressionFuzzer.cpp index e981a8c0f36f5..f8b656cb20fcb 100644 --- a/velox/expression/fuzzer/ExpressionFuzzer.cpp +++ b/velox/expression/fuzzer/ExpressionFuzzer.cpp @@ -185,8 +185,7 @@ static const std::unordered_map< // boolean, boolean,.. -> boolean facebook::velox::exec::FunctionSignatureBuilder() .argumentType("boolean") - .argumentType("boolean") - .variableArity() + .variableArity("boolean") .returnType("boolean") .build()}}, {"or", @@ -195,8 +194,7 @@ static const std::unordered_map< // boolean, boolean,.. -> boolean facebook::velox::exec::FunctionSignatureBuilder() .argumentType("boolean") - .argumentType("boolean") - .variableArity() + .variableArity("boolean") .returnType("boolean") .build()}}, {"coalesce", @@ -206,8 +204,7 @@ static const std::unordered_map< facebook::velox::exec::FunctionSignatureBuilder() .typeVariable("T") .argumentType("T") - .argumentType("T") - .variableArity() + .variableArity("T") .returnType("T") .build()}}, { diff --git a/velox/expression/fuzzer/tests/ArgumentTypeFuzzerTest.cpp b/velox/expression/fuzzer/tests/ArgumentTypeFuzzerTest.cpp index 32971df22e0d6..a60d16e24348f 100644 --- a/velox/expression/fuzzer/tests/ArgumentTypeFuzzerTest.cpp +++ b/velox/expression/fuzzer/tests/ArgumentTypeFuzzerTest.cpp @@ -182,8 +182,7 @@ TEST_F(ArgumentTypeFuzzerTest, variableArity) { .typeVariable("X") .returnType("X") .argumentType("X") - .argumentType("bigint") - .variableArity() + .variableArity("bigint") .build(); testFuzzingSuccess(signature, VARCHAR(), {VARCHAR(), BIGINT()}); @@ -193,8 +192,7 @@ TEST_F(ArgumentTypeFuzzerTest, variableArity) { auto signature = exec::FunctionSignatureBuilder() .knownTypeVariable("K") .returnType("bigint") - .argumentType("K") - .variableArity() + .variableArity("K") .build(); std::mt19937 seed{0}; ArgumentTypeFuzzer fuzzer{*signature, BIGINT(), seed}; @@ -434,8 +432,7 @@ TEST_F(ArgumentTypeFuzzerTest, fuzzDecimalArgumentTypes) { .integerVariable("s") .returnType("decimal(p,s)") .argumentType("decimal(p,s)") - .argumentType("decimal(p,s)") - .variableArity() + .variableArity("decimal(p,s)") .build(); argTypes = fuzzArgumentTypes(*signature, DECIMAL(10, 7)); ASSERT_LE(1, argTypes.size()); @@ -582,8 +579,7 @@ TEST_F(ArgumentTypeFuzzerTest, fuzzDecimalReturnType) { .integerVariable("s") .returnType("decimal(p,s)") .argumentType("decimal(p,s)") - .argumentType("decimal(p,s)") - .variableArity() + .variableArity("decimal(p,s)") .build(); returnType = fuzzReturnType(*signature); diff --git a/velox/expression/tests/ExprTest.cpp b/velox/expression/tests/ExprTest.cpp index 285abe68fcd3a..d3af7b405d012 100644 --- a/velox/expression/tests/ExprTest.cpp +++ b/velox/expression/tests/ExprTest.cpp @@ -1424,8 +1424,7 @@ class StatefulVectorFunction : public exec::VectorFunction { return {exec::FunctionSignatureBuilder() .typeVariable("T") .returnType("integer") - .argumentType("T") - .variableArity() + .variableArity("T") .build()}; } @@ -2008,8 +2007,7 @@ class NullArrayFunction : public exec::VectorFunction { return {exec::FunctionSignatureBuilder() .typeVariable("T") .returnType("array(varchar)") - .argumentType("T") - .variableArity() + .variableArity("T") .build()}; } }; diff --git a/velox/expression/tests/SignatureBinderTest.cpp b/velox/expression/tests/SignatureBinderTest.cpp index 4eba91f384550..4889dcb02d123 100644 --- a/velox/expression/tests/SignatureBinderTest.cpp +++ b/velox/expression/tests/SignatureBinderTest.cpp @@ -586,8 +586,7 @@ TEST(SignatureBinderTest, variableArity) { { auto signature = exec::FunctionSignatureBuilder() .returnType("varchar") - .argumentType("varchar") - .variableArity() + .variableArity("varchar") .build(); testSignatureBinder(signature, {}, VARCHAR()); @@ -602,8 +601,7 @@ TEST(SignatureBinderTest, variableArity) { auto signature = exec::FunctionSignatureBuilder() .returnType("varchar") .argumentType("integer") - .argumentType("double") - .variableArity() + .variableArity("double") .build(); testSignatureBinder(signature, {INTEGER()}, VARCHAR()); @@ -617,8 +615,7 @@ TEST(SignatureBinderTest, variableArity) { { auto signature = exec::FunctionSignatureBuilder() .returnType("varchar") - .argumentType("any") - .variableArity() + .variableArity("any") .build(); testSignatureBinder(signature, {}, VARCHAR()); @@ -633,8 +630,7 @@ TEST(SignatureBinderTest, variableArity) { auto signature = exec::FunctionSignatureBuilder() .returnType("timestamp") .argumentType("integer") - .argumentType("any") - .variableArity() + .variableArity("any") .build(); testSignatureBinder(signature, {INTEGER()}, TIMESTAMP()); @@ -683,8 +679,7 @@ TEST(SignatureBinderTest, unresolvable) { { auto signature = exec::FunctionSignatureBuilder() .returnType("varchar") - .argumentType("integer") - .variableArity() + .variableArity("integer") .build(); // wrong type diff --git a/velox/functions/lib/MapConcat.cpp b/velox/functions/lib/MapConcat.cpp index aac38fbc93154..c11b9ae19579f 100644 --- a/velox/functions/lib/MapConcat.cpp +++ b/velox/functions/lib/MapConcat.cpp @@ -161,8 +161,7 @@ class MapConcatFunction : public exec::VectorFunction { .typeVariable("V") .returnType("map(K,V)") .argumentType("map(K,V)") - .argumentType("map(K,V)") - .variableArity() + .variableArity("map(K,V)") .build()}; } }; diff --git a/velox/functions/prestosql/ArrayConstructor.cpp b/velox/functions/prestosql/ArrayConstructor.cpp index b6aa3bc80b54c..3dccc36707eb6 100644 --- a/velox/functions/prestosql/ArrayConstructor.cpp +++ b/velox/functions/prestosql/ArrayConstructor.cpp @@ -113,8 +113,7 @@ class ArrayConstructor : public exec::VectorFunction { exec::FunctionSignatureBuilder() .typeVariable("T") .returnType("array(T)") - .argumentType("T") - .variableArity() + .variableArity("T") .build(), }; } diff --git a/velox/functions/prestosql/StringFunctions.cpp b/velox/functions/prestosql/StringFunctions.cpp index 60d22e5e9a450..a90a0ee7e62d4 100644 --- a/velox/functions/prestosql/StringFunctions.cpp +++ b/velox/functions/prestosql/StringFunctions.cpp @@ -257,15 +257,13 @@ class ConcatFunction : public exec::VectorFunction { exec::FunctionSignatureBuilder() .returnType("varchar") .argumentType("varchar") - .argumentType("varchar") - .variableArity() + .variableArity("varchar") .build(), // varbinary, varbinary,.. -> varbinary exec::FunctionSignatureBuilder() .returnType("varbinary") .argumentType("varbinary") - .argumentType("varbinary") - .variableArity() + .variableArity("varbinary") .build(), }; } diff --git a/velox/functions/sparksql/Hash.cpp b/velox/functions/sparksql/Hash.cpp index 81fd319b2d599..92e14a70830ad 100644 --- a/velox/functions/sparksql/Hash.cpp +++ b/velox/functions/sparksql/Hash.cpp @@ -717,8 +717,7 @@ void checkArgTypes(const std::vector& args) { std::vector> hashSignatures() { return {exec::FunctionSignatureBuilder() .returnType("integer") - .argumentType("any") - .variableArity() + .variableArity("any") .build()}; } @@ -748,16 +747,14 @@ std::vector> hashWithSeedSignatures() { return {exec::FunctionSignatureBuilder() .returnType("integer") .constantArgumentType("integer") - .argumentType("any") - .variableArity() + .variableArity("any") .build()}; } std::vector> xxhash64Signatures() { return {exec::FunctionSignatureBuilder() .returnType("bigint") - .argumentType("any") - .variableArity() + .variableArity("any") .build()}; } @@ -766,8 +763,7 @@ xxhash64WithSeedSignatures() { return {exec::FunctionSignatureBuilder() .returnType("bigint") .constantArgumentType("bigint") - .argumentType("any") - .variableArity() + .variableArity("any") .build()}; } diff --git a/velox/functions/sparksql/LeastGreatest.cpp b/velox/functions/sparksql/LeastGreatest.cpp index c822bbda97e9a..24a77b0c8753e 100644 --- a/velox/functions/sparksql/LeastGreatest.cpp +++ b/velox/functions/sparksql/LeastGreatest.cpp @@ -152,8 +152,7 @@ std::vector> leastSignatures() { signatures.emplace_back(exec::FunctionSignatureBuilder() .returnType(type) .argumentType(type) - .argumentType(type) - .variableArity() + .variableArity(type) .build()); } signatures.emplace_back(exec::FunctionSignatureBuilder() @@ -161,8 +160,7 @@ std::vector> leastSignatures() { .integerVariable("s") .returnType("decimal(p,s)") .argumentType("decimal(p,s)") - .argumentType("decimal(p,s)") - .variableArity() + .variableArity("decimal(p,s)") .build()); return signatures; } diff --git a/velox/functions/tests/FunctionRegistryTest.cpp b/velox/functions/tests/FunctionRegistryTest.cpp index be34bb5bc3b79..6c10e18dc92d9 100644 --- a/velox/functions/tests/FunctionRegistryTest.cpp +++ b/velox/functions/tests/FunctionRegistryTest.cpp @@ -351,8 +351,7 @@ TEST_F(FunctionRegistryTest, getFunctionSignatures) { functionSignatures["variadic_func"].at(0)->toString(), exec::FunctionSignatureBuilder() .returnType("varchar") - .argumentType("varchar") - .variableArity() + .variableArity("varchar") .build() ->toString());