Skip to content

Commit

Permalink
Make concat function throw when there are less than 2 arguments (face…
Browse files Browse the repository at this point in the history
…bookincubator#11076)

Summary:
Pull Request resolved: facebookincubator#11076

Currently, the velox concat function handles having a single argument by returning the argument as the result. Presto throws an exception, so velox should as well.

This change was made before and had to be backed out due to failing XStream pipelines. XStream A/B test in ga and f3 have been verified to succeed this time.

Reviewed By: kevinwilfong

Differential Revision: D63271129

fbshipit-source-id: 60afd7821aa8b49707a9d6c8f0b5421a006a60b6
  • Loading branch information
Daniel Hunte authored and facebook-github-bot committed Sep 25, 2024
1 parent 451825e commit 5a6a744
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions velox/expression/FunctionSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class FunctionSignatureBuilder {
return *this;
}

/// Variable arity arguments can appear only at the end of the argument list
/// and their types must match the type specified in the last entry of
/// 'argumentTypes'. Variable arity arguments can appear zero or more times.
FunctionSignatureBuilder& variableArity() {
variableArity_ = true;
return *this;
Expand Down
4 changes: 1 addition & 3 deletions velox/expression/tests/ExprCompilerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ TEST_F(ExprCompilerTest, functionSignatureNotRegistered) {

VELOX_ASSERT_THROW(
compile(expression),
"Scalar function concat not registered with arguments: (BIGINT, BIGINT). "
"Found function registered with the following signatures:\n"
"((varchar,varchar...) -> varchar)");
"Scalar function concat not registered with arguments: (BIGINT, BIGINT)");
}

TEST_F(ExprCompilerTest, constantFromFlatVector) {
Expand Down
2 changes: 2 additions & 0 deletions velox/functions/prestosql/StringFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,14 @@ class ConcatFunction : public exec::VectorFunction {
exec::FunctionSignatureBuilder()
.returnType("varchar")
.argumentType("varchar")
.argumentType("varchar")
.variableArity("varchar")
.build(),
// varbinary, varbinary,.. -> varbinary
exec::FunctionSignatureBuilder()
.returnType("varbinary")
.argumentType("varbinary")
.argumentType("varbinary")
.variableArity("varbinary")
.build(),
};
Expand Down
9 changes: 8 additions & 1 deletion velox/functions/prestosql/tests/StringFunctionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ TEST_F(StringFunctionsTest, concat) {
size_t maxStringLength = 100;

std::vector<std::vector<std::string>> inputTable;
for (int argsCount = 1; argsCount <= maxArgsCount; argsCount++) {
for (int argsCount = 2; argsCount <= maxArgsCount; argsCount++) {
inputTable.clear();

// Create table with argsCount columns
Expand Down Expand Up @@ -930,6 +930,13 @@ TEST_F(StringFunctionsTest, concat) {

test::assertEqualVectors(expected, result);
}

// Less than 2 concatenation arguments throws exception.
{
VELOX_ASSERT_THROW(
evaluateOnce<std::string>("concat('a')", {}),
"Scalar function signature is not supported: concat(VARCHAR).");
}
}

TEST_F(StringFunctionsTest, concatVarbinary) {
Expand Down

0 comments on commit 5a6a744

Please sign in to comment.