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

   ## What is the purpose of the change
   
   When a planner rule rejects a query during the Volcano phase, 
`FlinkVolcanoProgram` wraps it as "Cannot generate a valid execution plan for 
the given query:" followed by the full logical plan and only then the rule's 
own message. The reason is the only actionable part and it is buried. A 
`ValidationException` thrown from a rule's `onMatch()`/`convert()` is not 
handled at all and reaches users as Calcite's "Error while applying rule ..." 
`RuntimeException`.
   
   This PR keeps the wrapper exception and its cause chain, so anything 
matching on the header, the type or the cause keeps working, but puts the 
reason on the header line and moves the plan behind a `Plan:` marker so that 
tools rewriting the message can find and strip it.
   
   Before (batch `GROUP BY SESSION(...)`, Java API / SQL gateway / PyFlink):
   
   ```
   org.apache.flink.table.api.TableException: Sql optimization: Cannot generate 
a valid execution plan for the given query:
   
   FlinkLogicalWindowAggregate(window=[SessionGroupWindow('w$, ts, 1800000)], 
select=[COUNT(*) AS cnt])
   +- FlinkLogicalCalc(select=[ts])
      +- FlinkLogicalTableSourceScan(table=[[default_catalog, default_database, 
t]], fields=[a, b, ts])
   
   Window SessionGroupWindow('w$, ts, 1800000) is not supported right now.
   Please check the documentation for the set of currently supported SQL 
features.
   ```
   
   After:
   
   ```
   org.apache.flink.table.api.TableException: Cannot generate a valid execution 
plan for the given query: Window SessionGroupWindow('w$, ts, 1800000) is not 
supported right now.
   
   Plan:
   FlinkLogicalWindowAggregate(window=[SessionGroupWindow('w$, ts, 1800000)], 
select=[COUNT(*) AS cnt])
   +- FlinkLogicalCalc(select=[ts])
      +- FlinkLogicalTableSourceScan(table=[[default_catalog, default_database, 
t]], fields=[a, b, ts])
   ```
   
   `OVER ... EXCLUDE GROUP`, which today surfaces as 
`java.lang.RuntimeException: Error while applying rule 
FlinkLogicalOverAggregateConverter, args [...]`, becomes a 
`ValidationException` with the same layout and the original exception as cause.
   
   ## Brief change log
   
     - `FlinkVolcanoProgram`: build one message layout (reason first, `Plan:` 
marker) for `CannotPlanException` and for 
`TableException`/`ValidationException` thrown by a rule; look through the plain 
`RuntimeException` Calcite wraps around exceptions from `onMatch()`. Other 
exceptions propagate unchanged. The "Sql optimization: " prefix and the "Please 
check the documentation" trailer on rule rejections are dropped.
     - Two existing tests pin the new layout (`GroupWindowTest`, 
`OverAggregateTest`); three unit tests cover the unwrapping helper.
   
   ## Verifying this change
   
   This change is already covered by existing tests: every existing assertion 
on the header text, the exception type or the cause chain passes unchanged 
(`./mvnw -pl flink-table/flink-table-planner verify`, 11429 unit and 10434 
integration tests). Added assertions for the new layout in 
`GroupWindowTest#testNonPartitionedSessionWindow` and 
`OverAggregateTest#testExclusionGroupIsNotSupported`, and unit tests for 
`FlinkVolcanoProgram#unwrapRuleException`.
   
   Note for reviewers: #29003 (FLINK-40449) adds a `SortValidationTest` that 
navigates to `rootCause()` to skip the plan dump; it keeps working with this 
change.
   
   ## 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: no
     - 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?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude Fable 5.1)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to