[ 
https://issues.apache.org/jira/browse/DRILL-7491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17015055#comment-17015055
 ] 

ASF GitHub Bot commented on DRILL-7491:
---------------------------------------

ihuzenko commented on pull request #1955: DRILL-7491: Incorrect count() 
returned for complex types in parquet
URL: https://github.com/apache/drill/pull/1955#discussion_r366313821
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractGroupScanWithMetadata.java
 ##########
 @@ -167,29 +167,43 @@ 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())) {
+      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;
+    }
+  }
 
-    return Statistic.NO_COLUMN_STATS == tableRowCount
-            || Statistic.NO_COLUMN_STATS == colNulls
-            ? Statistic.NO_COLUMN_STATS : tableRowCount - colNulls;
+  /**
+   * For complex columns, stats may be present only for nested fields. For 
example, a column path is `a`,
+   * but stats present for `a`.`b`. So before making a decision that column is 
absent, the case needs
+   * to be tested.
+   *
+   * @param column   column path
+   * @param metadata metadata with column statistics
+   * @return whether stats exists for nested fields
+   */
+  private boolean existsNestedStatsForColumn(SchemaPath column, Metadata 
metadata) {
 
 Review comment:
   No, the nested stats exists but not applicable for the parent column.  As 
javadoc says, the method is used only to determine whether the column is 
actually absent. The current name expresses exactly what the method does.  
 
----------------------------------------------------------------
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]


> Incorrect count() returned for complex types in parquet
> -------------------------------------------------------
>
>                 Key: DRILL-7491
>                 URL: https://issues.apache.org/jira/browse/DRILL-7491
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Functions - Drill, Functions - Hive, Storage - Parquet
>    Affects Versions: 1.16.0, 1.17.0
>            Reporter: Igor Guzenko
>            Assignee: Igor Guzenko
>            Priority: Major
>             Fix For: 1.18.0
>
>         Attachments: hive_alltypes.parquet
>
>
> To reproduce use the attached file for {{hive_alltypes.parquet}} (this is 
> parquet file generated by Hive) and try count on columns *c13 - c15.*  For 
> example, 
> {code:sql}
> SELECT count(c13) FROM dfs.tmp.`hive_alltypes.parquet`
> {code}
> *Expected result:* {color:green}3 {color}
> *Actual result:* {color:red}0{color}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to