Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1232#discussion_r183762287
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/output/DecimalReturnTypeInference.java
 ---
    @@ -281,20 +295,45 @@
         @Override
         public TypeProtos.MajorType getType(List<LogicalExpression> 
logicalExpressions, FunctionAttributes attributes) {
           int scale = 0;
    -      int precision = 0;
     
           // Get the max scale and precision from the inputs
           for (LogicalExpression e : logicalExpressions) {
             scale = Math.max(scale, e.getMajorType().getScale());
    -        precision = Math.max(precision, e.getMajorType().getPrecision());
           }
     
    -      return (TypeProtos.MajorType.newBuilder()
    -          
.setMinorType(attributes.getReturnValue().getType().getMinorType())
    +      return TypeProtos.MajorType.newBuilder()
    +          .setMinorType(TypeProtos.MinorType.VARDECIMAL)
               .setScale(scale)
    -          .setPrecision(38)
    -          .setMode(TypeProtos.DataMode.REQUIRED)
    -          .build());
    +          .setPrecision(DRILL_REL_DATATYPE_SYSTEM.getMaxNumericPrecision())
    +          .setMode(TypeProtos.DataMode.OPTIONAL)
    +          .build();
    +    }
    +  }
    +
    +  /**
    +   * Return type calculation implementation for functions with return type 
set as
    +   * {@link 
org.apache.drill.exec.expr.annotations.FunctionTemplate.ReturnType#DECIMAL_AVG_AGGREGATE}.
    +   */
    +  public static class DecimalAvgAggReturnTypeInference implements 
ReturnTypeInference {
    --- End diff --
    
    Please add information how precision and scale are calculated.


---

Reply via email to