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


##########
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:
   IMO we should keep the scope of this PR to remove the hints about alias. And 
in the tests, we should only see the change, `query_plan_with_alias_hint` -> 
`the_exact_same_query_plan_without_unnecessary_alias`. Would that make sense to 
you?



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/utils/RelTreeWriterImpl.scala:
##########
@@ -189,7 +191,16 @@ class RelTreeWriterImpl(
         case value =>
           if (j == 0) s.append("(") else s.append(", ")
           j = j + 1
-          s.append(value.left).append("=[").append(value.right).append("]")
+          val rightStr = value.right match {
+            case subQuery: RexSubQuery =>
+              if (withRicherDetailInSubQuery) {
+                computeSubQueryRicherDigest(subQuery)
+              } else {
+                value.right.toString
+              }
+            case _ => value.right.toString
+          }
+          s.append(value.left).append("=[").append(rightStr).append("]")

Review Comment:
   Is this block needed for the fixing the table alias clearance? 



-- 
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-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to