amansinha100 commented on a change in pull request #1718: DRILL-7121: Use 
correct ndv when statistics is disabled
URL: https://github.com/apache/drill/pull/1718#discussion_r270054867
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdDistinctRowCount.java
 ##########
 @@ -75,8 +75,25 @@ public Double getDistinctRowCount(Join rel, 
RelMetadataQuery mq,
 
   @Override
   public Double getDistinctRowCount(RelNode rel, RelMetadataQuery mq, 
ImmutableBitSet groupKey, RexNode predicate) {
-    if (rel instanceof TableScan && !DrillRelOptUtil.guessRows(rel)) {
-      return getDistinctRowCount((TableScan) rel, mq, groupKey, predicate);
+    if (rel instanceof DrillScanRelBase) {
+      DrillTable table = rel.getTable().unwrap(DrillTable.class);
+      if (table == null) {
+        if (rel.getTable().unwrap(DrillTranslatableTable.class) != null) {
+          table = 
rel.getTable().unwrap(DrillTranslatableTable.class).getDrillTable();
+        }
+      }
+      if (table != null && table.getStatsTable() != null && 
!DrillRelOptUtil.guessRows(rel)) {
+        return getDistinctRowCount(((DrillScanRelBase)rel), mq, table, 
groupKey, rel.getRowType(), predicate);
+      } else {
+        // If guessing, return NDV as 0.1 * rowCount
+        /* If there is no table or metadata (stats) table associated with 
scan, estimate the
+         * distinct row count. Consistent with the estimation of Aggregate row 
count in
+         * RelMdRowCount: distinctRowCount = rowCount * 10%.
+         */
+        if (rel instanceof DrillScanRel) {
 
 Review comment:
   It would be good to add some comment here why the earlier check is for 
DrillScanRelBase and this one is for DrillScanRel. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to