[ https://issues.apache.org/jira/browse/HIVE-21633?focusedWorklogId=233827&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-233827 ]
ASF GitHub Bot logged work on HIVE-21633: ----------------------------------------- Author: ASF GitHub Bot Created on: 27/Apr/19 01:00 Start Date: 27/Apr/19 01:00 Worklog Time Spent: 10m Work Description: vineetgarg02 commented on pull request #603: HIVE-21633 URL: https://github.com/apache/hive/pull/603#discussion_r279137177 ########## File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java ########## @@ -1524,6 +1531,77 @@ public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, return null; } + /** + * If possible, sets the min / max value for the column based on the aggregate function + * being calculated and its input. + */ + private static void computeAggregateColumnMinMax(ColStatistics cs, HiveConf conf, AggregationDesc agg, String aggType, + Statistics parentStats) throws SemanticException { + if (agg.getParameters() != null && agg.getParameters().size() == 1) { + ColStatistics parentCS = StatsUtils.getColStatisticsFromExpression( + conf, parentStats, agg.getParameters().get(0)); + if (parentCS != null && parentCS.getRange() != null && + parentCS.getRange().minValue != null && parentCS.getRange().maxValue != null) { + long valuesCount = agg.getDistinct() ? + parentCS.getCountDistint() : + parentStats.getNumRows() - parentCS.getNumNulls(); + Range range = parentCS.getRange(); + // Get the aggregate function matching the name in the query. + GenericUDAFResolver udaf = + FunctionRegistry.getGenericUDAFResolver(agg.getGenericUDAFName()); + if (udaf instanceof GenericUDAFCount) { + cs.setRange(new Range(0, valuesCount)); Review comment: Assuming range represent the min,max possible value for the expression is this calculation correct? Lets say there are 1M numRows and count distinct is 2 and count aggregate is distinct, this will set the range to (0,2) but it should be (0, 1/2M). No? Or did I miss-understand range ---------------------------------------------------------------- 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: 233827) Time Spent: 20m (was: 10m) > Estimate range for value generated by aggregate function in statistics > annotation > --------------------------------------------------------------------------------- > > Key: HIVE-21633 > URL: https://issues.apache.org/jira/browse/HIVE-21633 > Project: Hive > Issue Type: Improvement > Components: Statistics > Reporter: Jesus Camacho Rodriguez > Assignee: Jesus Camacho Rodriguez > Priority: Major > Labels: pull-request-available > Attachments: HIVE-21633.02.patch, HIVE-21633.03.patch > > Time Spent: 20m > Remaining Estimate: 0h > > In some cases, we can infer the estimate of the range for a value generated > by an aggregate function during statistics annotation. For instance, we can > estimate the min of the sum of a column with positive min value as that same > min value. -- This message was sent by Atlassian JIRA (v7.6.3#76005)