You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/12/27 02:09:39 UTC

[GitHub] [flink] swuferhong commented on a diff in pull request #21490: [FLINK-30368][table-planner] Fix calcite method RelMdUtil$numDistinctVals() wrongly return zero if the method input domainSize much larger than numSelected

swuferhong commented on code in PR #21490:
URL: https://github.com/apache/flink/pull/21490#discussion_r1057401207


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/utils/FlinkRelMdUtil.scala:
##########
@@ -247,6 +248,77 @@ object FlinkRelMdUtil {
     RexUtil.composeConjunction(rexBuilder, pushable, true)
   }
 
+  /**
+   * This method is copied from calcite RelMdUtil. This method should be removed once CALCITE-4351
+   * is fixed. See CALCITE-4351 and FLINK-19780.
+   *
+   * Computes the number of distinct rows for a set of keys returned from a join. Also known as NDV
+   * (number of distinct values).
+   *
+   * @param joinRel
+   *   RelNode representing the join
+   * @param joinType
+   *   type of join
+   * @param groupKey
+   *   keys that the distinct row count will be computed for
+   * @param predicate
+   *   join predicate
+   * @param useMaxNdv
+   *   If true use formula <code>max(left NDV, right NDV)</code>, otherwise use <code>left NDV *
+   *   right NDV</code>.
+   * @return
+   *   number of distinct rows
+   */
+  def getJoinDistinctRowCount(
+      mq: RelMetadataQuery,
+      joinRel: RelNode,
+      joinType: JoinRelType,
+      groupKey: ImmutableBitSet,
+      predicate: RexNode,
+      useMaxNdv: Boolean): Double = {
+    if ((predicate == null || predicate.isAlwaysTrue) && groupKey.isEmpty) return 1d

Review Comment:
   > please format the copied code
   
   Done!



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

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