You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "gustavodemorais (via GitHub)" <gi...@apache.org> on 2026/04/22 11:29:44 UTC

[PR] [FLINK-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   When restoring a compiled plan whose query calls a built-in PTF with unprovided optional args (e.g. TO_CHANGELOG(input => TABLE t) without op / op_mapping), code generation fails: Unsupported call: DEFAULT()
   
   Cause: Unprovided slots are filled by SqlDefaultArgOperator, a per-call-site instance that carries the expected return type. It's not registered in any operator table, so on restore RexNodeJsonDeserializer falls through to Calcite's stock SqlStdOperatorTable.DEFAULT_OPERATOR. Codegen's op instanceof SqlDefaultArgOperator check (StringCallGen.scala:242) misses, and the call hits the generic unsupported branch.
   
   The same bug affects any built-in PTF that exposes optional user-level args (those survive toUdfCall and reach codegen). Existing user-defined PTF restore tests don't catch it because their DEFAULT() operands are system args (uid, on_time) that toUdfCall strips.
   
   Fix: In RexNodeJsonDeserializer.deserializeCall, when the deserialized operator's kind is SqlKind.DEFAULT, rebuild it as new SqlDefaultArgOperator(callType) so the typed Flink instance reaches codegen.
   
   
   ## Brief change log
   
   - Added fix to RexNodejsonDeserializer
   - Added restore tests
   
   
   ## Verifying this change
   
   Repro / coverage: New restore tests ToChangelogRestoreTest and FromChangelogRestoreTest, each running a RETRACT_RESTORE program. Both fail with Unsupported call: DEFAULT() without the fix and pass with it.
   
   ## 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?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change the checkbox below to `[X]` followed by the name of the tool, and uncomment the
   "Generated-by" line. See the ASF Generative Tooling Guidance for details:
   https://www.apache.org/legal/generative-tooling.html
   
   You are responsible for the quality and correctness of every change in this PR
   regardless of the tooling used. Low-effort AI-generated PRs will be closed. See
   AGENTS.md for the full guidance.
   -->
   
   - [x] Yes (please specify the tool below)
   
   <!--
   Generated-by: [2.1.117 (Claude Code)]
   -->
   


-- 
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-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "167f03a10034ce6ef5947334ea47f1080a5dea32",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "167f03a10034ce6ef5947334ea47f1080a5dea32",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 167f03a10034ce6ef5947334ea47f1080a5dea32 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-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/FromChangelogRestoreTest.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.plan.nodes.exec.stream;
+
+import org.apache.flink.table.planner.plan.nodes.exec.testutils.RestoreTestBase;
+import org.apache.flink.table.test.program.TableTestProgram;
+
+import java.util.List;
+
+/**
+ * Restore tests for the built-in FROM_CHANGELOG PTF. Verifies that {@link
+ * org.apache.flink.table.planner.functions.sql.SqlDefaultArgOperator} placeholders for unprovided
+ * optional args round-trip through compiled-plan serialization.

Review Comment:
   Nobody cares about this specific bug in the future. So comments can be simplified.
   ```suggestion
    * Restore tests for the built-in {@link BuiltInFunctionDefinitsions.FROM_CHANGELOG} PTF.
   ```



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/FromChangelogTestPrograms.java:
##########
@@ -183,6 +183,49 @@ public class FromChangelogTestPrograms {
                                     + "input => TABLE changelog_view)")
                     .build();
 
+    // --------------------------------------------------------------------------------------------
+    // Restore tests
+    // --------------------------------------------------------------------------------------------
+
+    /**
+     * Append source with retract op codes through FROM_CHANGELOG, split across a compiled-plan +
+     * savepoint restore. The unprovided {@code op} and {@code op_mapping} args become {@code
+     * DEFAULT()} placeholders that survive {@code toUdfCall} and reach codegen on the restore path
+     * - exercising the {@link org.apache.flink.table.planner.functions.sql.SqlDefaultArgOperator}

Review Comment:
   ```suggestion
        * savepoint restore. The unprovided {@code op} and {@code op_mapping} args become {@code
        * DEFAULT()} placeholders.
   ```



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RexNodeJsonDeserializer.java:
##########
@@ -374,7 +375,15 @@ private static RexNode deserializeCall(JsonNode jsonNode, SerdeContext serdeCont
         } else {
             callType = serdeContext.getRexBuilder().deriveReturnType(operator, rexOperands);
         }
-        return serdeContext.getRexBuilder().makeCall(callType, operator, rexOperands);
+        // SqlDefaultArgOperator is constructed per-call site by FlinkSqlCallBinding and not

Review Comment:
   Update RexNodeJsonSerdeTest



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RexNodeJsonDeserializer.java:
##########
@@ -374,7 +375,15 @@ private static RexNode deserializeCall(JsonNode jsonNode, SerdeContext serdeCont
         } else {
             callType = serdeContext.getRexBuilder().deriveReturnType(operator, rexOperands);
         }
-        return serdeContext.getRexBuilder().makeCall(callType, operator, rexOperands);
+        // SqlDefaultArgOperator is constructed per-call site by FlinkSqlCallBinding and not
+        // registered in any operator table, so the lookup above falls through to Calcite's stock
+        // SqlStdOperatorTable.DEFAULT_OPERATOR. Rebuild the typed Flink instance here so codegen's
+        // `op instanceof SqlDefaultArgOperator` check (StringCallGen) recognizes it on restore.

Review Comment:
   ```suggestion
           // SqlDefaultArgOperator is constructed per-call site by FlinkSqlCallBinding and not
           // registered in any operator table. Rebuild the typed Flink instance 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-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RexNodeJsonSerdeTest.java:
##########
@@ -230,6 +232,20 @@ public void testInlineFunction() throws IOException {
                                 "The function's implementation class must not be stateful"));
     }
 
+    @Test
+    public void testDefaultArgOperatorRoundTrip() throws IOException {

Review Comment:
   Is there a reason why you added a dedicated test, and not just a new list entry in `testRexNodeSerde`?



-- 
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-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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

   Thanks for the review, @twalthr! Simplified comments and added 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-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RexNodeJsonSerdeTest.java:
##########
@@ -230,6 +232,20 @@ public void testInlineFunction() throws IOException {
                                 "The function's implementation class must not be stateful"));
     }
 
+    @Test
+    public void testDefaultArgOperatorRoundTrip() throws IOException {

Review Comment:
   No, there isn't. Thanks for the pointer



-- 
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-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RexNodeJsonDeserializer.java:
##########
@@ -374,7 +375,15 @@ private static RexNode deserializeCall(JsonNode jsonNode, SerdeContext serdeCont
         } else {
             callType = serdeContext.getRexBuilder().deriveReturnType(operator, rexOperands);
         }
-        return serdeContext.getRexBuilder().makeCall(callType, operator, rexOperands);
+        // SqlDefaultArgOperator is constructed per-call site by FlinkSqlCallBinding and not

Review Comment:
   Added a test 



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/FromChangelogTestPrograms.java:
##########
@@ -183,6 +183,49 @@ public class FromChangelogTestPrograms {
                                     + "input => TABLE changelog_view)")
                     .build();
 
+    // --------------------------------------------------------------------------------------------
+    // Restore tests
+    // --------------------------------------------------------------------------------------------
+
+    /**
+     * Append source with retract op codes through FROM_CHANGELOG, split across a compiled-plan +
+     * savepoint restore. The unprovided {@code op} and {@code op_mapping} args become {@code
+     * DEFAULT()} placeholders that survive {@code toUdfCall} and reach codegen on the restore path
+     * - exercising the {@link org.apache.flink.table.planner.functions.sql.SqlDefaultArgOperator}

Review Comment:
   Simplified - also removed "The unprovided {@code op} and {@code op_mapping} args become {@code * DEFAULT()} placeholders."



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/FromChangelogRestoreTest.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.plan.nodes.exec.stream;
+
+import org.apache.flink.table.planner.plan.nodes.exec.testutils.RestoreTestBase;
+import org.apache.flink.table.test.program.TableTestProgram;
+
+import java.util.List;
+
+/**
+ * Restore tests for the built-in FROM_CHANGELOG PTF. Verifies that {@link
+ * org.apache.flink.table.planner.functions.sql.SqlDefaultArgOperator} placeholders for unprovided
+ * optional args round-trip through compiled-plan serialization.

Review Comment:
   done



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RexNodeJsonDeserializer.java:
##########
@@ -374,7 +375,15 @@ private static RexNode deserializeCall(JsonNode jsonNode, SerdeContext serdeCont
         } else {
             callType = serdeContext.getRexBuilder().deriveReturnType(operator, rexOperands);
         }
-        return serdeContext.getRexBuilder().makeCall(callType, operator, rexOperands);
+        // SqlDefaultArgOperator is constructed per-call site by FlinkSqlCallBinding and not
+        // registered in any operator table, so the lookup above falls through to Calcite's stock
+        // SqlStdOperatorTable.DEFAULT_OPERATOR. Rebuild the typed Flink instance here so codegen's
+        // `op instanceof SqlDefaultArgOperator` check (StringCallGen) recognizes it on restore.

Review Comment:
   Done



-- 
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-39515][table] Fix compiled plan restore for built-in PTFs with default args [flink]

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


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