You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "zzzzzzzs (via GitHub)" <gi...@apache.org> on 2023/03/31 12:05:35 UTC

[GitHub] [flink] zzzzzzzs commented on a diff in pull request #20342: [FLINK-26939][Table SQL/API] Add TRANSLATE supported in SQL & Table API

zzzzzzzs commented on code in PR #20342:
URL: https://github.com/apache/flink/pull/20342#discussion_r1154393863


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java:
##########
@@ -371,6 +371,11 @@ public static String repeat(String str, int repeat) {
         return EncodingUtils.repeat(str, repeat);
     }
 
+    /** Returns an expr where all characters in from have been replaced with those in to. */
+    public static String translate3(String str, String search, String replacement) {
+        return org.apache.commons.lang3.StringUtils.replaceChars(str, search, replacement);

Review Comment:
   StringUtils#replaceChars replaces a set of characters with a single character, while SqlFunctionUtils#replace replaces a substring with another string.
   example:
   ``` java
   String replaced = StringUtils.replaceChars("AaBbCc", "abc", "123");
   System.out.println(replaced); // "A1B2C3"
   String replaced = SqlFunctionUtils.replace("AaBbCc", "abc", "123");
   System.out.println(replaced1); // "AaBbCc"
   ```
   To meet the functionality requirements of Hive or Spark, it is necessary to use StringUtils#replaceChars. This is also the approach taken in Calcite.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org