xuyangzhong commented on code in PR #24239:
URL: https://github.com/apache/flink/pull/24239#discussion_r1477160533


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/utils/RelTreeWriterImpl.scala:
##########
@@ -286,4 +297,45 @@ class RelTreeWriterImpl(
               })
     }
   }
+
+  private def copy(pw: PrintWriter): RelTreeWriterImpl = {
+    new RelTreeWriterImpl(
+      pw,
+      explainLevel,
+      withIdPrefix,
+      withChangelogTraits,
+      withRowType,
+      withTreeStyle,
+      withUpsertKey,
+      withQueryHint,
+      withQueryBlockAlias,
+      statementNum,
+      withAdvice,
+      withRicherDetailInSubQuery)
+  }
+
+  /**
+   * Mainly copy from [[RexSubQuery#computeDigest]].
+   *
+   * Modified to support explain sub-query with richer additional detail by 
[[RelTreeWriterImpl]] in
+   * Flink rather than Calcite.
+   */
+  private def computeSubQueryRicherDigest(subQuery: RexSubQuery): String = {
+    val sb = new StringBuilder(subQuery.getOperator.getName);
+    sb.append("(")
+    subQuery.getOperands.forEach(
+      operand => {
+        sb.append(operand)
+        sb.append(", ")
+      })
+    sb.append("{\n")
+
+    val sw = new StringWriter
+    val newRelTreeWriter = copy(new PrintWriter(sw))
+    subQuery.rel.explain(newRelTreeWriter)
+    sb.append(sw.toString)
+
+    sb.append("})")
+    sb.toString()
+  }

Review Comment:
   In fact, the PR includes two commits. One for FLINK-34335, which is to fix 
the issue where query hints are not printed within subqueries, and the other 
for FLINK-33396, which addresses the issue of table alias hints not being 
cleared within subqueries.
   
   There is a certain relationship between these two commits. Without 
FLINK-34335, you would notice that the query hints inside the printed 
subqueries seem to be cleared as well (In `JoinHintTestBase` the printed plans 
do not contain join hints that should be present actually in the subqueries).
   
   However, their relationship is not so close, which is why I used two 
separate commits to facilitate the code review for the reviewers. Also, to 
avoid expanding the impact range of FLINK-34335, I have limited the changes to 
a confined set of tests(Only in JoinHintTestBase).
   
   If you insist that the PR should not include FLINK-34335 (if you're okay 
with the printed subqueries not containing alias hints, as well as other query 
hints, like join hints, which may confuse other reviews), I would be happy to 
revert the first commit and create a separate PR for it.
   
   WDYT?



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