You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "AHeise (via GitHub)" <gi...@apache.org> on 2026/08/27 13:18:21 UTC

[PR] [FLINK-40481][table] Fix SHOW CREATE FROM_NOW timestamp direction [flink]

AHeise opened a new pull request, #29030:
URL: https://github.com/apache/flink/pull/29030

   ```sql
   CREATE MATERIALIZED TABLE mt
   START_MODE = FROM_NOW(INTERVAL '3' MINUTE)
   AS SELECT ...;
   ```
   ```sql
   SHOW CREATE TABLE mt;
   -- START_MODE = FROM_NOW(INTERVAL '3' MINUTE) /* Evaluated to FROM_TIMESTAMP(TIMESTAMP '2026-08-27 09:43:12') at execution */
   ```
   Statement created at `2026-08-27 09:40:12`. The comment claims resolution to `09:43:12` — three minutes in the *future*. `FROM_NOW(<interval>)` actually resolves three minutes into the *past* (the documented, correct runtime behavior); only the `SHOW CREATE` annotation is wrong.
   
   `ShowCreateUtil.extractStartMode` builds the comment with:
   ```java
   LocalDateTime.now().plus(amount).toInstant(ZoneOffset.UTC)
   ```
   which should subtract the interval, not add it. Introduced in FLINK-39323.
   
   There's a second, related bug in the same expression: `LocalDateTime.now()` uses the JVM's default time zone, but the result is then reinterpreted with `.toInstant(ZoneOffset.UTC)` — mislabeling local wall-clock time as UTC. On a non-UTC host this shifts the annotated timestamp by the zone offset on top of the sign error.
   
   ### Fix
   Thread a `Clock` through `extractStartMode` (production passes `Clock.systemUTC()`) and compute `LocalDateTime.now(clock).minus(amount)`. This fixes both the sign and the zone-mislabeling in one change, and makes the sign directly testable: `ShowCreateUtilTest` now has a dedicated test using `Clock.fixed(...)` that asserts the exact resolved timestamp.
   
   ### Note for reviewers
   The existing parameterized `showCreateMaterializedTable` test can't catch a sign flip on its own — it normalizes the `Evaluated to FROM_TIMESTAMP(...)` comment via regex on both actual and expected before comparing (`setFixedTimestamp`), since the real value is wall-clock and non-deterministic. I left that normalization in place (it's still needed for the full-row equality checks against the real clock) and added the new `extractStartModeFromNowEvaluatesToPastTimestamp` test as a targeted, deterministic check via the injected `Clock` instead of widening the public API.


-- 
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-40481][table] Fix SHOW CREATE FROM_NOW timestamp direction [flink]

Posted by "AHeise (via GitHub)" <gi...@apache.org>.
AHeise commented on code in PR #29030:
URL: https://github.com/apache/flink/pull/29030#discussion_r3872852523


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/ShowCreateUtil.java:
##########
@@ -184,7 +185,7 @@ public static String buildShowCreateMaterializedTableRow(
                 .ifPresent(partitionedBy -> sb.append(formatPartitionedBy(partitionedBy)));
         extractFormattedOptions(table.getOptions(), PRINT_INDENT, additionalSensitiveKeys)
                 .ifPresent(v -> sb.append("WITH (\n").append(v).append("\n)\n"));
-        sb.append(extractStartMode(table, timeZoneId)).append("\n");
+        sb.append(extractStartMode(table, timeZoneId, Clock.systemUTC())).append("\n");

Review Comment:
   1. Fixed by normalizing the clock to UTC before reading its wall-clock time: `LocalDateTime.now(clock.withZone(ZoneOffset.UTC))`. Switching to `Instant.now(clock).minus(amount)` would actually break: `amount` can be a `Period` for MONTH/QUARTER/YEAR intervals, and `Period` arithmetic on `Instant` throws `UnsupportedTemporalTypeException` (Instant has no calendar fields) — `LocalDateTime` is required here to support those units. Added `extractStartModeFromNowIsUnaffectedByClockZone`, which uses a `Clock.fixed(..., ZoneId.of("America/New_York"))` and asserts the same output as the UTC-clock test, proving the mislabeling can't recur regardless of what zone a future caller's clock carries.
   
   2. `timeZoneId` isn't used in the FROM_NOW branch at all — the evaluated-timestamp comment is unconditionally rendered in UTC (`getFormattedLocalDateTime(instant, ZoneOffset.UTC)`), regardless of session zone. `timeZoneId` only matters for the `FROM_TIMESTAMP ... WITH LOCAL TIME ZONE` branch below it. So a non-UTC session doesn't change this code path; no additional coverage needed there.
   
   3. Already fixed in a later push — that fixture's date is now anchored to match its sibling case (2020-11-12, exactly 1 month before 2020-12-12).



-- 
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-40481][table] Fix SHOW CREATE FROM_NOW timestamp direction [flink]

Posted by "AHeise (via GitHub)" <gi...@apache.org>.
AHeise commented on code in PR #29030:
URL: https://github.com/apache/flink/pull/29030#discussion_r3880331003


##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/api/internal/ShowCreateUtilTest.java:
##########
@@ -195,6 +196,51 @@ void showCreateMaterializedTableWithFlags(
         assertThat(result).isEqualTo(expected.toString());
     }
 
