raminqaf commented on code in PR #28403:
URL: https://github.com/apache/flink/pull/28403#discussion_r3413277563


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/optimize/program/FlinkChangelogModeInferenceProgram.scala:
##########
@@ -114,9 +114,24 @@ class FlinkChangelogModeInferenceProgram extends 
FlinkOptimizeProgram[StreamOpti
 
     // step4: sanity check and return non-empty root
     if (finalRoot.isEmpty) {
-      val plan = FlinkRelOptUtil.toString(root, withChangelogTraits = true)
-      throw new TableException(
-        "Can't generate a valid execution plan for the given query:\n" + plan)
+      val errorMessage =
+        if (containsUpdates(rootWithModifyKindSet)) {
+          // Point at the failing node and its inputs instead of dumping the 
whole plan.
+          val conflict = new 
StringBuilder(describeChangelog(rootWithModifyKindSet))
+          rootWithModifyKindSet.getInputs.foreach(
+            input => conflict.append("\n  +- 
").append(describeChangelog(input)))
+          "Can't generate a valid execution plan for the given query.\n\n" +
+            "There is a changelog mismatch between two operators. One produces 
an upsert " +
+            "changelog (UPDATE_AFTER without UPDATE_BEFORE). The other 
requires a retract " +
+            "changelog (UPDATE_BEFORE and UPDATE_AFTER), for example a sink 
without a primary " +
+            "key. To resolve it, declare a PRIMARY KEY on the sink, or make 
the input produce " +

Review Comment:
   Addressed Timo's feedback on this section



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