paul-rogers commented on a change in pull request #1955: DRILL-7491: Incorrect
count() returned for complex types in parquet
URL: https://github.com/apache/drill/pull/1955#discussion_r366674972
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractGroupScanWithMetadata.java
##########
@@ -167,29 +167,46 @@ public boolean isMatchAllMetadata() {
*/
@Override
public long getColumnValueCount(SchemaPath column) {
- long tableRowCount, colNulls;
- Long nulls;
ColumnStatistics<?> columnStats =
getTableMetadata().getColumnStatistics(column);
- ColumnStatistics<?> nonInterestingColStats = null;
- if (columnStats == null) {
- nonInterestingColStats =
getNonInterestingColumnsMetadata().getColumnStatistics(column);
- }
+ ColumnStatistics<?> nonInterestingColStats = columnStats == null
+ ? getNonInterestingColumnsMetadata().getColumnStatistics(column) :
null;
+ long tableRowCount;
if (columnStats != null) {
tableRowCount =
TableStatisticsKind.ROW_COUNT.getValue(getTableMetadata());
} else if (nonInterestingColStats != null) {
tableRowCount =
TableStatisticsKind.ROW_COUNT.getValue(getNonInterestingColumnsMetadata());
+ columnStats = nonInterestingColStats;
+ } else if (existsNestedStatsForColumn(column, getTableMetadata())
+ || existsNestedStatsForColumn(column,
getNonInterestingColumnsMetadata())) {
+ // When statistics for nested field exists, this is complex column which
is present in table.
+ // But its nested fields statistics can't be used to extract
tableRowCount for this column.
+ // So NO_COLUMN_STATS returned here to avoid problems described in
DRILL-7491.
+ return Statistic.NO_COLUMN_STATS;
} else {
return 0; // returns 0 if the column doesn't exist in the table.
}
- columnStats = columnStats != null ? columnStats : nonInterestingColStats;
- nulls = ColumnStatisticsKind.NULLS_COUNT.getFrom(columnStats);
- colNulls = nulls != null ? nulls : Statistic.NO_COLUMN_STATS;
+ Long nulls = ColumnStatisticsKind.NULLS_COUNT.getFrom(columnStats);
+ if (nulls == null || Statistic.NO_COLUMN_STATS == nulls ||
Statistic.NO_COLUMN_STATS == tableRowCount) {
+ return Statistic.NO_COLUMN_STATS;
+ } else {
+ return tableRowCount - nulls;
Review comment:
The above is true, but non-interesting. The number of nulls is useful when
estimating selectivity of things like `IS NULL` or `IS NOT NULL`. If we are
interested in scans, then the null count is not helpful.
Given the math here, is the meaning of this function, "return the number of
rows with non-null values for this column"? If so, that is somewhat a backward
request. More typical is to return the null count directly, or the percentage
of nulls.
A reason that this value is not as helpful as it could be is if we are using
stats to estimate something like `WHERE x = 10 AND y IS NOT NULL`. First, we
estimate table row count, which might have been adjusted via partitioning. Then
we estimate the selectivity reduction due to `x = 10`. Then we estimate the
further reduction due to `y IS NOT NULL`. We cannot do this math if all we have
is a number *n* that tell us the number of non-null rows in the table; we'd
have to work out the selectivity number ourselves from the table row count.
----------------------------------------------------------------
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