Skip to content

Commit c1a6d6a

Browse files
JkSelfyma11
authored andcommitted
Rename presto 'replace' function to 'presto_replace' to avoid confliction (workaround of 4922)
1 parent 35a9fce commit c1a6d6a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

velox/functions/prestosql/registration/StringFunctionsRegistration.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ void registerStringFunctions(const std::string& prefix) {
102102
Varchar,
103103
Varchar>({prefix + "split_to_map"});
104104
VELOX_REGISTER_VECTOR_FUNCTION(udf_concat, prefix + "concat");
105-
VELOX_REGISTER_VECTOR_FUNCTION(udf_replace, prefix + "replace");
105+
// In Gluten, presto 'replace' function is conflict with sparksql, because
106+
// presto 'replace' is registered as VectorFunction, and spark 'replace' is
107+
// registered as SimpleFunction. Velox respect VectorFunction first.
108+
VELOX_REGISTER_VECTOR_FUNCTION(udf_replace, prefix + "presto_replace");
106109
VELOX_REGISTER_VECTOR_FUNCTION(udf_reverse, prefix + "reverse");
107110
VELOX_REGISTER_VECTOR_FUNCTION(udf_to_utf8, prefix + "to_utf8");
108111
VELOX_REGISTER_VECTOR_FUNCTION(udf_from_utf8, prefix + "from_utf8");

velox/functions/prestosql/tests/StringFunctionsTest.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ void StringFunctionsTest::testReplaceInPlace(
12301230
};
12311231

12321232
auto result = evaluate<FlatVector<StringView>>(
1233-
fmt::format("replace(c0, '{}', '{}')", search, replace),
1233+
fmt::format("presto_replace(c0, '{}', '{}')", search, replace),
12341234
makeRowVector({makeInput()}));
12351235
testResults(result.get());
12361236

@@ -1239,8 +1239,8 @@ void StringFunctionsTest::testReplaceInPlace(
12391239
auto applyReplaceFunction = [&](std::vector<VectorPtr>& functionInputs,
12401240
VectorPtr& resultPtr) {
12411241
core::QueryConfig config({});
1242-
auto replaceFunction =
1243-
exec::getVectorFunction("replace", {VARCHAR(), VARCHAR()}, {}, config);
1242+
auto replaceFunction = exec::getVectorFunction(
1243+
"presto_replace", {VARCHAR(), VARCHAR()}, {}, config);
12441244
SelectivityVector rows(tests.size());
12451245
ExprSet exprSet({}, &execCtx_);
12461246
RowVectorPtr inputRows = makeRowVector({});
@@ -1285,11 +1285,11 @@ void StringFunctionsTest::testReplaceFlatVector(
12851285

12861286
if (withReplaceArgument) {
12871287
result = evaluate<FlatVector<StringView>>(
1288-
"replace(c0, c1, c2)",
1288+
"presto_replace(c0, c1, c2)",
12891289
makeRowVector({stringVector, searchVector, replaceVector}));
12901290
} else {
12911291
result = evaluate<FlatVector<StringView>>(
1292-
"replace(c0, c1)", makeRowVector({stringVector, searchVector}));
1292+
"presto_replace(c0, c1)", makeRowVector({stringVector, searchVector}));
12931293
}
12941294

12951295
for (int32_t i = 0; i < tests.size(); ++i) {
@@ -1331,8 +1331,8 @@ TEST_F(StringFunctionsTest, replace) {
13311331

13321332
// Test constant vectors
13331333
auto rows = makeRowVector(makeRowType({BIGINT()}), 10);
1334-
auto result =
1335-
evaluate<SimpleVector<StringView>>("replace('high', 'ig', 'f')", rows);
1334+
auto result = evaluate<SimpleVector<StringView>>(
1335+
"presto_replace('high', 'ig', 'f')", rows);
13361336
for (int i = 0; i < 10; ++i) {
13371337
EXPECT_EQ(result->valueAt(i), StringView("hfh"));
13381338
}
@@ -1351,7 +1351,8 @@ TEST_F(StringFunctionsTest, replaceWithReusableInputButNoInplace) {
13511351
[](vector_size_t) { return 2851588633; },
13521352
[](auto row) { return row >= 50; });
13531353
auto result = evaluateSimplified<FlatVector<StringView>>(
1354-
"substr(replace('bar', rtrim(c0)), c1, c2)", makeRowVector({c0, c1, c2}));
1354+
"substr(presto_replace('bar', rtrim(c0)), c1, c2)",
1355+
makeRowVector({c0, c1, c2}));
13551356
ASSERT_EQ(result->size(), 100);
13561357
for (int i = 0; i < 50; ++i) {
13571358
EXPECT_FALSE(result->isNullAt(i));

0 commit comments

Comments
 (0)