+    @Test
+    void extractStartModeFromNowEvaluatesToPastTimestamp() {
+        final Clock fixedClock = Clock.fixed(Instant.parse("2020-12-12T23:18:12Z"), ZoneOffset.UTC);
+        final ResolvedCatalogMaterializedTable materializedTable =
+                createResolvedMaterialized(
+                        ONE_COLUMN_SCHEMA,
+                        null,
+                        List.of(),
+                        null,
+                        StartMode.of(StartModeKind.FROM_NOW, Interval.of(3, TimeUnit.MINUTE)),
+                        IntervalFreshness.ofMinute(1),
+                        RefreshMode.CONTINUOUS,
+                        "SELECT 1",
+                        "SELECT 1");
+
+        assertThat(ShowCreateUtil.extractStartMode(materializedTable, ZoneOffset.UTC, fixedClock))
+                .isEqualTo(
+                        "START_MODE = FROM_NOW(INTERVAL '3' MINUTE) /* Evaluated to"
+                                + " FROM_TIMESTAMP(TIMESTAMP '2020-12-12 23:15:12') at execution"
+                                + " */");
+    }

Review Comment:
   Fair — that one was fully redundant, same fixed clock/interval/expected string already exercised by the parameterized `showCreateMaterializedTable` case. Removed it. Kept `extractStartModeFromNowIsUnaffectedByClockZone` since it varies a different axis (non-UTC clock zone) that the parameterized test doesn't cover — it hardcodes one shared clock across all table-shape fixtures, so folding a variable clock in there just for this one case would mix concerns rather than share coverage.



-- 
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-40481][table] Fix SHOW CREATE FROM_NOW timestamp direction [flink]

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


-- 
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-40481][table] Fix SHOW CREATE FROM_NOW timestamp direction [flink]

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

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "1a21f71108cb5a8e277a3de6201d260ebbe4efd5",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "1a21f71108cb5a8e277a3de6201d260ebbe4efd5",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 1a21f71108cb5a8e277a3de6201d260ebbe4efd5 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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-40481][table] Fix SHOW CREATE FROM_NOW timestamp direction [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #29030:
URL: https://github.com/apache/flink/pull/29030#discussion_r3872325372


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/ShowCreateUtil.java:
##########
@@ -184,7 +185,7 @@ public static String buildShowCreateMaterializedTableRow(
                 .ifPresent(partitionedBy -> sb.append(formatPartitionedBy(partitionedBy)));
         extractFormattedOptions(table.getOptions(), PRINT_INDENT, additionalSensitiveKeys)
                 .ifPresent(v -> sb.append("WITH (\n").append(v).append("\n)\n"));
-        sb.append(extractStartMode(table, timeZoneId)).append("\n");
+        sb.append(extractStartMode(table, timeZoneId, Clock.systemUTC())).append("\n");

Review Comment:
   My AI said 
   1. LocalDateTime.now(clock).minus(amount).toInstant(ZoneOffset.UTC) — is the zone still correct?
   
   The fix calls LocalDateTime.now(clock) where clock is Clock.systemUTC(). LocalDateTime.now(Clock.systemUTC()) returns UTC wall time as a LocalDateTime (no zone info). Then .toInstant(ZoneOffset.UTC) reinterprets it as UTC — which is consistent. This is correct for the UTC clock case.
   
   However, if someone ever passes a non-UTC clock (e.g. for a different locale), the zone mislabeling would re-emerge silently. A more robust fix would be Instant.now(clock).minus(amount) followed by direct formatting, avoiding LocalDateTime entirely since it's zone-naive. This is a minor concern given Clock.systemUTC() is hardcoded at the call site, but worth a comment or a follow-up.
   
   2. The test uses ZoneOffset.UTC as the timeZoneId — does the production call path ever use a non-UTC zone?
   
   Looking at buildShowCreateMaterializedTableRow, timeZoneId is passed in from a session config. If the session is non-UTC, the test doesn't cover that path. Not a blocker, but a test with a non-UTC zone would strengthen confidence.
   
   3. The 1-month case change (1970-01-02 12:34:56 → 1969-10-29 12:34:56):
   
   Subtracting 1 month from 1970-01-02 gives 1969-12-02, not 1969-10-29. This suggests the fixed clock used in that test case is not 1970-01-02 — it's a different anchor. This is likely fine (the test fixtures use a mocked fixed time), but reviewers should confirm the expected value is correct for the fixture's clock value. The PR description doesn't explicitly state what fixed time that parameterized case uses.
   
   
   



-- 
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-40481][table] Fix SHOW CREATE FROM_NOW timestamp direction [flink]

Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #29030:
URL: https://github.com/apache/flink/pull/29030#discussion_r3879760672


##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/api/internal/ShowCreateUtilTest.java:
##########
@@ -195,6 +196,51 @@ void showCreateMaterializedTableWithFlags(
         assertThat(result).isEqualTo(expected.toString());
     }
 
+    @Test
+    void extractStartModeFromNowEvaluatesToPastTimestamp() {
+        final Clock fixedClock = Clock.fixed(Instant.parse("2020-12-12T23:18:12Z"), ZoneOffset.UTC);
+        final ResolvedCatalogMaterializedTable materializedTable =
+                createResolvedMaterialized(
+                        ONE_COLUMN_SCHEMA,
+                        null,
+                        List.of(),
+                        null,
+                        StartMode.of(StartModeKind.FROM_NOW, Interval.of(3, TimeUnit.MINUTE)),
+                        IntervalFreshness.ofMinute(1),
+                        RefreshMode.CONTINUOUS,
+                        "SELECT 1",
+                        "SELECT 1");
+
+        assertThat(ShowCreateUtil.extractStartMode(materializedTable, ZoneOffset.UTC, fixedClock))
+                .isEqualTo(
+                        "START_MODE = FROM_NOW(INTERVAL '3' MINUTE) /* Evaluated to"
+                                + " FROM_TIMESTAMP(TIMESTAMP '2020-12-12 23:15:12') at execution"
+                                + " */");
+    }

Review Comment:
   What is the value of having this test vs the one that is in the parasitized 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