You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/03/08 09:58:25 UTC

[GitHub] [incubator-seatunnel] simon824 opened a new pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

simon824 opened a new pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442


   
   ## Purpose of this pull request
   
   closed #1441
   The dateTime substitute in connectors is using `org.apache.commons.lang3.text.StrSubstitutor` ,but flinksql variable substitute in config is using `replaceAll`, we can implement in a unified function.
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in you PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/developement/NewLicenseGuide.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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



[GitHub] [incubator-seatunnel] yx91490 commented on a change in pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

Posted by GitBox <gi...@apache.org>.
yx91490 commented on a change in pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442#discussion_r821664110



##########
File path: seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/VariablesSubstitute.java
##########
@@ -25,25 +25,23 @@
 import java.util.Map;
 import java.util.UUID;
 
-public final class StringTemplate {

Review comment:
       I don't suggest to change Class name, seatuunel-apis depend on it, so we should keep it stable and compatible.




-- 
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: commits-unsubscribe@seatunnel.apache.org

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



[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on a change in pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442#discussion_r827163386



##########
File path: seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/StringTemplate.java
##########
@@ -17,35 +17,17 @@
 
 package org.apache.seatunnel.common.utils;
 
-import org.apache.commons.lang3.text.StrSubstitutor;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
+/**
+ * please using {@link VariablesSubstitute} instead, since 2.0.5
+ */
+@Deprecated
 public final class StringTemplate {
 
     private StringTemplate() {
     }
 
-    /**
-     * @param str        raw string
-     * @param timeFormat example : "yyyy-MM-dd HH:mm:ss"
-     * @return replaced string
-     */
     public static String substitute(String str, String timeFormat) {
-
-        final SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
-        final String formattedDate = sdf.format(new Date());
-
-        final Map<String, String> valuesMap = new HashMap<>(3);
-        valuesMap.put("uuid", UUID.randomUUID().toString());
-        valuesMap.put("now", formattedDate);
-        valuesMap.put(timeFormat, formattedDate);
-        final StrSubstitutor sub = new StrSubstitutor(valuesMap);
-        return sub.replace(str);
+        return VariablesSubstitute.substitute(str, timeFormat);

Review comment:
       It's better to use DateTimeFormatter, we can't guarantee what kind of scenarios this will be used in later, but DateTimeFormatter is a better choice than SimpleDateFormat.
   btw,All public methods should have corresponding java doc added




-- 
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: commits-unsubscribe@seatunnel.apache.org

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



[GitHub] [incubator-seatunnel] wuchunfu commented on pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442#issuecomment-1068657903


   looks good


-- 
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: commits-unsubscribe@seatunnel.apache.org

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



[GitHub] [incubator-seatunnel] simon824 commented on a change in pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

Posted by GitBox <gi...@apache.org>.
simon824 commented on a change in pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442#discussion_r822211854



##########
File path: seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/VariablesSubstitute.java
##########
@@ -25,25 +25,23 @@
 import java.util.Map;
 import java.util.UUID;
 
-public final class StringTemplate {

Review comment:
       make sense




-- 
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: commits-unsubscribe@seatunnel.apache.org

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



[GitHub] [incubator-seatunnel] simon824 commented on a change in pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

Posted by GitBox <gi...@apache.org>.
simon824 commented on a change in pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442#discussion_r827537728



##########
File path: seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/StringTemplate.java
##########
@@ -17,35 +17,17 @@
 
 package org.apache.seatunnel.common.utils;
 
-import org.apache.commons.lang3.text.StrSubstitutor;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
+/**
+ * please using {@link VariablesSubstitute} instead, since 2.0.5
+ */
+@Deprecated
 public final class StringTemplate {
 
     private StringTemplate() {
     }
 
-    /**
-     * @param str        raw string
-     * @param timeFormat example : "yyyy-MM-dd HH:mm:ss"
-     * @return replaced string
-     */
     public static String substitute(String str, String timeFormat) {
-
-        final SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
-        final String formattedDate = sdf.format(new Date());
-
-        final Map<String, String> valuesMap = new HashMap<>(3);
-        valuesMap.put("uuid", UUID.randomUUID().toString());
-        valuesMap.put("now", formattedDate);
-        valuesMap.put(timeFormat, formattedDate);
-        final StrSubstitutor sub = new StrSubstitutor(valuesMap);
-        return sub.replace(str);
+        return VariablesSubstitute.substitute(str, timeFormat);

Review comment:
       Updated, thanks.




-- 
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: commits-unsubscribe@seatunnel.apache.org

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



[GitHub] [incubator-seatunnel] CalvinKirs merged pull request #1442: [Improve][Config] Refactor StringTemplate to unify variables substitute util

Posted by GitBox <gi...@apache.org>.
CalvinKirs merged pull request #1442:
URL: https://github.com/apache/incubator-seatunnel/pull/1442


   


-- 
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: commits-unsubscribe@seatunnel.apache.org

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