Skip to content

Commit ba9837e

Browse files
author
Aman Sinha
committed
DRILL-7187: Improve selectivity estimation of BETWEEN predicates and arbitrary combination of range predicates.
Address review comments. Modify unit test expected rowcount after rebasing. close #1772
1 parent 99707a3 commit ba9837e

6 files changed

Lines changed: 308 additions & 133 deletions

File tree

exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillStatsTable.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Double getNdv(SchemaPath col) {
120120
Long ndvCol = ndv.get(col);
121121
// Ndv estimation techniques like HLL may over-estimate, hence cap it at rowCount
122122
if (ndvCol != null) {
123-
return Math.min(ndvCol, rowCount);
123+
return (double) Math.min(ndvCol, rowCount);
124124
}
125125
return null;
126126
}
@@ -185,7 +185,6 @@ public Histogram getHistogram(SchemaPath column) {
185185
return histogram.get(column);
186186
}
187187

188-
189188
/**
190189
* Read the stats from storage and keep them in memory.
191190
*/
@@ -337,7 +336,7 @@ public void setType(TypeProtos.MajorType type) {
337336
this.type = type;
338337
}
339338
@JsonGetter ("schema")
340-
public double getSchema() {
339+
public long getSchema() {
341340
return this.schema;
342341
}
343342
@JsonSetter ("schema")
@@ -494,6 +493,10 @@ public static Map<StatisticsKind, Object> getEstimatedColumnStats(DrillStatsTabl
494493
if (histogram != null) {
495494
statisticsValues.put(ColumnStatisticsKind.HISTOGRAM, histogram);
496495
}
496+
Double rowcount = statsProvider.getRowCount();
497+
if (rowcount != null) {
498+
statisticsValues.put(ColumnStatisticsKind.ROWCOUNT, rowcount);
499+
}
497500
return statisticsValues;
498501
}
499502
return Collections.emptyMap();

exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/Histogram.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public interface Histogram {
3535
/**
3636
* For a filter condition, estimate the selectivity (matching rows/total rows) for this histogram
3737
* @param filter
38+
* @param totalRowCount
3839
* @return estimated selectivity or NULL if it could not be estimated for any reason
3940
*/
40-
Double estimatedSelectivity(final RexNode filter);
41+
Double estimatedSelectivity(final RexNode filter, final long totalRowCount);
4142
}

0 commit comments

Comments
 (0)