You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "aiwenmo (via GitHub)" <gi...@apache.org> on 2024/07/02 17:10:18 UTC

[PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

aiwenmo opened a new pull request, #3449:
URL: https://github.com/apache/flink-cdc/pull/3449

   This closes [FLINK-35743](https://issues.apache.org/jira/browse/FLINK-35743).


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1704771418


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/JaninoCompiler.java:
##########
@@ -300,7 +315,19 @@ private static Java.Rvalue generateOtherFunctionOperation(
         }
     }
 
-    private static Java.Rvalue generateNoOperandTimestampFunctionOperation(String operationName) {
+    private static Java.Rvalue generateTimezoneFreeTemporalFunctionOperation(String operationName) {
+        List<Java.Rvalue> timestampFunctionParam = new ArrayList<>();
+        timestampFunctionParam.add(
+                new Java.AmbiguousName(Location.NOWHERE, new String[] {DEFAULT_EPOCH_TIME}));
+        return new Java.MethodInvocation(
+                Location.NOWHERE,
+                null,
+                StringUtils.convertToCamelCase(operationName),
+                timestampFunctionParam.toArray(new Java.Rvalue[0]));

Review Comment:
   I wonder if is it necessary to initialize `timestampFunctionParam` here, since it seems did the same thing:
   
   ```java
   new Java.Rvalue[] {
       new Java.AmbiguousName(Location.NOWHERE, new String[] {
           DEFAULT_EPOCH_TIME
       })
   }
   ```



##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/JaninoCompiler.java:
##########
@@ -313,6 +340,27 @@ private static Java.Rvalue generateNoOperandTimestampFunctionOperation(String op
                 timestampFunctionParam.toArray(new Java.Rvalue[0]));
     }
 
+    private static Java.Rvalue generateTimezoneFreeTemporalConversionFunctionOperation(
+            String operationName) {
+        return new Java.MethodInvocation(
+                Location.NOWHERE,
+                null,
+                StringUtils.convertToCamelCase(operationName),
+                new ArrayList<>().toArray(new Java.Rvalue[0]));

Review Comment:
   ```suggestion
                   new Java.Rvalue[0]);
   ```



##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/JaninoCompiler.java:
##########
@@ -359,6 +407,15 @@ private static Java.Rvalue generateTypeConvertMethod(
             case "VARCHAR":
             case "STRING":
                 return new Java.MethodInvocation(Location.NOWHERE, null, "castToString", atoms);
+            case "TIMESTAMP":
+                List<Java.Rvalue> timestampFunctionParam = new ArrayList<>(Arrays.asList(atoms));
+                timestampFunctionParam.add(
+                        new Java.AmbiguousName(Location.NOWHERE, new String[] {DEFAULT_TIME_ZONE}));
+                return new Java.MethodInvocation(
+                        Location.NOWHERE,
+                        null,
+                        "castToTimestamp",
+                        timestampFunctionParam.toArray(new Java.Rvalue[0]));

Review Comment:
   I remember that there's a `ArrayUtils#add(T[], T)` method in Apache commons that doesn't require initializing mutable lists and keeps code clearer. Is it possible to use it here?



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2235283994

   > Considering this fixes timezone functions' incorrect behavior, should this be merged before 3.2 release? @leonardBang
   
   +1 to merge this before 3.2 release


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "aiwenmo (via GitHub)" <gi...@apache.org>.
aiwenmo commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2261821796

   thx. I will add more test.


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1705038132


##########
flink-cdc-runtime/src/test/java/org/apache/flink/cdc/runtime/parser/TransformParserTest.java:
##########
@@ -292,6 +292,9 @@ public void testTranslateFilterToJaninoExpression() {
         testFilterExpression("cast(null as decimal)", "castToBigDecimal(null, 10, 0)");
         testFilterExpression("cast(null as char)", "castToString(null)");
         testFilterExpression("cast(null as varchar)", "castToString(null)");
+        testFilterExpression(
+                "cast(CURRENT_TIMESTAMP as TIMESTAMP)", "castToTimestamp(__time_zone__)");
+        testFilterExpression("cast(dt as TIMESTAMP)", "castToTimestamp(__time_zone__)");

Review Comment:
   sorry, I forgot update here, fix it soon



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2270319084

   Sure, thanks for @aiwenmo's work so far, I'll create a patch for this.


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1663358098


##########
flink-cdc-runtime/src/test/java/org/apache/flink/cdc/runtime/operators/transform/TransformDataOperatorTest.java:
##########


Review Comment:
   I could still reproduce `testTimestampDiffTransform` failure when testing time was set to June 1st 04:00. Seems month and year diff will not be 0 when 8 hours gap crossed month / year boundaries, where the output would be `-28800, -480, -8, 0, [0 or -1], [0 or -1]`.



##########
flink-cdc-runtime/src/test/java/org/apache/flink/cdc/runtime/operators/transform/TransformDataOperatorTest.java:
##########
@@ -553,6 +562,26 @@ void testTimestampDiffTransform() throws Exception {
         Assertions.assertThat(
                         transformFunctionEventEventOperatorTestHarness.getOutputRecords().poll())
                 .isEqualTo(new StreamRecord<>(insertEventExpect));
+
+        DataChangeEvent insertEvent2 =
+                DataChangeEvent.insertEvent(
+                        TIMESTAMPDIFF_TABLEID,
+                        recordDataGenerator.generate(
+                                new Object[] {
+                                    new BinaryStringData("2"), null, null, null, null, null, null
+                                }));
+        DataChangeEvent insertEventExpect2 =
+                DataChangeEvent.insertEvent(
+                        TIMESTAMPDIFF_TABLEID,
+                        recordDataGenerator.generate(
+                                new Object[] {
+                                    new BinaryStringData("2"), -28800, -480, -8, 0, 0, 0

Review Comment:
   Ditto.



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "aiwenmo (via GitHub)" <gi...@apache.org>.
aiwenmo commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1704333378


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/JaninoCompiler.java:
##########
@@ -359,6 +407,15 @@ private static Java.Rvalue generateTypeConvertMethod(
             case "VARCHAR":
             case "STRING":
                 return new Java.MethodInvocation(Location.NOWHERE, null, "castToString", atoms);
+            case "TIMESTAMP":
+                List<Java.Rvalue> timestampFunctionParam = new ArrayList<>(Arrays.asList(atoms));

Review Comment:
   Do we need to add tests for `cast( ... as timestamp)` ?



##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/functions/SystemFunctionUtils.java:
##########
@@ -38,65 +41,62 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static org.apache.flink.cdc.common.utils.DateTimeUtils.timestampMillisToDate;
+import static org.apache.flink.cdc.common.utils.DateTimeUtils.timestampMillisToTime;
+
 /** System function utils to support the call of flink cdc pipeline transform. */
 public class SystemFunctionUtils {
-    private static final Logger LOG = LoggerFactory.getLogger(SystemFunctionUtils.class);
 
-    public static int localtime(long epochTime, String timezone) {
-        return DateTimeUtils.timestampMillisToTime(epochTime);
-    }
+    private static final Logger LOG = LoggerFactory.getLogger(SystemFunctionUtils.class);
 
-    public static TimestampData localtimestamp(long epochTime, String timezone) {
-        return TimestampData.fromMillis(epochTime);
+    public static LocalZonedTimestampData currentTimestamp(long epochTime) {
+        return LocalZonedTimestampData.fromEpochMillis(epochTime);
     }
 
-    // synonym: localtime
-    public static int currentTime(long epochTime, String timezone) {
-        return localtime(epochTime, timezone);
+    // synonym with currentTimestamp
+    public static LocalZonedTimestampData now(long epochTime) {
+        return LocalZonedTimestampData.fromEpochMillis(epochTime);
     }
 
-    public static int currentDate(long epochTime, String timezone) {
-        return DateTimeUtils.timestampMillisToDate(epochTime);
+    public static TimestampData localtimestamp(long epochTime, String timezone) {
+        return TimestampData.fromLocalDateTime(
+                Instant.ofEpochMilli(epochTime).atZone(ZoneId.of(timezone)).toLocalDateTime());
     }
 
-    public static TimestampData currentTimestamp(long epochTime, String timezone) {
-        return TimestampData.fromMillis(
-                epochTime + TimeZone.getTimeZone(timezone).getOffset(epochTime));
+    public static int localtime(long epochTime, String timezone) {
+        return timestampMillisToTime(localtimestamp(epochTime, timezone).getMillisecond());
     }
 
-    public static LocalZonedTimestampData now(long epochTime, String timezone) {
-        return LocalZonedTimestampData.fromEpochMillis(epochTime);
+    public static int currentTime(long epochTime, String timezone) {
+        // the time value of currentTimestamp under given session time zone
+        return timestampMillisToTime(localtimestamp(epochTime, timezone).getMillisecond());
     }
 
-    public static String dateFormat(LocalZonedTimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getEpochMillisecond()));
+    public static int currentDate(long epochTime, String timezone) {
+        // the date value of currentTimestamp under given session time zone
+        return timestampMillisToDate(localtimestamp(epochTime, timezone).getMillisecond());
     }
 
     public static String dateFormat(TimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getMillisecond()));
-    }
-
-    public static String dateFormat(ZonedTimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getMillisecond()));
+        return DateTimeUtils.formatTimestampMillis(
+                timestamp.getMillisecond(), format, TimeZone.getTimeZone("UTC"));

Review Comment:
   Does it not require timezone to participate in calculations?



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1704843120


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/JaninoCompiler.java:
##########
@@ -359,6 +407,15 @@ private static Java.Rvalue generateTypeConvertMethod(
             case "VARCHAR":
             case "STRING":
                 return new Java.MethodInvocation(Location.NOWHERE, null, "castToString", atoms);
+            case "TIMESTAMP":
+                List<Java.Rvalue> timestampFunctionParam = new ArrayList<>(Arrays.asList(atoms));

Review Comment:
   +1, I’ll add test to cover this



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2271237005

   Seems CI is failing since ValuesDatabase is trying to deserialize every RecordData as STRINGs.


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1699834398


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/functions/SystemFunctionUtils.java:
##########
@@ -64,22 +64,23 @@ public static TimestampData currentTimestamp(long epochTime, String timezone) {
     }
 
     public static LocalZonedTimestampData now(long epochTime, String timezone) {
-        return LocalZonedTimestampData.fromEpochMillis(epochTime);
+        return LocalZonedTimestampData.fromEpochMillis(
+                epochTime + TimeZone.getTimeZone(timezone).getOffset(epochTime));

Review Comment:
   `LocalZonedTimestampData` is not related to TimeZone IIUC



##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/functions/SystemFunctionUtils.java:
##########
@@ -64,22 +64,23 @@ public static TimestampData currentTimestamp(long epochTime, String timezone) {
     }
 
     public static LocalZonedTimestampData now(long epochTime, String timezone) {
-        return LocalZonedTimestampData.fromEpochMillis(epochTime);
+        return LocalZonedTimestampData.fromEpochMillis(
+                epochTime + TimeZone.getTimeZone(timezone).getOffset(epochTime));
     }
 
     public static String dateFormat(LocalZonedTimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getEpochMillisecond()));
+        return DateTimeUtils.formatTimestampMillis(
+                timestamp.getEpochMillisecond(), format, TimeZone.getTimeZone("GMT"));

Review Comment:
   Could you use “UTC” instead of "GMT" as later is deprecated?



##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/functions/SystemFunctionUtils.java:
##########
@@ -64,22 +64,23 @@ public static TimestampData currentTimestamp(long epochTime, String timezone) {
     }
 
     public static LocalZonedTimestampData now(long epochTime, String timezone) {
-        return LocalZonedTimestampData.fromEpochMillis(epochTime);
+        return LocalZonedTimestampData.fromEpochMillis(
+                epochTime + TimeZone.getTimeZone(timezone).getOffset(epochTime));
     }
 
     public static String dateFormat(LocalZonedTimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getEpochMillisecond()));
+        return DateTimeUtils.formatTimestampMillis(
+                timestamp.getEpochMillisecond(), format, TimeZone.getTimeZone("GMT"));
     }
 
     public static String dateFormat(TimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getMillisecond()));
+        return DateTimeUtils.formatTimestampMillis(
+                timestamp.getMillisecond(), format, TimeZone.getTimeZone("GMT"));
     }
 
     public static String dateFormat(ZonedTimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getMillisecond()));
+        return DateTimeUtils.formatTimestampMillis(
+                timestamp.getMillisecond(), format, TimeZone.getTimeZone("GMT"));
     }

Review Comment:
   plz use UTC



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1704843782


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/functions/SystemFunctionUtils.java:
##########
@@ -38,65 +41,62 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static org.apache.flink.cdc.common.utils.DateTimeUtils.timestampMillisToDate;
+import static org.apache.flink.cdc.common.utils.DateTimeUtils.timestampMillisToTime;
+
 /** System function utils to support the call of flink cdc pipeline transform. */
 public class SystemFunctionUtils {
-    private static final Logger LOG = LoggerFactory.getLogger(SystemFunctionUtils.class);
 
-    public static int localtime(long epochTime, String timezone) {
-        return DateTimeUtils.timestampMillisToTime(epochTime);
-    }
+    private static final Logger LOG = LoggerFactory.getLogger(SystemFunctionUtils.class);
 
-    public static TimestampData localtimestamp(long epochTime, String timezone) {
-        return TimestampData.fromMillis(epochTime);
+    public static LocalZonedTimestampData currentTimestamp(long epochTime) {
+        return LocalZonedTimestampData.fromEpochMillis(epochTime);
     }
 
-    // synonym: localtime
-    public static int currentTime(long epochTime, String timezone) {
-        return localtime(epochTime, timezone);
+    // synonym with currentTimestamp
+    public static LocalZonedTimestampData now(long epochTime) {
+        return LocalZonedTimestampData.fromEpochMillis(epochTime);
     }
 
-    public static int currentDate(long epochTime, String timezone) {
-        return DateTimeUtils.timestampMillisToDate(epochTime);
+    public static TimestampData localtimestamp(long epochTime, String timezone) {
+        return TimestampData.fromLocalDateTime(
+                Instant.ofEpochMilli(epochTime).atZone(ZoneId.of(timezone)).toLocalDateTime());
     }
 
-    public static TimestampData currentTimestamp(long epochTime, String timezone) {
-        return TimestampData.fromMillis(
-                epochTime + TimeZone.getTimeZone(timezone).getOffset(epochTime));
+    public static int localtime(long epochTime, String timezone) {
+        return timestampMillisToTime(localtimestamp(epochTime, timezone).getMillisecond());
     }
 
-    public static LocalZonedTimestampData now(long epochTime, String timezone) {
-        return LocalZonedTimestampData.fromEpochMillis(epochTime);
+    public static int currentTime(long epochTime, String timezone) {
+        // the time value of currentTimestamp under given session time zone
+        return timestampMillisToTime(localtimestamp(epochTime, timezone).getMillisecond());
     }
 
-    public static String dateFormat(LocalZonedTimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getEpochMillisecond()));
+    public static int currentDate(long epochTime, String timezone) {
+        // the date value of currentTimestamp under given session time zone
+        return timestampMillisToDate(localtimestamp(epochTime, timezone).getMillisecond());
     }
 
     public static String dateFormat(TimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getMillisecond()));
-    }
-
-    public static String dateFormat(ZonedTimestampData timestamp, String format) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
-        return dateFormat.format(new Date(timestamp.getMillisecond()));
+        return DateTimeUtils.formatTimestampMillis(
+                timestamp.getMillisecond(), format, TimeZone.getTimeZone("UTC"));

Review Comment:
   yes, TimestampData is timezone unrelated data structure. 



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2270865553

   I've added a draft integrated test case for this at my branch [here](https://github.com/yuxiqian/flink-cdc/tree/FLINK-35743-patch), but noticed something strange. Run `FlinkPipelineTransformITCase#testTransformWithTemporalFunction` reveals that:
   
   ```
   Output for manual check:
   
   CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT,`name` STRING,`age` INT,`lcl_t` TIME(0),`cur_t` TIME(0),`cur_ts` TIMESTAMP_LTZ(3),`now_ts` TIMESTAMP_LTZ(3),`lcl_ts` TIMESTAMP(3),`cur_dt` DATE}, primaryKeys=id, options=()}
   DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[1, Alice, 18, 6410611, 6410611, 2024-08-06T09:46:50.611, 2024-08-06T09:46:50.611, 2024-08-06T01:46:50.611, 19941], op=INSERT, meta=()}
   DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[2, Bob, 20, 6410818, 6410818, 2024-08-06T09:46:50.818, 2024-08-06T09:46:50.818, 2024-08-06T01:46:50.818, 19941], op=INSERT, meta=()}
   DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[2, Bob, 20, 6410819, 6410819, 2024-08-06T09:46:50.819, 2024-08-06T09:46:50.819, 2024-08-06T01:46:50.819, 19941], after=[2, Bob, 30, 6410819, 6410819, 2024-08-06T09:46:50.819, 2024-08-06T09:46:50.819, 2024-08-06T01:46:50.819, 19941], op=UPDATE, meta=()}
   CreateTableEvent{tableId=default_namespace.default_schema.mytable2, schema=columns={`id` BIGINT,`name` STRING,`age` TINYINT,`description` STRING,`lcl_t` TIME(0),`cur_t` TIME(0),`cur_ts` TIMESTAMP_LTZ(3),`now_ts` TIMESTAMP_LTZ(3),`lcl_ts` TIMESTAMP(3),`cur_dt` DATE}, primaryKeys=id, options=()}
   DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[3, Carol, 15, student, 6411969, 6411969, 2024-08-06T09:46:51.969, 2024-08-06T09:46:51.969, 2024-08-06T01:46:51.969, 19941], op=INSERT, meta=()}
   DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[4, Derrida, 25, student, 6411972, 6411972, 2024-08-06T09:46:51.972, 2024-08-06T09:46:51.972, 2024-08-06T01:46:51.972, 19941], op=INSERT, meta=()}
   DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[4, Derrida, 25, student, 6411973, 6411973, 2024-08-06T09:46:51.973, 2024-08-06T09:46:51.973, 2024-08-06T01:46:51.973, 19941], after=[], op=DELETE, meta=()}
   ```
   
   (Pipeline local time zone was set to `GMT-08:00`.)
   
   IIUC, `CURRENT_TIMESTAMP`, `NOW()`, and `LOCALTIMESTAMP` should prints out identical timestamp, since they either 1) ignores the timestamp or 2) converts internally to appears like local timestamp, but seems there's an 8 hour gap.


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2269086514

   @aiwenmo @yuxiqian I append a commit to make sure our temporal function semantics align with Flink SQL, please help review my commit


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang merged PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2235241553

   Considering this fixes timezone functions' incorrect behavior, should this be merged before 3.2 release? @leonardBang 


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "aiwenmo (via GitHub)" <gi...@apache.org>.
aiwenmo commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1705026303


##########
flink-cdc-runtime/src/test/java/org/apache/flink/cdc/runtime/parser/TransformParserTest.java:
##########
@@ -292,6 +292,9 @@ public void testTranslateFilterToJaninoExpression() {
         testFilterExpression("cast(null as decimal)", "castToBigDecimal(null, 10, 0)");
         testFilterExpression("cast(null as char)", "castToString(null)");
         testFilterExpression("cast(null as varchar)", "castToString(null)");
+        testFilterExpression(
+                "cast(CURRENT_TIMESTAMP as TIMESTAMP)", "castToTimestamp(__time_zone__)");
+        testFilterExpression("cast(dt as TIMESTAMP)", "castToTimestamp(__time_zone__)");

Review Comment:
   Expect value may be incorrect.
   ```
   castToTimestamp(currentTimestamp(__epoch_time__), __time_zone__)
   castToTimestamp(dt, __time_zone__)
   ```



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "aiwenmo (via GitHub)" <gi...@apache.org>.
aiwenmo commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2269264056

   thx. I'm reviewing it.


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "aiwenmo (via GitHub)" <gi...@apache.org>.
aiwenmo commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2270316674

   @yuxiqian Hi. I'm busy with other things. Could you add an e2e test for the temporal function?
   For example: Mysql -> Transform -> Doris/Values
   
   `projection: *,LOCALTIME as time1,CURRENT_TIME as time2,CURRENT_TIMESTAMP as timestamp1,NOW() as timestamp2,LOCALTIMESTAMP as timestamp3,CURRENT_DATE as date1`
   
   I guess the data type generated by the temporal function modified by this PR may not match the Flink type in practical use.


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2261817511

   It's August 1st again and similar CI failure is observed.


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "aiwenmo (via GitHub)" <gi...@apache.org>.
aiwenmo commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2203201015

   @yuxiqian PTAL


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2270607846

   Seems `CURRENT_TIMESTAMP AS cur_ts` still doesn't work since Calcite deduces its return type as `TIMESTAMP` instead of `TIMESTAMP_LTZ`, causing the following Janino exception:
   
   ```
   Caused by: org.apache.flink.api.common.InvalidProgramException: Expression cannot be compiled. This is a bug. Please file an issue.
   Expression: import static org.apache.flink.cdc.runtime.functions.SystemFunctionUtils.*;currentTimestamp(__epoch_time__)
   	at org.apache.flink.cdc.runtime.operators.transform.TransformExpressionCompiler.lambda$compileExpression$0(TransformExpressionCompiler.java:63)
   	at org.apache.flink.shaded.guava31.com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4868)
   	at org.apache.flink.shaded.guava31.com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3533)
   	at org.apache.flink.shaded.guava31.com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2282)
   	at org.apache.flink.shaded.guava31.com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2159)
   	at org.apache.flink.shaded.guava31.com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2049)
   	... 21 more
   Caused by: org.codehaus.commons.compiler.CompileException: Line 1, Column 107: Assignment conversion not possible from type "org.apache.flink.cdc.common.data.LocalZonedTimestampData" to type "org.apache.flink.cdc.common.data.TimestampData"
   
           ...
   ```
   
   Investigating this...


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on code in PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#discussion_r1705002901


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/JaninoCompiler.java:
##########
@@ -359,6 +407,15 @@ private static Java.Rvalue generateTypeConvertMethod(
             case "VARCHAR":
             case "STRING":
                 return new Java.MethodInvocation(Location.NOWHERE, null, "castToString", atoms);
+            case "TIMESTAMP":
+                List<Java.Rvalue> timestampFunctionParam = new ArrayList<>(Arrays.asList(atoms));
+                timestampFunctionParam.add(
+                        new Java.AmbiguousName(Location.NOWHERE, new String[] {DEFAULT_TIME_ZONE}));
+                return new Java.MethodInvocation(
+                        Location.NOWHERE,
+                        null,
+                        "castToTimestamp",
+                        timestampFunctionParam.toArray(new Java.Rvalue[0]));

Review Comment:
   I tried to use it but I'm hesitated as many lib used it and we may need to deal dependency shade issue.



-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2271118899

   > 
   
   It's expected as TIMESTAMP_LTZ type uses UTC0 timezone to get the string expression


-- 
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


Re: [PR] [FLINK-35743][cdc-runtime] Fix the time zone configuration for temporal functions is not effective [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3449:
URL: https://github.com/apache/flink-cdc/pull/3449#issuecomment-2261867487

   Seems running tests between 00:00 ~ 08:00 UTC (08:00 ~ 16:00 UTC+08:00) on the first day of a month would trigger this problem.


-- 
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