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

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

                Author: ASF GitHub Bot
            Created on: 26/Feb/20 00:09
            Start Date: 26/Feb/20 00:09
    Worklog Time Spent: 10m 
      Work Description: jcamachor commented on pull request #915: HIVE-22893 
StatEstimate
URL: https://github.com/apache/hive/pull/915#discussion_r384203016
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSubstr.java
 ##########
 @@ -131,4 +137,52 @@ public BytesWritable evaluate(BytesWritable bw, 
IntWritable pos, IntWritable len
   public BytesWritable evaluate(BytesWritable bw, IntWritable pos){
     return evaluate(bw, pos, maxValue);
   }
+
+  @Override
+  public Optional<IStatEstimator> getStatEstimator() {
+    return Optional.of(new SubStrStatEstimator());
+  }
+
+  private static class SubStrStatEstimator implements IStatEstimator {
+
+    @Override
+    public Optional<ColStatistics> estimate(List<ColStatistics> csList) {
+      ColStatistics cs = csList.get(0).clone();
+
+      // this might bad in a skewed case; consider:
+      // 1 row with 1000 long string
+      // 99 rows with 0 length
+      // orig avg is 10
+      // new avg is 5 (if substr(5)) ; but in reality it will stay ~10
+      Optional<Double> start = getRangeWidth(csList.get(1).getRange());
+      Range startRange = csList.get(1).getRange();
+      if (startRange != null && startRange.minValue != null) {
+        double newAvgColLen = cs.getAvgColLen() - 
startRange.minValue.doubleValue();
+        if (newAvgColLen > 0) {
+          cs.setAvgColLen(newAvgColLen);
+        }
+
 
 Review comment:
   you can remove \n
 
----------------------------------------------------------------
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: 393068)

> Enhance data size estimation for fields computed by UDFs
> --------------------------------------------------------
>
>                 Key: HIVE-22893
>                 URL: https://issues.apache.org/jira/browse/HIVE-22893
>             Project: Hive
>          Issue Type: Improvement
>          Components: Statistics
>            Reporter: Zoltan Haindrich
>            Assignee: Zoltan Haindrich
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-22893.01.patch, HIVE-22893.02.patch, 
> HIVE-22893.03.patch, HIVE-22893.04.patch, HIVE-22893.05.patch, 
> HIVE-22893.06.patch, HIVE-22893.07.patch, HIVE-22893.08.patch, 
> HIVE-22893.09.patch, HIVE-22893.10.patch, HIVE-22893.11.patch, 
> HIVE-22893.12.patch
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Right now if we have columnstat on a column ; we use that to estimate things 
> about the column; - however if an UDF is executed on a column ; the resulting 
> column is treated as unknown thing and defaults are assumed.
> An improvement could be to give wide estimation(s) in case of frequently used 
> udf.
> For example; consider {{substr(c,1,1)}} ; no matter what the input; the 
> output is at most a 1 long string



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

Reply via email to