Skip to content

[FLINK-41637][table] Fix UNIX_TIMESTAMP determinism - #30080

Closed
Au-Miner wants to merge 1 commit into
apache:masterfrom
Au-Miner:fix/41637
Closed

Au-Miner wants to merge 1 commit into
apache:masterfrom
Au-Miner:fix/41637

Conversation

@Au-Miner

Copy link
Copy Markdown
Contributor

What is the purpose of the change

UNIX_TIMESTAMP(ts) and UNIX_TIMESTAMP(ts, format) parse their arguments. Marking them as non-deterministic prevents their use in filters on updating tables with table.optimizer.non-deterministic-update.strategy=TRY_RESOLVE. Only the zero-argument overload reads the current time. FLINK-41637

Brief change log

  • Select the SQL operator by argument count in SQL and Table API calls. Keep the clock-based overload non-deterministic and allow constant folding for string arguments.
  • Use operand counts to resolve built-in overloads that share a name in compiled plans.

Verifying this change

  • Added tests for determinism, monotonicity, non-deterministic arguments and compiled-plan round trips. Updated the batch and streaming plan expectations for constant folding.
  • Verified the updating-table filters with all three overloads and restored a plan containing all three that was compiled before the fix.
  • Ran spotless:check and verify for flink-table/flink-table-planner.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: yes
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

Was generative AI tooling used to co-author this PR?
  • Yes

Generated-by: OpenAI Codex CLI 0.169.1

@flinkbot

flinkbot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@shihchengwei-lab

Copy link
Copy Markdown

Compiled-plan execution fails for UNIX_TIMESTAMP(ts) at 08cb2981. Direct execution of the same SQL succeeds, and the compiled-plan round trip succeeds at the parent commit b1f051d0. A job loading this plan fails before it starts.

Minimal reproduction in a JsonPlanTestBase subclass:

@Test
void restoresUnixTimestamp() throws Exception {
    tableEnv.getConfig().setLocalTimeZone(ZoneId.of("UTC"));
    createTestValuesSourceTable(
            "InputTimes", List.of(Row.of("2020-01-01 00:00:00")), "ts STRING");
    createTestValuesSinkTable("Result", "now BIGINT", "parsed BIGINT");

    String sql = "INSERT INTO Result "
            + "SELECT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(ts) FROM InputTimes";
    String json = tableEnv.compilePlanSql(sql).asJsonString();
    tableEnv.loadPlan(PlanReference.fromJsonString(json)).execute().await();
}

The expected row has parsed = 1577836800. Instead, the PR commit throws CodeGenException: Unsupported call: UNIX_TIMESTAMP(STRING) during code generation. deserializeCall resolves the operator before reading its operands, and the lookup returns the first same-name candidate. Could restoration select the overload by the serialized operand count? A round-trip test with a nonconstant ts would cover this path.

@Au-Miner Au-Miner closed this Nov 25, 2026
@Au-Miner

Copy link
Copy Markdown
Contributor Author

Compiled-plan execution fails for UNIX_TIMESTAMP(ts) at 08cb2981. Direct execution of the same SQL succeeds, and the compiled-plan round trip succeeds at the parent commit b1f051d0. A job loading this plan fails before it starts.

Minimal reproduction in a JsonPlanTestBase subclass:

@test
void restoresUnixTimestamp() throws Exception {
tableEnv.getConfig().setLocalTimeZone(ZoneId.of("UTC"));
createTestValuesSourceTable(
"InputTimes", List.of(Row.of("2020-01-01 00:00:00")), "ts STRING");
createTestValuesSinkTable("Result", "now BIGINT", "parsed BIGINT");

String sql = "INSERT INTO Result "
        + "SELECT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(ts) FROM InputTimes";
String json = tableEnv.compilePlanSql(sql).asJsonString();
tableEnv.loadPlan(PlanReference.fromJsonString(json)).execute().await();

}
The expected row has parsed = 1577836800. Instead, the PR commit throws CodeGenException: Unsupported call: UNIX_TIMESTAMP(STRING) during code generation. deserializeCall resolves the operator before reading its operands, and the lookup returns the first same-name candidate. Could restoration select the overload by the serialized operand count? A round-trip test with a nonconstant ts would cover this path.

Thank you for discovering this issue. Yes, because of the introduction of the parameterless UNIX_TIMESTAMP, the current deserialization process results in multiple built-in functions, and the default first one is taken as the deserialization result. This logic should be replaced with selecting different built-in functions based on the number of overloaded parameters. I will try to fix this logic and address it as a pre-PR. What do you think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants