diff --git a/velox/functions/prestosql/registration/StringFunctionsRegistration.cpp b/velox/functions/prestosql/registration/StringFunctionsRegistration.cpp index f1e36049e92d..9420be9c7fca 100644 --- a/velox/functions/prestosql/registration/StringFunctionsRegistration.cpp +++ b/velox/functions/prestosql/registration/StringFunctionsRegistration.cpp @@ -104,7 +104,10 @@ void registerStringFunctions(const std::string& prefix) { Varchar, Varchar>({prefix + "split_to_map"}); VELOX_REGISTER_VECTOR_FUNCTION(udf_concat, prefix + "concat"); - VELOX_REGISTER_VECTOR_FUNCTION(udf_replace, prefix + "replace"); + // In Gluten, presto 'replace' function is conflict with sparksql, because + // presto 'replace' is registered as VectorFunction, and spark 'replace' is + // registered as SimpleFunction. Velox respect VectorFunction first. + VELOX_REGISTER_VECTOR_FUNCTION(udf_replace, prefix + "presto_replace"); VELOX_REGISTER_VECTOR_FUNCTION(udf_reverse, prefix + "reverse"); VELOX_REGISTER_VECTOR_FUNCTION(udf_to_utf8, prefix + "to_utf8"); VELOX_REGISTER_VECTOR_FUNCTION(udf_from_utf8, prefix + "from_utf8"); diff --git a/velox/functions/prestosql/tests/StringFunctionsTest.cpp b/velox/functions/prestosql/tests/StringFunctionsTest.cpp index 3df9a96a00cb..e451734c7172 100644 --- a/velox/functions/prestosql/tests/StringFunctionsTest.cpp +++ b/velox/functions/prestosql/tests/StringFunctionsTest.cpp @@ -1230,7 +1230,7 @@ void StringFunctionsTest::testReplaceInPlace( }; auto result = evaluate>( - fmt::format("replace(c0, '{}', '{}')", search, replace), + fmt::format("presto_replace(c0, '{}', '{}')", search, replace), makeRowVector({makeInput()})); testResults(result.get()); @@ -1239,8 +1239,8 @@ void StringFunctionsTest::testReplaceInPlace( auto applyReplaceFunction = [&](std::vector& functionInputs, VectorPtr& resultPtr) { core::QueryConfig config({}); - auto replaceFunction = - exec::getVectorFunction("replace", {VARCHAR(), VARCHAR()}, {}, config); + auto replaceFunction = exec::getVectorFunction( + "presto_replace", {VARCHAR(), VARCHAR()}, {}, config); SelectivityVector rows(tests.size()); ExprSet exprSet({}, &execCtx_); RowVectorPtr inputRows = makeRowVector({}); @@ -1285,11 +1285,11 @@ void StringFunctionsTest::testReplaceFlatVector( if (withReplaceArgument) { result = evaluate>( - "replace(c0, c1, c2)", + "presto_replace(c0, c1, c2)", makeRowVector({stringVector, searchVector, replaceVector})); } else { result = evaluate>( - "replace(c0, c1)", makeRowVector({stringVector, searchVector})); + "presto_replace(c0, c1)", makeRowVector({stringVector, searchVector})); } for (int32_t i = 0; i < tests.size(); ++i) { @@ -1331,8 +1331,8 @@ TEST_F(StringFunctionsTest, replace) { // Test constant vectors auto rows = makeRowVector(makeRowType({BIGINT()}), 10); - auto result = - evaluate>("replace('high', 'ig', 'f')", rows); + auto result = evaluate>( + "presto_replace('high', 'ig', 'f')", rows); for (int i = 0; i < 10; ++i) { EXPECT_EQ(result->valueAt(i), StringView("hfh")); } @@ -1351,7 +1351,8 @@ TEST_F(StringFunctionsTest, replaceWithReusableInputButNoInplace) { [](vector_size_t) { return 2851588633; }, [](auto row) { return row >= 50; }); auto result = evaluateSimplified>( - "substr(replace('bar', rtrim(c0)), c1, c2)", makeRowVector({c0, c1, c2})); + "substr(presto_replace('bar', rtrim(c0)), c1, c2)", + makeRowVector({c0, c1, c2})); ASSERT_EQ(result->size(), 100); for (int i = 0; i < 50; ++i) { EXPECT_FALSE(result->isNullAt(i));