From 1f6b3754563a4e31f1d8e633cd7f1f189411b9c3 Mon Sep 17 00:00:00 2001 From: Guibo Pan Date: Tue, 21 Aug 2018 17:34:41 +0800 Subject: [PATCH] [FLINK-10145][table] Add replace supported in TableAPI and SQL Change-Id: Ibeb0e1bf2cc68bb3cfeb6ab7c1f7d791096d017b --- docs/dev/table/functions.md | 18 +++++++++--------- .../functions/sql/ScalarSqlFunctions.scala | 1 - .../runtime/functions/ScalarFunctions.scala | 11 ----------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/docs/dev/table/functions.md b/docs/dev/table/functions.md index 9813119fbecd4..0046572739979 100644 --- a/docs/dev/table/functions.md +++ b/docs/dev/table/functions.md @@ -2451,12 +2451,12 @@ SUBSTRING(string FROM integer1 [ FOR integer2 ]) {% highlight text %} -REPLACE(string, search, replacement) +REPLACE(string1, string2, string3) {% endhighlight %} -

Returns a new string from string replaced search(non-overlapping) with replacement.

-

E.g., REPLACE("hello world", "world", "flink") returns "hello flink"; REPLACE("ababab", "abab", "z") returns "zab"

+

Returns a new string which replaces string2 with string3 (non-overlapping) from string1

+

E.g., REPLACE("hello world", "world", "flink") returns "hello flink"; REPLACE("ababab", "abab", "z") returns "zab".

@@ -2703,12 +2703,12 @@ STRING.substring(INT1, INT2) {% highlight java %} -STRING.replace(STRING1, STRING2) +STRING1.replace(STRING2, STRING3) {% endhighlight %} -

Returns a new string from STRING replaced STRING1(non-overlapping) with STRING2.

-

E.g., "hello world".replace("world", "flink") returns "hello flink"; "ababab".replace("abab", "z") returns "zab"

+

Returns a new string which replaces STRING2 with STRING3 (non-overlapping) from STRING1.

+

E.g., 'hello world'.replace('world', 'flink') returns 'hello flink'; 'ababab'.replace('abab', 'z') returns 'zab'.

@@ -2954,12 +2954,12 @@ STRING.substring(INT1, INT2) {% highlight scala %} -STRING.replace(STRING1, STRING2) +STRING1.replace(STRING2, STRING3) {% endhighlight %} -

Returns a new string from STRING replaced STRING1(non-overlapping) with STRING2.

-

E.g., "hello world".replace("world", "flink") returns "hello flink"; "ababab".replace("abab", "z") returns "zab"

+

Returns a new string which replaces STRING2 with STRING3 (non-overlapping) from STRING1.

+

E.g., "hello world".replace("world", "flink") returns "hello flink"; "ababab".replace("abab", "z") returns "zab".

diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala index 2f597743047f9..249eb8a8840fa 100644 --- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala +++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala @@ -67,7 +67,6 @@ object ScalarSqlFunctions { OperandTypes.ONE_OR_MORE, SqlFunctionCategory.STRING) - val LOG = new SqlFunction( "LOG", SqlKind.OTHER_FUNCTION, diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala index a6225bbd988c4..001fb98538a44 100644 --- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala +++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala @@ -95,17 +95,6 @@ object ScalarFunctions { sb.toString } - /** - * Returns the string str with all non-overlapping occurrences - * of search replaced with replacement. - */ - def replace(str: String, search: String, replacement: String): String = { - if (str == null || search == null || replacement == null) { - return null - } - str.replace(search, replacement) - } - /** * Returns the natural logarithm of "x". */