[ 
https://issues.apache.org/jira/browse/HIVE-23530?focusedWorklogId=437810&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-437810
 ]

ASF GitHub Bot logged work on HIVE-23530:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/May/20 14:40
            Start Date: 27/May/20 14:40
    Worklog Time Spent: 10m 
      Work Description: jcamachor commented on a change in pull request #1034:
URL: https://github.com/apache/hive/pull/1034#discussion_r431189978



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsSemanticAnalyzer.java
##########
@@ -304,15 +287,199 @@ public static String genRewrittenQuery(Table tbl, 
List<String> colNames, HiveCon
     }
 
     String rewrittenQuery = rewrittenQueryBuilder.toString();
-    rewrittenQuery = new VariableSubstitution(new HiveVariableSource() {
-      @Override
-      public Map<String, String> getHiveVariable() {
-        return SessionState.get().getHiveVariables();
-      }
-    }).substitute(conf, rewrittenQuery);
+    rewrittenQuery = new VariableSubstitution(
+        () -> SessionState.get().getHiveVariables()).substitute(conf, 
rewrittenQuery);
     return rewrittenQuery;
   }
 
+  private static void genComputeStats(StringBuilder rewrittenQueryBuilder, 
HiveConf conf,
+      int pos, String columnName, TypeInfo typeInfo) throws SemanticException {
+    Preconditions.checkArgument(typeInfo.getCategory() == Category.PRIMITIVE);
+    ColumnStatsType columnStatsType =
+        ColumnStatsType.getColumnStatsType((PrimitiveTypeInfo) typeInfo);
+    // The first column is always the type
+    // The rest of columns will depend on the type itself
+    int size = columnStatsType.getColumnStats().size() - 1;
+    for (int i = 0; i < size; i++) {
+      ColumnStatsField columnStatsField = 
columnStatsType.getColumnStats().get(i);
+      appendStatsField(rewrittenQueryBuilder, conf, columnStatsField, 
columnStatsType,
+          columnName, pos);
+      rewrittenQueryBuilder.append(", ");
+    }
+    ColumnStatsField columnStatsField = 
columnStatsType.getColumnStats().get(size);
+    appendStatsField(rewrittenQueryBuilder, conf, columnStatsField, 
columnStatsType,
+        columnName, pos);
+  }
+
+  private static void appendStatsField(StringBuilder rewrittenQueryBuilder, 
HiveConf conf,
+      ColumnStatsField columnStatsField, ColumnStatsType columnStatsType,
+      String columnName, int pos) throws SemanticException {
+    switch (columnStatsField) {
+    case COLUMN_TYPE:
+      appendColumnType(rewrittenQueryBuilder, conf, columnStatsType, pos);

Review comment:
       This is kind of misleading because `column_type` does not always match 
the actual column type, e.g., BYTE, SHORT, INT or BIGINT are all mapped to the 
same column stats type (LONG). However, I did not want to change the internal 
name that was used before in this patch too. I renamed the enum to 
`COLUMN_STATS_TYPE` to add some more clarity.




----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 437810)
    Time Spent: 50m  (was: 40m)

> Use SQL functions instead of compute_stats UDAF to compute column statistics
> ----------------------------------------------------------------------------
>
>                 Key: HIVE-23530
>                 URL: https://issues.apache.org/jira/browse/HIVE-23530
>             Project: Hive
>          Issue Type: Improvement
>          Components: Statistics
>            Reporter: Jesus Camacho Rodriguez
>            Assignee: Jesus Camacho Rodriguez
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-23530.01.patch, HIVE-23530.02.patch, 
> HIVE-23530.03.patch, HIVE-23530.patch
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Currently we compute column statistics by relying on the {{compute_stats}} 
> UDAF. For instance, for a given table {{tbl}}, the query to compute 
> statistics for columns is translated internally into:
> {code}
> SELECT compute_stats(c1),
>        compute_stats(c2),
>        ...
> FROM tbl;
> {code}
> {{compute_stats}} produces data for the stats available for each column type, 
> e.g., struct<"max":long,"min":long,"countnulls":long,...>.
> This issue is to produce a query that relies purely on SQL functions instead:
> {code}
> SELECT max(c1), min(c1), count(case when c1 is null then 1 else null end),
>        ...
> FROM tbl;
> {code}
> This will allow us to deprecate the {{compute_stats}} UDAF since it mostly 
> duplicates functionality found in those other functions. Additionally, many 
> of those functions already provide a vectorized implementation so the 
> approach can potentially improve the performance of column stats collection.



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

Reply via email to