[FLINK-39556][table] Make file path optional in COMPILE PLAN to return plan inline as a result set#28054
Open
luca-p-castelli wants to merge 1 commit intoapache:masterfrom
Open
Conversation
Author
|
@flinkbot run azure |
Collaborator
f7ff6b9 to
44a797b
Compare
…n plan inline as a result set
44a797b to
8fb0c22
Compare
luca-p-castelli
commented
Apr 27, 2026
| - SQL Syntax | ||
|
|
||
| ```sql | ||
| COMPILE PLAN [IF NOT EXISTS] <plan_file_path> FOR <insert_statement>|<statement_set>; |
Author
There was a problem hiding this comment.
Typo in the current docs. [IF NOT EXISTS] should be after the file path.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
Today
COMPILE PLANrequires a file path and writes the compiledExecNodeGraphJSON to disk:This requires the caller to share a filesystem with the executor. For tooling built on the SQL Gateway (CLIs, IDEs, CI systems) this adds filesystem-coordination complexity, and for remote SQL Gateway deployments it does not work at all — the file lands on the gateway host, not the caller's host.
This PR makes the file path optional. When omitted, the compiled plan is returned inline as a single-row, single-column
STRINGresult set withResultKind.SUCCESS_WITH_CONTENT— the same result-set pattern already used byEXPLAIN:Fully backward compatible: the existing
COMPILE PLAN '<path>' [IF NOT EXISTS] FOR <dml>syntax and behavior are unchanged. This is an internal-only change at the API level — bothSqlCompilePlanandCompilePlanOperationare annotated@Internal; no new public API surface, no new REST endpoints.Discussion thread: https://lists.apache.org/thread/j2z9obdyr9k0078jj1cd6tjj5nvbdk86
Brief change log
parserImpls.ftl): make the path-and-IF NOT EXISTSblock optional so the grammar accepts bothCOMPILE PLAN '<path>' [IF NOT EXISTS] FOR <dml>andCOMPILE PLAN FOR <dml>. The two branches are LL(1)-distinguishable (FIRST sets{<QUOTED_STRING>}vs{<FOR>}are disjoint), so no explicitLOOKAHEADdirective is required.SqlCompilePlan):planFileis now@Nullable;unparseemits the path andIF NOT EXISTSonly when present.CompilePlanOperation):filePathis now@Nullable; constructor adds aPreconditions.checkArgumentrejectingIF NOT EXISTSwhen no file path is specified.TableEnvironmentImpl): when the file path is null, return the plan viaTableResultUtils.buildStringArrayResult("result", new String[]{compiledPlan.asJsonString()})— the same single-columnSTRINGSUCCESS_WITH_CONTENTshape used by other show-style commands (SHOW CREATE *,SHOW CURRENT CATALOG, etc.). Extracted a sharedcompileOperationToPlanhelper used by both the file-based and inline paths.FlinkSqlParserImplTestfor inlineINSERTand inlineSTATEMENT SET; integration tests inCompiledPlanITCase(testCompilePlanInline,testCompilePlanInlineWithStatementSet) verifyingResultKind.SUCCESS_WITH_CONTENT, the presence offlinkVersion, and the expected sink identifiers in the returned JSON.Verifying this change
This change added tests and can be verified as follows:
FlinkSqlParserImplTest#compilePlan— extended with parse/unparse round-trip cases for both inline forms (singleINSERT,STATEMENT SET).CompiledPlanITCase#testCompilePlanInline— verifies single-INSERTinline form: result kind isSUCCESS_WITH_CONTENT, returned JSON containsflinkVersion, source-scan, and sink exec nodes.CompiledPlanITCase#testCompilePlanInlineWithStatementSet— verifiesSTATEMENT SETinline form: returned JSON contains both sink identifiers (sinkA,sinkB).COMPILE PLANtests pass unchanged.Does this pull request potentially affect one of the following parts:
@Public(Evolving): no (bothSqlCompilePlanandCompilePlanOperationare@Internal)Documentation
COMPILE PLANsyntax with an optional file path)SqlCompilePlanandCompilePlanOperationjavadocs updated to document the optional-path semantics) and SQL reference documentation.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Opus 4.7)