drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From par...@apache.org
Subject [3/7] drill git commit: DRILL-5419: Calculate return string length for literals & some string functions
Date Sat, 13 May 2017 17:39:01 GMT
http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
index b461b5c..f14d816 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
@@ -216,7 +216,7 @@ public class ExpressionTreeMaterializer {
        * using an arbitrary value. We trim down the size of the stored bytes
        * to the actual size so this size doesn't really matter.
        */
-      castArgs.add(new ValueExpressions.LongExpression(TypeHelper.VARCHAR_DEFAULT_CAST_LEN, null));
+      castArgs.add(new ValueExpressions.LongExpression(Types.MAX_VARCHAR_LENGTH, null));
     }
     else if (CoreDecimalUtility.isDecimalType(toType)) {
       // Add the scale and precision to the arguments of the implicit cast
@@ -573,7 +573,7 @@ public class ExpressionTreeMaterializer {
      * @return
      */
     private LogicalExpression getExceptionFunction(String message) {
-      QuotedString msg = new QuotedString(message, ExpressionPosition.UNKNOWN);
+      QuotedString msg = new QuotedString(message, message.length(), ExpressionPosition.UNKNOWN);
       List<LogicalExpression> args = Lists.newArrayList();
       args.add(msg);
       FunctionCall call = new FunctionCall(ExceptionFunction.EXCEPTION_FUNCTION_NAME, args, ExpressionPosition.UNKNOWN);
@@ -855,8 +855,9 @@ public class ExpressionTreeMaterializer {
         // if the type still isn't fully bound, leave as cast expression.
         return new CastExpression(input, e.getMajorType(), e.getPosition());
       } else if (newMinor == MinorType.NULL) {
-        // if input is a NULL expression, remove cast expression and return a TypedNullConstant directly.
-        return new TypedNullConstant(Types.optional(e.getMajorType().getMinorType()));
+        // if input is a NULL expression, remove cast expression and return a TypedNullConstant directly
+        // preserve original precision and scale if present
+        return new TypedNullConstant(e.getMajorType().toBuilder().setMode(DataMode.OPTIONAL).build());
       } else {
         // if the type is fully bound, convert to functioncall and materialze the function.
         MajorType type = e.getMajorType();
@@ -869,11 +870,12 @@ public class ExpressionTreeMaterializer {
 
         //VarLen type
         if (!Types.isFixedWidthType(type)) {
-          newArgs.add(new ValueExpressions.LongExpression(type.getWidth(), null));
+          newArgs.add(new ValueExpressions.LongExpression(type.getPrecision(), null));
         }  if (CoreDecimalUtility.isDecimalType(type)) {
             newArgs.add(new ValueExpressions.LongExpression(type.getPrecision(), null));
             newArgs.add(new ValueExpressions.LongExpression(type.getScale(), null));
         }
+
         FunctionCall fc = new FunctionCall(castFuncWithType, newArgs, e.getPosition());
         return fc.accept(this, functionLookupContext);
       }
@@ -930,11 +932,7 @@ public class ExpressionTreeMaterializer {
         // 2) or "to" length is unknown (0 means unknown length?).
         // Case 1 and case 2 mean that cast will do nothing.
         // In other cases, cast is required to trim the "from" according to "to" length.
-        if ( (to.getWidth() >= from.getWidth() && from.getWidth() > 0) || to.getWidth() == 0) {
-          return true;
-        } else {
-          return false;
-        }
+        return (to.getPrecision() >= from.getPrecision() && from.getPrecision() > 0) || to.getPrecision() == 0;
 
       default:
         errorCollector.addGeneralError(pos, String.format("Casting rules are unknown for type %s.", from));

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
index f43b253..ac4ba07 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -17,10 +17,23 @@
  */
 package org.apache.drill.exec.expr.annotations;
 
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.types.TypeProtos;
+import org.apache.drill.exec.expr.fn.FunctionAttributes;
+import org.apache.drill.exec.expr.fn.FunctionInitializer;
+import org.apache.drill.exec.expr.fn.output.ConcatReturnTypeInference;
+import org.apache.drill.exec.expr.fn.output.DecimalReturnTypeInference;
+import org.apache.drill.exec.expr.fn.output.DefaultReturnTypeInference;
+import org.apache.drill.exec.expr.fn.output.PadReturnTypeInference;
+import org.apache.drill.exec.expr.fn.output.ReturnTypeInference;
+import org.apache.drill.exec.expr.fn.output.SameInOutLengthReturnTypeInference;
+import org.apache.drill.exec.expr.fn.output.StringCastReturnTypeInference;
+
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
+import java.util.List;
 
 
 @Retention(RetentionPolicy.RUNTIME)
@@ -36,7 +49,7 @@ public @interface FunctionTemplate {
    *   to resolve the current issue of spaces vs. underlines in names (e.g., we
    *   have both "less_than" and "less than".
    * </p>
-   * @return
+   * @return function name
    */
   String name() default "";
 
@@ -49,11 +62,12 @@ public @interface FunctionTemplate {
    *   to resolve the current issue of spaces vs. underlines in names (e.g., we
    *   have both "less_than" and "less than".
    * </p>
-   * @return
+   * @return list of function names
    */
   String[] names() default {};
 
   FunctionScope scope();
+  ReturnType returnType() default ReturnType.DEFAULT;
   NullHandling nulls() default NullHandling.INTERNAL;
   boolean isBinaryCommutative() default false;
   boolean isRandom()  default false;
@@ -61,22 +75,21 @@ public @interface FunctionTemplate {
   FunctionCostCategory costCategory() default FunctionCostCategory.SIMPLE;
 
   /**
-   * Set Operand type-checking strategy for an operator which takes no operands and need to be invoked
-   * without parentheses. E.g.: session_id is a niladic function.
+   * <p>Set Operand type-checking strategy for an operator which takes no operands and need to be invoked
+   * without parentheses. E.g.: session_id is a niladic function.</p>
    *
-   * Niladic functions override columns that have names same as any niladic function. Such columns cannot be
+   * <p>Niladic functions override columns that have names same as any niladic function. Such columns cannot be
    * queried without the table qualification. Value of the niladic function is returned when table
-   * qualification is not used.
-   *
-   * For e.g. in the case of session_id:
-   *
-   * select session_id from <table> -> returns the value of niladic function session_id
-   * select t1.session_id from <table> t1 -> returns session_id column value from <table>
+   * qualification is not used.</p>
    *
+   * <p>For e.g. in the case of session_id:<br/>
+   * select session_id from table -> returns the value of niladic function session_id<br/>
+   * select t1.session_id from table t1 -> returns session_id column value from table<p>
    */
   boolean isNiladic() default false;
+  boolean checkPrecisionRange() default false;
 
-  public static enum NullHandling {
+  public enum NullHandling {
     /**
      * Method handles nulls.
      */
@@ -88,33 +101,61 @@ public @interface FunctionTemplate {
      * either input is NULL, and therefore that the method must not be called
      * with null inputs.  (The calling framework must handle NULLs.)
      */
-    NULL_IF_NULL;
+    NULL_IF_NULL
   }
 
-  public static enum FunctionScope {
+  /**
+   * Function scope is used to indicate function output rows relation:
+   * simple / scalar (1 -> 1) or aggregate (n -> 1).
+   */
+  public enum FunctionScope {
     SIMPLE,
     POINT_AGGREGATE,
-    DECIMAL_AGGREGATE,
-    DECIMAL_SUM_AGGREGATE,
     HOLISTIC_AGGREGATE,
-    RANGE_AGGREGATE,
-    DECIMAL_MAX_SCALE,
-    DECIMAL_MUL_SCALE,
-    DECIMAL_CAST,
-    DECIMAL_DIV_SCALE,
-    DECIMAL_MOD_SCALE,
-    DECIMAL_ADD_SCALE,
-    DECIMAL_SET_SCALE,
-    DECIMAL_ZERO_SCALE,
-    SC_BOOLEAN_OPERATOR
+    RANGE_AGGREGATE
+  }
+
+  /**
+   * Return type enum is used to indicate which return type calculation logic
+   * should be used for functions.
+   */
+  public enum ReturnType {
+    DEFAULT(DefaultReturnTypeInference.INSTANCE),
+
+    STRING_CAST(StringCastReturnTypeInference.INSTANCE),
+    CONCAT(ConcatReturnTypeInference.INSTANCE),
+    PAD(PadReturnTypeInference.INSTANCE),
+    SAME_IN_OUT_LENGTH(SameInOutLengthReturnTypeInference.INSTANCE),
+
+    DECIMAL_AGGREGATE(DecimalReturnTypeInference.DecimalAggReturnTypeInference.INSTANCE),
+    DECIMAL_SUM_AGGREGATE(DecimalReturnTypeInference.DecimalSumAggReturnTypeInference.INSTANCE),
+    DECIMAL_MAX_SCALE(DecimalReturnTypeInference.DecimalMaxScaleReturnTypeInference.INSTANCE),
+    DECIMAL_SUM_SCALE(DecimalReturnTypeInference.DecimalSumScaleReturnTypeInference.INSTANCE),
+    DECIMAL_CAST(DecimalReturnTypeInference.DecimalCastReturnTypeInference.INSTANCE),
+    DECIMAL_DIV_SCALE(DecimalReturnTypeInference.DecimalDivScaleReturnTypeInference.INSTANCE),
+    DECIMAL_MOD_SCALE(DecimalReturnTypeInference.DecimalModScaleReturnTypeInference.INSTANCE),
+    DECIMAL_ADD_SCALE(DecimalReturnTypeInference.DecimalAddReturnTypeInference.INSTANCE),
+    DECIMAL_SET_SCALE(DecimalReturnTypeInference.DecimalSetScaleReturnTypeInference.INSTANCE),
+    DECIMAL_ZERO_SCALE(DecimalReturnTypeInference.DecimalZeroScaleReturnTypeInference.INSTANCE);
+
+    private final ReturnTypeInference inference;
+
+    ReturnType(ReturnTypeInference inference) {
+      this.inference = inference;
+    }
+
+    public TypeProtos.MajorType getType(List<LogicalExpression> logicalExpressions, FunctionAttributes attributes) {
+      return inference.getType(logicalExpressions, attributes);
+    }
+
   }
 
-  public static enum FunctionCostCategory {
+  public enum FunctionCostCategory {
     SIMPLE(1), MEDIUM(20), COMPLEX(50);
 
     private final int value;
 
-    private FunctionCostCategory(int value) {
+    FunctionCostCategory(int value) {
       this.value = value;
     }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillAggFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillAggFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillAggFuncHolder.java
index 9493b4d..a52cc16 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillAggFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillAggFuncHolder.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,10 +18,6 @@
 package org.apache.drill.exec.expr.fn;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.List;
-import java.util.Map;
 
 import org.apache.drill.common.exceptions.DrillRuntimeException;
 import org.apache.drill.common.types.TypeProtos.DataMode;
@@ -30,8 +26,6 @@ import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.expr.ClassGenerator;
 import org.apache.drill.exec.expr.ClassGenerator.BlockType;
 import org.apache.drill.exec.expr.ClassGenerator.HoldingContainer;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionCostCategory;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
 import org.apache.drill.exec.record.TypedFieldId;
 
@@ -44,7 +38,6 @@ import com.sun.codemodel.JExpression;
 import com.sun.codemodel.JForLoop;
 import com.sun.codemodel.JInvocation;
 import com.sun.codemodel.JMod;
-import com.sun.codemodel.JType;
 import com.sun.codemodel.JVar;
 
 class DrillAggFuncHolder extends DrillFuncHolder {
@@ -98,15 +91,15 @@ class DrillAggFuncHolder extends DrillFuncHolder {
         //Loop through all workspace vectors, to get the minimum of size of all workspace vectors.
         JVar sizeVar = setupBlock.decl(g.getModel().INT, "vectorSize", JExpr.lit(Integer.MAX_VALUE));
         JClass mathClass = g.getModel().ref(Math.class);
-        for (int id = 0; id<workspaceVars.length; id ++) {
-          if (!workspaceVars[id].isInject()) {
-            setupBlock.assign(sizeVar,mathClass.staticInvoke("min").arg(sizeVar).arg(g.getWorkspaceVectors().get(workspaceVars[id]).invoke("getValueCapacity")));
+        for (int id = 0; id < getWorkspaceVars().length; id ++) {
+          if (!getWorkspaceVars()[id].isInject()) {
+            setupBlock.assign(sizeVar,mathClass.staticInvoke("min").arg(sizeVar).arg(g.getWorkspaceVectors().get(getWorkspaceVars()[id]).invoke("getValueCapacity")));
           }
         }
 
-        for(int i =0 ; i < workspaceVars.length; i++) {
-          if (!workspaceVars[i].isInject()) {
-            setupBlock.assign(workspaceJVars[i], JExpr._new(g.getHolderType(workspaceVars[i].majorType)));
+        for(int i =0 ; i < getWorkspaceVars().length; i++) {
+          if (!getWorkspaceVars()[i].isInject()) {
+            setupBlock.assign(workspaceJVars[i], JExpr._new(g.getHolderType(getWorkspaceVars()[i].getMajorType())));
           }
         }
 
@@ -133,10 +126,10 @@ class DrillAggFuncHolder extends DrillFuncHolder {
 
   @Override
   public HoldingContainer renderEnd(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[]  workspaceJVars) {
-    HoldingContainer out = g.declare(returnValue.type, false);
+    HoldingContainer out = g.declare(getReturnType(), false);
     JBlock sub = new JBlock();
     g.getEvalBlock().add(sub);
-    JVar internalOutput = sub.decl(JMod.FINAL, g.getHolderType(returnValue.type), returnValue.name, JExpr._new(g.getHolderType(returnValue.type)));
+    JVar internalOutput = sub.decl(JMod.FINAL, g.getHolderType(getReturnType()), getReturnValue().getName(), JExpr._new(g.getHolderType(getReturnType())));
     addProtectedBlock(g, sub, output(), null, workspaceJVars, false);
     sub.assign(out.getHolder(), internalOutput);
         //hash aggregate uses workspace vectors. Initialization is done in "setup" and does not require "reset" block.
@@ -150,25 +143,27 @@ class DrillAggFuncHolder extends DrillFuncHolder {
 
 
   private JVar[] declareWorkspaceVectors(ClassGenerator<?> g) {
-    JVar[] workspaceJVars = new JVar[workspaceVars.length];
+    JVar[] workspaceJVars = new JVar[getWorkspaceVars().length];
 
-    for(int i =0 ; i < workspaceVars.length; i++){
-      if (workspaceVars[i].isInject() == true) {
-        workspaceJVars[i] = g.declareClassField("work", g.getModel()._ref(workspaceVars[i].type));
+    for(int i =0 ; i < getWorkspaceVars().length; i++){
+      if (getWorkspaceVars()[i].isInject()) {
+        workspaceJVars[i] = g.declareClassField("work", g.getModel()._ref(getWorkspaceVars()[i].getType()));
         g.getBlock(BlockType.SETUP).assign(workspaceJVars[i], g.getMappingSet().getIncoming().invoke("getContext").invoke("getManagedBuffer"));
       } else {
-        Preconditions.checkState(Types.isFixedWidthType(workspaceVars[i].majorType), String.format("Workspace variable '%s' in aggregation function '%s' is not allowed to have variable length type.", workspaceVars[i].name, registeredNames[0]));
-        Preconditions.checkState(workspaceVars[i].majorType.getMode()==DataMode.REQUIRED, String.format("Workspace variable '%s' in aggregation function '%s' is not allowed to have null or repeated type.", workspaceVars[i].name, registeredNames[0]));
+        Preconditions.checkState(Types.isFixedWidthType(getWorkspaceVars()[i].getMajorType()), String.format("Workspace variable '%s' in aggregation function '%s' is not allowed to " +
+            "have variable length type.", getWorkspaceVars()[i].getName(), getRegisteredNames()[0]));
+        Preconditions.checkState(getWorkspaceVars()[i].getMajorType().getMode()==DataMode.REQUIRED, String.format("Workspace variable '%s' in aggregation function '%s' is not allowed" +
+            " to have null or repeated type.", getWorkspaceVars()[i].getName(), getRegisteredNames()[0]));
 
         //workspaceJVars[i] = g.declareClassField("work", g.getHolderType(workspaceVars[i].majorType), JExpr._new(g.getHolderType(workspaceVars[i].majorType)));
-        workspaceJVars[i] = g.declareClassField("work", g.getHolderType(workspaceVars[i].majorType));
+        workspaceJVars[i] = g.declareClassField("work", g.getHolderType(getWorkspaceVars()[i].getMajorType()));
 
         //Declare a workspace vector for the workspace var.
-        TypedFieldId typedFieldId = new TypedFieldId(workspaceVars[i].majorType, g.getWorkspaceTypes().size());
+        TypedFieldId typedFieldId = new TypedFieldId(getWorkspaceVars()[i].getMajorType(), g.getWorkspaceTypes().size());
         JVar vv  = g.declareVectorValueSetupAndMember(g.getMappingSet().getWorkspace(), typedFieldId);
 
         g.getWorkspaceTypes().add(typedFieldId);
-        g.getWorkspaceVectors().put(workspaceVars[i], vv);
+        g.getWorkspaceVectors().put(getWorkspaceVars()[i], vv);
       }
     }
     return workspaceJVars;
@@ -179,9 +174,9 @@ class DrillAggFuncHolder extends DrillFuncHolder {
     if(!Strings.isNullOrEmpty(body) && !body.trim().isEmpty()){
       JBlock sub = new JBlock(true, true);
       addProtectedBlockHA(g, sub, body, null, workspaceJVars, wsIndexVariable);
-      initBlock.directStatement(String.format("/** start %s for function %s **/ ", bt.name(), registeredNames[0]));
+      initBlock.directStatement(String.format("/** start %s for function %s **/ ", bt.name(), getRegisteredNames()[0]));
       initBlock.add(sub);
-      initBlock.directStatement(String.format("/** end %s for function %s **/ ", bt.name(), registeredNames[0]));
+      initBlock.directStatement(String.format("/** end %s for function %s **/ ", bt.name(), getRegisteredNames()[0]));
     }
     return initBlock;
   }
@@ -202,28 +197,28 @@ class DrillAggFuncHolder extends DrillFuncHolder {
   private void addProtectedBlockHA(ClassGenerator<?> g, JBlock sub, String body, HoldingContainer[] inputVariables, JVar[] workspaceJVars, JExpression wsIndexVariable){
     if (inputVariables != null){
       for(int i =0; i < inputVariables.length; i++){
-        ValueReference parameter = parameters[i];
+        ValueReference parameter = getParameters()[i];
         HoldingContainer inputVariable = inputVariables[i];
-        sub.decl(inputVariable.getHolder().type(), parameter.name, inputVariable.getHolder());
+        sub.decl(inputVariable.getHolder().type(), parameter.getName(), inputVariable.getHolder());
       }
     }
 
     JVar[] internalVars = new JVar[workspaceJVars.length];
     for(int i =0; i < workspaceJVars.length; i++){
 
-      if (workspaceVars[i].isInject()) {
-        internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
+      if (getWorkspaceVars()[i].isInject()) {
+        internalVars[i] = sub.decl(g.getModel()._ref(getWorkspaceVars()[i].getType()), getWorkspaceVars()[i].getName(), workspaceJVars[i]);
         continue;
       }
       //sub.assign(workspaceJVars[i], JExpr._new(g.getHolderType(workspaceVars[i].majorType)));
       //Access workspaceVar through workspace vector.
-      JInvocation getValueAccessor = g.getWorkspaceVectors().get(workspaceVars[i]).invoke("getAccessor").invoke("get");
-      if (Types.usesHolderForGet(workspaceVars[i].majorType)) {
+      JInvocation getValueAccessor = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getAccessor").invoke("get");
+      if (Types.usesHolderForGet(getWorkspaceVars()[i].getMajorType())) {
         sub.add(getValueAccessor.arg(wsIndexVariable).arg(workspaceJVars[i]));
       } else {
         sub.assign(workspaceJVars[i].ref("value"), getValueAccessor.arg(wsIndexVariable));
       }
-      internalVars[i] = sub.decl(g.getHolderType(workspaceVars[i].majorType),  workspaceVars[i].name, workspaceJVars[i]);
+      internalVars[i] = sub.decl(g.getHolderType(getWorkspaceVars()[i].getMajorType()),  getWorkspaceVars()[i].getName(), workspaceJVars[i]);
     }
 
     Preconditions.checkNotNull(body);
@@ -234,19 +229,19 @@ class DrillAggFuncHolder extends DrillFuncHolder {
       sub.assign(workspaceJVars[i], internalVars[i]);
 
       // Injected buffers are not stored as vectors skip storing them in vectors
-      if (workspaceVars[i].isInject()) {
+      if (getWorkspaceVars()[i].isInject()) {
         continue;
       }
       //Change workspaceVar through workspace vector.
       JInvocation setMeth;
-      MajorType type = workspaceVars[i].majorType;
+      MajorType type = getWorkspaceVars()[i].getMajorType();
       if (Types.usesHolderForGet(type)) {
-          setMeth = g.getWorkspaceVectors().get(workspaceVars[i]).invoke("getMutator").invoke("setSafe").arg(wsIndexVariable).arg(workspaceJVars[i]);
+          setMeth = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getMutator").invoke("setSafe").arg(wsIndexVariable).arg(workspaceJVars[i]);
       }else{
         if (!Types.isFixedWidthType(type) || Types.isRepeated(type)) {
-          setMeth = g.getWorkspaceVectors().get(workspaceVars[i]).invoke("getMutator").invoke("setSafe").arg(wsIndexVariable).arg(workspaceJVars[i].ref("value"));
+          setMeth = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getMutator").invoke("setSafe").arg(wsIndexVariable).arg(workspaceJVars[i].ref("value"));
         } else {
-          setMeth = g.getWorkspaceVectors().get(workspaceVars[i]).invoke("getMutator").invoke("set").arg(wsIndexVariable).arg(workspaceJVars[i].ref("value"));
+          setMeth = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getMutator").invoke("set").arg(wsIndexVariable).arg(workspaceJVars[i].ref("value"));
         }
       }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillBooleanOPHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillBooleanOPHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillBooleanOPHolder.java
deleted file mode 100644
index af1d84f..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillBooleanOPHolder.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.drill.exec.expr.fn;
-
-public class DrillBooleanOPHolder extends DrillSimpleFuncHolder{
-
-  public DrillBooleanOPHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillComplexWriterFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillComplexWriterFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillComplexWriterFuncHolder.java
index a0bf134..2488e41 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillComplexWriterFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillComplexWriterFuncHolder.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -32,7 +32,7 @@ import com.sun.codemodel.JExpression;
 import com.sun.codemodel.JInvocation;
 import com.sun.codemodel.JVar;
 
-public class DrillComplexWriterFuncHolder extends DrillSimpleFuncHolder{
+public class DrillComplexWriterFuncHolder extends DrillSimpleFuncHolder {
 
   private FieldReference ref;
 
@@ -51,7 +51,7 @@ public class DrillComplexWriterFuncHolder extends DrillSimpleFuncHolder{
   @Override
   protected HoldingContainer generateEvalBody(ClassGenerator<?> g, HoldingContainer[] inputVariables, String body, JVar[] workspaceJVars) {
 
-    g.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", registeredNames[0]));
+    g.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", getRegisteredNames()[0]));
 
     JBlock sub = new JBlock(true, true);
     JBlock topSub = sub;
@@ -75,7 +75,7 @@ public class DrillComplexWriterFuncHolder extends DrillSimpleFuncHolder{
 
     g.getEvalBlock().add(complexWriter.invoke("setPosition").arg(g.getMappingSet().getValueWriteIndex()));
 
-    sub.decl(g.getModel()._ref(ComplexWriter.class), returnValue.name, complexWriter);
+    sub.decl(g.getModel()._ref(ComplexWriter.class), getReturnValue().getName(), complexWriter);
 
     // add the subblock after the out declaration.
     g.getEvalBlock().add(topSub);
@@ -91,7 +91,7 @@ public class DrillComplexWriterFuncHolder extends DrillSimpleFuncHolder{
 
     //jc._else().directStatement("System.out.println(\"debug : write successful, inIndex = \" + inIndex);");
 
-    g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", registeredNames[0]));
+    g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", getRegisteredNames()[0]));
 
     return null;
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAddFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAddFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAddFuncHolder.java
deleted file mode 100644
index 00ad1f5..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAddFuncHolder.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.util.DecimalScalePrecisionAddFunction;
-import org.apache.drill.exec.expr.DrillSimpleFunc;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-import org.apache.drill.exec.util.DecimalUtility;
-
-public class DrillDecimalAddFuncHolder extends DrillSimpleFuncHolder{
-
-  public DrillDecimalAddFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-  /*
-   * This function scope is used by add and subtract functions for decimal data type.
-   * DecimalScalePrecisionAddFunction is used to compute the output types'
-   * scale and precision
-   */
-  @Override
-  public MajorType getReturnType(List<LogicalExpression> args) {
-
-    TypeProtos.DataMode mode = returnValue.type.getMode();
-
-    if (nullHandling == NullHandling.NULL_IF_NULL) {
-      // if any one of the input types is nullable, then return nullable return type
-      for (LogicalExpression e : args) {
-        if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-          mode = TypeProtos.DataMode.OPTIONAL;
-          break;
-        }
-      }
-    }
-
-
-    /* Get the result's scale and precision. This is a function scope for add function, assert we have
-     * only two inputs
-     */
-    assert args.size() == 2;
-
-    DecimalScalePrecisionAddFunction outputScalePrec =
-        new DecimalScalePrecisionAddFunction(args.get(0).getMajorType().getPrecision(), args.get(0).getMajorType().getScale(),
-            args.get(1).getMajorType().getPrecision(), args.get(1).getMajorType().getScale());
-    return (TypeProtos.MajorType.newBuilder().setMinorType(DecimalUtility.getDecimalDataType(outputScalePrec.getOutputPrecision()))
-        .setScale(outputScalePrec.getOutputScale()).setPrecision(outputScalePrec.getOutputPrecision()).setMode(mode).build());
-  }
-
-  @Override
-  public boolean checkPrecisionRange() {
-    return true;
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAggFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAggFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAggFuncHolder.java
deleted file mode 100644
index 78d865c..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalAggFuncHolder.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-
-public class DrillDecimalAggFuncHolder extends DrillAggFuncHolder {
-
-  public DrillDecimalAggFuncHolder(FunctionAttributes attributes, FunctionInitializer initializer) {
-    super(attributes, initializer);
-  }
-
-  @Override
-  public TypeProtos.MajorType getReturnType(List<LogicalExpression> args) {
-
-    int scale = 0;
-    int precision = 0;
-
-    // Get the max scale and precision from the inputs
-    for (LogicalExpression e : args) {
-      scale = Math.max(scale, e.getMajorType().getScale());
-      precision = Math.max(precision, e.getMajorType().getPrecision());
-    }
-
-    return (TypeProtos.MajorType.newBuilder().setMinorType(returnValue.type.getMinorType()).setScale(scale).setPrecision(precision).setMode(TypeProtos.DataMode.REQUIRED).build());
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalCastFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalCastFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalCastFuncHolder.java
deleted file mode 100644
index 2fb9e28..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalCastFuncHolder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-
-import org.apache.drill.common.exceptions.DrillRuntimeException;
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.expression.ValueExpressions;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-
-public class DrillDecimalCastFuncHolder extends DrillSimpleFuncHolder {
-
-  public DrillDecimalCastFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-    @Override
-    public MajorType getReturnType(List<LogicalExpression> args) {
-
-        TypeProtos.DataMode mode = returnValue.type.getMode();
-
-        if (nullHandling == NullHandling.NULL_IF_NULL) {
-            // if any one of the input types is nullable, then return nullable return type
-            for (LogicalExpression e : args) {
-                if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-                    mode = TypeProtos.DataMode.OPTIONAL;
-                    break;
-                }
-            }
-        }
-
-        if (args.size() != 3) {
-            StringBuilder err = new StringBuilder();
-            for (int i = 0; i < args.size(); i++) {
-                err.append("arg" + i + ": " + args.get(i).getMajorType().getMinorType());
-            }
-            throw new DrillRuntimeException("Decimal cast function invoked with incorect arguments" + err);
-        }
-
-        int scale = (int) ((ValueExpressions.LongExpression)(args.get(args.size() - 1))).getLong();
-        int precision = (int) ((ValueExpressions.LongExpression)(args.get(args.size() - 2))).getLong();
-        return (TypeProtos.MajorType.newBuilder().setMinorType(returnValue.type.getMinorType()).setScale(scale).setPrecision(precision).setMode(mode).build());
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalDivScaleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalDivScaleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalDivScaleFuncHolder.java
deleted file mode 100644
index c867890..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalDivScaleFuncHolder.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.util.DecimalScalePrecisionDivideFunction;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-import org.apache.drill.exec.util.DecimalUtility;
-
-public class DrillDecimalDivScaleFuncHolder extends DrillSimpleFuncHolder{
-
-  public DrillDecimalDivScaleFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-  /*
-   * This function scope is used by divide functions for decimal data type.
-   * DecimalScalePrecisionDivideFunction is used to compute the output types'
-   * scale and precision
-   */
-  @Override
-  public MajorType getReturnType(List<LogicalExpression> args) {
-
-    TypeProtos.DataMode mode = returnValue.type.getMode();
-
-    if (nullHandling == NullHandling.NULL_IF_NULL) {
-      // if any one of the input types is nullable, then return nullable return type
-      for (LogicalExpression e : args) {
-        if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-          mode = TypeProtos.DataMode.OPTIONAL;
-          break;
-        }
-      }
-    }
-
-
-    /* Get the result's scale and precision. This is a function scope for Divide function, assert we have
-     * only two inputs
-     */
-    assert args.size() == 2;
-
-    DecimalScalePrecisionDivideFunction outputScalePrec =
-      new DecimalScalePrecisionDivideFunction(args.get(0).getMajorType().getPrecision(), args.get(0).getMajorType().getScale(),
-                                              args.get(1).getMajorType().getPrecision(), args.get(1).getMajorType().getScale());
-    return (TypeProtos.MajorType.newBuilder().setMinorType(DecimalUtility.getDecimalDataType(outputScalePrec.getOutputPrecision()))
-        .setScale(outputScalePrec.getOutputScale()).setPrecision(outputScalePrec.getOutputPrecision()).setMode(mode).build());
-  }
-
-  @Override
-  public boolean checkPrecisionRange() {
-    return true;
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalMaxScaleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalMaxScaleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalMaxScaleFuncHolder.java
deleted file mode 100644
index e0b8f9a..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalMaxScaleFuncHolder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.exec.expr.DrillSimpleFunc;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-
-public class DrillDecimalMaxScaleFuncHolder extends DrillSimpleFuncHolder {
-
-  public DrillDecimalMaxScaleFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-    @Override
-    public MajorType getReturnType(List<LogicalExpression> args) {
-
-        TypeProtos.DataMode mode = returnValue.type.getMode();
-        boolean nullInput = false;
-        int scale = 0;
-        int precision = 0;
-
-        for (LogicalExpression e : args) {
-            if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-                nullInput = true;
-            }
-            scale = Math.max(scale, e.getMajorType().getScale());
-            precision = Math.max(precision, e.getMajorType().getPrecision());
-        }
-
-        if (nullHandling == NullHandling.NULL_IF_NULL && nullInput) {
-            mode = TypeProtos.DataMode.OPTIONAL;
-        }
-
-        return (TypeProtos.MajorType.newBuilder().setMinorType(returnValue.type.getMinorType()).setScale(scale).setPrecision(precision).setMode(mode).build());
-    }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalModScaleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalModScaleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalModScaleFuncHolder.java
deleted file mode 100644
index b373fa9..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalModScaleFuncHolder.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.util.DecimalScalePrecisionModFunction;
-import org.apache.drill.exec.expr.DrillSimpleFunc;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-import org.apache.drill.exec.util.DecimalUtility;
-
-public class DrillDecimalModScaleFuncHolder extends DrillSimpleFuncHolder{
-
-  public DrillDecimalModScaleFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-  /*
-   * This function scope is used by divide functions for decimal data type.
-   * DecimalScalePrecisionDivideFunction is used to compute the output types'
-   * scale and precision
-   */
-  @Override
-  public MajorType getReturnType(List<LogicalExpression> args) {
-
-    TypeProtos.DataMode mode = returnValue.type.getMode();
-
-    if (nullHandling == NullHandling.NULL_IF_NULL) {
-      // if any one of the input types is nullable, then return nullable return type
-      for (LogicalExpression e : args) {
-        if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-          mode = TypeProtos.DataMode.OPTIONAL;
-          break;
-        }
-      }
-    }
-
-
-    /* Get the result's scale and precision. This is a function scope for Divide function, assert we have
-     * only two inputs
-     */
-    assert args.size() == 2;
-
-    DecimalScalePrecisionModFunction outputScalePrec =
-        new DecimalScalePrecisionModFunction(args.get(0).getMajorType().getPrecision(), args.get(0).getMajorType().getScale(),
-            args.get(1).getMajorType().getPrecision(), args.get(1).getMajorType().getScale());
-    return (TypeProtos.MajorType.newBuilder().setMinorType(DecimalUtility.getDecimalDataType(outputScalePrec.getOutputPrecision()))
-        .setScale(outputScalePrec.getOutputScale()).setPrecision(outputScalePrec.getOutputPrecision()).setMode(mode).build());
-  }
-
-  @Override
-  public boolean checkPrecisionRange() {
-    return true;
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSetScaleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSetScaleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSetScaleFuncHolder.java
deleted file mode 100644
index a10d6ea..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSetScaleFuncHolder.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.expression.ValueExpressions;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-
-public class DrillDecimalSetScaleFuncHolder extends DrillSimpleFuncHolder{
-
-  public DrillDecimalSetScaleFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-  @Override
-  public MajorType getReturnType(List<LogicalExpression> args) {
-
-    TypeProtos.DataMode mode = returnValue.type.getMode();
-    int scale = 0;
-    int precision = 0;
-    int i = 0;
-
-    if (nullHandling == NullHandling.NULL_IF_NULL) {
-      // if any one of the input types is nullable, then return nullable return type
-      for (LogicalExpression e : args) {
-
-        precision = Math.max(precision, e.getMajorType().getPrecision());
-        if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-          mode = TypeProtos.DataMode.OPTIONAL;
-        }
-      }
-
-      /* Used by functions like round, truncate which specify the scale for
-       * the output as the second argument
-       */
-      assert (args.size() == 2) && (args.get(1) instanceof ValueExpressions.IntExpression);
-
-      // Get the scale from the second argument which should be a constant
-      scale = ((ValueExpressions.IntExpression) args.get(1)).getInt();
-    }
-
-    return (TypeProtos.MajorType.newBuilder().setMinorType(returnValue.type.getMinorType()).setScale(scale).setPrecision(precision).setMode(mode).build());
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumAggFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumAggFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumAggFuncHolder.java
deleted file mode 100644
index 89ea7cc..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumAggFuncHolder.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-
-public class DrillDecimalSumAggFuncHolder extends DrillAggFuncHolder {
-
-  public DrillDecimalSumAggFuncHolder(FunctionAttributes attributes, FunctionInitializer initializer) {
-    super(attributes, initializer);
-  }
-
-  @Override
-  public TypeProtos.MajorType getReturnType(List<LogicalExpression> args) {
-
-    int scale = 0;
-    int precision = 0;
-
-    // Get the max scale and precision from the inputs
-    for (LogicalExpression e : args) {
-      scale = Math.max(scale, e.getMajorType().getScale());
-      precision = Math.max(precision, e.getMajorType().getPrecision());
-    }
-
-    return (TypeProtos.MajorType.newBuilder().setMinorType(returnValue.type.getMinorType()).setScale(scale).setPrecision(38).setMode(TypeProtos.DataMode.REQUIRED).build());
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumScaleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumScaleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumScaleFuncHolder.java
deleted file mode 100644
index d45e674..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalSumScaleFuncHolder.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.util.DecimalScalePrecisionMulFunction;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-import org.apache.drill.exec.util.DecimalUtility;
-
-public class DrillDecimalSumScaleFuncHolder extends DrillSimpleFuncHolder{
-
-
-  public DrillDecimalSumScaleFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-    @Override
-    public MajorType getReturnType(List<LogicalExpression> args) {
-
-        TypeProtos.DataMode mode = returnValue.type.getMode();
-
-        if (nullHandling == NullHandling.NULL_IF_NULL) {
-            // if any one of the input types is nullable, then return nullable return type
-            for (LogicalExpression e : args) {
-                if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-                    mode = TypeProtos.DataMode.OPTIONAL;
-                    break;
-                }
-            }
-        }
-
-    /* Get the result's scale and precision. This is a function scope for Multiply function, assert we have
-     * only two inputs
-     */
-    assert args.size() == 2;
-
-    DecimalScalePrecisionMulFunction outputScalePrec =
-      new DecimalScalePrecisionMulFunction(args.get(0).getMajorType().getPrecision(), args.get(0).getMajorType().getScale(),
-                                              args.get(1).getMajorType().getPrecision(), args.get(1).getMajorType().getScale());
-        return (TypeProtos.MajorType.newBuilder().setMinorType(DecimalUtility.getDecimalDataType(outputScalePrec.getOutputPrecision()))
-            .setScale(outputScalePrec.getOutputScale()).setPrecision(outputScalePrec.getOutputPrecision()).setMode(mode).build());
-    }
-
-    @Override
-    public boolean checkPrecisionRange() {
-        return true;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalZeroScaleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalZeroScaleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalZeroScaleFuncHolder.java
deleted file mode 100644
index f941750..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillDecimalZeroScaleFuncHolder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.exec.expr.DrillSimpleFunc;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-
-public class DrillDecimalZeroScaleFuncHolder extends DrillSimpleFuncHolder{
-
-  public DrillDecimalZeroScaleFuncHolder(FunctionAttributes functionAttributes, FunctionInitializer initializer) {
-    super(functionAttributes, initializer);
-  }
-
-  /* This function scope is used when we need to remove the scale part.
-   * trunc and round functions with single argument use this
-   */
-  @Override
-  public MajorType getReturnType(List<LogicalExpression> args) {
-
-    int precision = 0;
-    TypeProtos.DataMode mode = returnValue.type.getMode();
-
-    if (nullHandling == NullHandling.NULL_IF_NULL) {
-      // if any one of the input types is nullable, then return nullable return type
-      for (LogicalExpression e : args) {
-        if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-          mode = TypeProtos.DataMode.OPTIONAL;
-        }
-        precision = Math.max(precision, e.getMajorType().getPrecision());
-      }
-    }
-
-    return (TypeProtos.MajorType.newBuilder().setMinorType(returnValue.type.getMinorType()).setScale(0).setPrecision(precision).setMode(mode).build());
-  }
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
index a859889..b25aa43 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -19,16 +19,12 @@ package org.apache.drill.exec.expr.fn;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.Set;
 
-import com.google.common.collect.Sets;
 import org.apache.drill.common.exceptions.DrillRuntimeException;
 import org.apache.drill.common.exceptions.UserException;
 import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.FunctionHolderExpression;
 import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.TypeProtos.DataMode;
 import org.apache.drill.common.types.TypeProtos.MajorType;
 import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.common.types.Types;
@@ -39,7 +35,6 @@ import org.apache.drill.exec.expr.ClassGenerator.BlockType;
 import org.apache.drill.exec.expr.ClassGenerator.HoldingContainer;
 import org.apache.drill.exec.expr.DrillFuncHolderExpr;
 import org.apache.drill.exec.expr.TypeHelper;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
 import org.apache.drill.exec.ops.UdfUtilities;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
@@ -56,33 +51,12 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillFuncHolder.class);
 
   private final FunctionAttributes attributes;
-  protected final FunctionTemplate.FunctionScope scope;
-  protected final FunctionTemplate.NullHandling nullHandling;
-  protected final FunctionTemplate.FunctionCostCategory costCategory;
-  protected final boolean isNiladic;
-  protected final boolean isBinaryCommutative;
-  protected final boolean isDeterministic;
-  protected final String[] registeredNames;
-  protected final WorkspaceReference[] workspaceVars;
-  protected final ValueReference[] parameters;
-  protected final ValueReference returnValue;
   private final FunctionInitializer initializer;
 
   public DrillFuncHolder(
       FunctionAttributes attributes,
       FunctionInitializer initializer) {
-    super();
     this.attributes = attributes;
-    this.scope = attributes.getScope();
-    this.nullHandling = attributes.getNullHandling();
-    this.costCategory = attributes.getCostCategory();
-    this.isNiladic = attributes.isNiladic();
-    this.isBinaryCommutative = attributes.isBinaryCommutative();
-    this.isDeterministic = attributes.isDeterministic();
-    this.registeredNames = attributes.getRegisteredNames();
-    this.workspaceVars = attributes.getWorkspaceVars();
-    this.parameters = attributes.getParameters();
-    this.returnValue = attributes.getReturnValue();
     this.initializer = initializer;
   }
 
@@ -108,11 +82,11 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
   @Override
   public JVar[] renderStart(ClassGenerator<?> g, HoldingContainer[] inputVariables) {
     return declareWorkspaceVariables(g);
-  };
+  }
 
   @Override
   public void renderMiddle(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[] workspaceJVars) {
-  };
+  }
 
   @Override
   public abstract HoldingContainer renderEnd(ClassGenerator<?> g, HoldingContainer[] inputVariables,
@@ -149,7 +123,7 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
   public String getInputParameters() {
     StringBuilder builder = new StringBuilder();
     builder.append("");
-    for (ValueReference ref : parameters) {
+    for (ValueReference ref : attributes.getParameters()) {
       final MajorType type = ref.getType();
       builder.append(",");
       builder.append(type.getMinorType().toString());
@@ -167,12 +141,12 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
   }
 
   protected JVar[] declareWorkspaceVariables(ClassGenerator<?> g) {
-    JVar[] workspaceJVars = new JVar[workspaceVars.length];
-    for (int i = 0; i < workspaceVars.length; i++) {
-      WorkspaceReference ref = workspaceVars[i];
-      JType jtype = g.getModel()._ref(ref.type);
+    JVar[] workspaceJVars = new JVar[attributes.getWorkspaceVars().length];
+    for (int i = 0; i < attributes.getWorkspaceVars().length; i++) {
+      WorkspaceReference ref = attributes.getWorkspaceVars()[i];
+      JType jtype = g.getModel()._ref(ref.getType());
 
-      if (ScalarReplacementTypes.CLASSES.contains(ref.type)) {
+      if (ScalarReplacementTypes.CLASSES.contains(ref.getType())) {
         workspaceJVars[i] = g.declareClassField("work", jtype);
         JBlock b = g.getBlock(SignatureHolder.DRILL_INIT_METHOD);
         b.assign(workspaceJVars[i], JExpr._new(jtype));
@@ -207,9 +181,9 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
       } else {
         addProtectedBlock(g, sub, body, null, workspaceJVars, false);
       }
-      g.getBlock(bt).directStatement(String.format("/** start %s for function %s **/ ", bt.name(), registeredNames[0]));
+      g.getBlock(bt).directStatement(String.format("/** start %s for function %s **/ ", bt.name(), attributes.getRegisteredNames()[0]));
       g.getBlock(bt).add(sub);
-      g.getBlock(bt).directStatement(String.format("/** end %s for function %s **/ ", bt.name(), registeredNames[0]));
+      g.getBlock(bt).directStatement(String.format("/** end %s for function %s **/ ", bt.name(), attributes.getRegisteredNames()[0]));
     }
   }
 
@@ -221,15 +195,15 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
           continue;
         }
 
-        ValueReference parameter = parameters[i];
+        ValueReference parameter = attributes.getParameters()[i];
         HoldingContainer inputVariable = inputVariables[i];
-        if (parameter.isFieldReader && ! inputVariable.isReader() && ! Types.isComplex(inputVariable.getMajorType()) && inputVariable.getMinorType() != MinorType.UNION) {
+        if (parameter.isFieldReader() && ! inputVariable.isReader() && ! Types.isComplex(inputVariable.getMajorType()) && inputVariable.getMinorType() != MinorType.UNION) {
           JType singularReaderClass = g.getModel()._ref(TypeHelper.getHolderReaderImpl(inputVariable.getMajorType().getMinorType(),
               inputVariable.getMajorType().getMode()));
           JType fieldReadClass = g.getModel()._ref(FieldReader.class);
-          sub.decl(fieldReadClass, parameter.name, JExpr._new(singularReaderClass).arg(inputVariable.getHolder()));
+          sub.decl(fieldReadClass, parameter.getName(), JExpr._new(singularReaderClass).arg(inputVariable.getHolder()));
         } else {
-          sub.decl(inputVariable.getHolder().type(), parameter.name, inputVariable.getHolder());
+          sub.decl(inputVariable.getHolder().type(), parameter.getName(), inputVariable.getHolder());
         }
       }
     }
@@ -237,9 +211,9 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
     JVar[] internalVars = new JVar[workspaceJVars.length];
     for (int i = 0; i < workspaceJVars.length; i++) {
       if (decConstInputOnly) {
-        internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
+        internalVars[i] = sub.decl(g.getModel()._ref(attributes.getWorkspaceVars()[i].getType()), attributes.getWorkspaceVars()[i].getName(), workspaceJVars[i]);
       } else {
-        internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
+        internalVars[i] = sub.decl(g.getModel()._ref(attributes.getWorkspaceVars()[i].getType()), attributes.getWorkspaceVars()[i].getName(), workspaceJVars[i]);
       }
 
     }
@@ -255,20 +229,20 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
 
   public boolean matches(MajorType returnType, List<MajorType> argTypes) {
 
-    if (!softCompare(returnType, returnValue.type)) {
+    if (!softCompare(returnType, attributes.getReturnValue().getType())) {
       // logger.debug(String.format("Call [%s] didn't match as return type [%s] was different than expected [%s]. ",
       // call.getDefinition().getName(), returnValue.type, call.getMajorType()));
       return false;
     }
 
-    if (argTypes.size() != parameters.length) {
+    if (argTypes.size() != attributes.getParameters().length) {
       // logger.debug(String.format("Call [%s] didn't match as the number of arguments provided [%d] were different than expected [%d]. ",
       // call.getDefinition().getName(), parameters.length, call.args.size()));
       return false;
     }
 
-    for (int i = 0; i < parameters.length; i++) {
-      if (!softCompare(parameters[i].type, argTypes.get(i))) {
+    for (int i = 0; i < attributes.getParameters().length; i++) {
+      if (!softCompare(attributes.getParameters()[i].getType(), argTypes.get(i))) {
         // logger.debug(String.format("Call [%s] didn't match as the argument [%s] didn't match the expected type [%s]. ",
         // call.getDefinition().getName(), arg.getMajorType(), param.type));
         return false;
@@ -280,48 +254,24 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
 
   @Override
   public MajorType getParmMajorType(int i) {
-    return this.parameters[i].type;
+    return attributes.getParameters()[i].getType();
   }
 
   @Override
   public int getParamCount() {
-    return this.parameters.length;
+    return attributes.getParameters().length;
   }
 
   public boolean isConstant(int i) {
-    return this.parameters[i].isConstant;
+    return attributes.getParameters()[i].isConstant();
   }
 
   public boolean isFieldReader(int i) {
-    return this.parameters[i].isFieldReader;
+    return attributes.getParameters()[i].isFieldReader();
   }
 
   public MajorType getReturnType(final List<LogicalExpression> logicalExpressions) {
-    if (returnValue.type.getMinorType() == MinorType.UNION) {
-      final Set<MinorType> subTypes = Sets.newHashSet();
-      for(final ValueReference ref : parameters) {
-        subTypes.add(ref.getType().getMinorType());
-      }
-
-      final MajorType.Builder builder = MajorType.newBuilder()
-          .setMinorType(MinorType.UNION)
-          .setMode(DataMode.OPTIONAL);
-
-      for(final MinorType subType : subTypes) {
-        builder.addSubType(subType);
-      }
-      return builder.build();
-    }
-
-    if(nullHandling == NullHandling.NULL_IF_NULL) {
-      // if any one of the input types is nullable, then return nullable return type
-      for(final LogicalExpression logicalExpression : logicalExpressions) {
-        if(logicalExpression.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
-          return Types.optional(returnValue.type.getMinorType());
-        }
-      }
-    }
-    return returnValue.type;
+    return attributes.getReturnType().getType(logicalExpressions, attributes);
   }
 
   public NullHandling getNullHandling() {
@@ -340,118 +290,36 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
     return attributes.getCostCategory().getValue();
   }
 
-  @Override
-  public String toString() {
-    final int maxLen = 10;
-    return this.getClass().getSimpleName()
-        + " [functionNames=" + Arrays.toString(registeredNames)
-        + ", returnType=" + Types.toString(returnValue.type)
-        + ", nullHandling=" + nullHandling
-        + ", parameters=" + (parameters != null ? Arrays.asList(parameters).subList(0, Math.min(parameters.length, maxLen)) : null) + "]";
+  public ValueReference[] getParameters() {
+    return attributes.getParameters();
   }
 
-  public WorkspaceReference[] getWorkspaceVars() {
-    return this.workspaceVars;
+  public boolean checkPrecisionRange() {
+    return attributes.checkPrecisionRange();
   }
 
-  public ValueReference[] getParameters() {
-    return this.parameters;
+  public MajorType getReturnType() {
+    return attributes.getReturnValue().getType();
   }
 
-  public static class ValueReference {
-    MajorType type;
-    String name;
-    boolean isConstant = false;
-    boolean isFieldReader = false;
-    boolean isComplexWriter = false;
-
-    public ValueReference(MajorType type, String name) {
-      super();
-      Preconditions.checkNotNull(type);
-      Preconditions.checkNotNull(name);
-      this.type = type;
-      this.name = name;
-    }
-
-    public MajorType getType() {
-      return type;
-    }
-
-    public String getName() {
-      return name;
-    }
-
-    public void setConstant(boolean isConstant) {
-      this.isConstant = isConstant;
-    }
-
-    @Override
-    public String toString() {
-      return "ValueReference [type=" + Types.toString(type) + ", name=" + name + "]";
-    }
-
-    public static ValueReference createFieldReaderRef(String name) {
-      MajorType type = Types.required(MinorType.LATE);
-      ValueReference ref = new ValueReference(type, name);
-      ref.isFieldReader = true;
-
-      return ref;
-    }
-
-    public static ValueReference createComplexWriterRef(String name) {
-      MajorType type = Types.required(MinorType.LATE);
-      ValueReference ref = new ValueReference(type, name);
-      ref.isComplexWriter = true;
-      return ref;
-    }
-
-    public boolean isComplexWriter() {
-      return isComplexWriter;
-    }
-
+  public ValueReference getReturnValue() {
+    return attributes.getReturnValue();
   }
 
-  public static class WorkspaceReference {
-    Class<?> type;
-    String name;
-    MajorType majorType;
-    boolean inject;
-
-    public WorkspaceReference(Class<?> type, String name, boolean inject) {
-      super();
-      Preconditions.checkNotNull(type);
-      Preconditions.checkNotNull(name);
-      this.type = type;
-      this.name = name;
-      this.inject = inject;
-    }
-
-    void setMajorType(MajorType majorType) {
-      this.majorType = majorType;
-    }
-
-    public boolean isInject() {
-      return inject;
-    }
-
-    public Class<?> getType() {
-      return type;
-    }
-
-    public String getName() {
-      return name;
-    }
+  public WorkspaceReference[] getWorkspaceVars() {
+    return attributes.getWorkspaceVars();
   }
 
-  public boolean checkPrecisionRange() {
-    return false;
+  @Override
+  public String toString() {
+    final int maxLen = 10;
+    return this.getClass().getSimpleName()
+        + " [functionNames=" + Arrays.toString(attributes.getRegisteredNames())
+        + ", returnType=" + Types.toString(attributes.getReturnValue().getType())
+        + ", nullHandling=" + attributes.getNullHandling()
+        + ", parameters=" + (attributes.getParameters() != null ?
+        Arrays.asList(attributes.getParameters()).subList(0, Math.min(attributes.getParameters().length, maxLen)) : null) + "]";
   }
 
-  public MajorType getReturnType() {
-    return returnValue.type;
-  }
 
-  public ValueReference getReturnValue() {
-    return returnValue;
-  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
index 655f571..8f0591f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -77,8 +77,8 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder {
     //If the function's annotation specifies a parameter has to be constant expression, but the HoldingContainer
     //for the argument is not, then raise exception.
     for (int i =0; i < inputVariables.length; i++) {
-      if (parameters[i].isConstant && !inputVariables[i].isConstant()) {
-        throw new DrillRuntimeException(String.format("The argument '%s' of Function '%s' has to be constant!", parameters[i].name, this.getRegisteredNames()[0]));
+      if (getParameters()[i].isConstant() && !inputVariables[i].isConstant()) {
+        throw new DrillRuntimeException(String.format("The argument '%s' of Function '%s' has to be constant!", getParameters()[i].getName(), this.getRegisteredNames()[0]));
       }
     }
     generateBody(g, BlockType.SETUP, setupBody(), inputVariables, workspaceJVars, true);
@@ -90,15 +90,15 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder {
 
   protected HoldingContainer generateEvalBody(ClassGenerator<?> g, HoldingContainer[] inputVariables, String body, JVar[] workspaceJVars) {
 
-    g.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", registeredNames[0]));
+    g.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", getRegisteredNames()[0]));
 
     JBlock sub = new JBlock(true, true);
     JBlock topSub = sub;
     HoldingContainer out = null;
-    MajorType returnValueType = returnValue.type;
+    MajorType returnValueType = getReturnType();
 
     // add outside null handling if it is defined.
-    if (nullHandling == NullHandling.NULL_IF_NULL) {
+    if (getNullHandling() == NullHandling.NULL_IF_NULL) {
       JExpression e = null;
       for (HoldingContainer v : inputVariables) {
         if (v.isOptional()) {
@@ -118,7 +118,7 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder {
 
       if (e != null) {
         // if at least one expression must be checked, set up the conditional.
-        returnValueType = returnValue.type.toBuilder().setMode(DataMode.OPTIONAL).build();
+        returnValueType = getReturnType().toBuilder().setMode(DataMode.OPTIONAL).build();
         out = g.declare(returnValueType);
         e = e.eq(JExpr.lit(0));
         JConditional jc = sub._if(e);
@@ -135,7 +135,7 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder {
     g.getEvalBlock().add(topSub);
 
 
-    JVar internalOutput = sub.decl(JMod.FINAL, g.getHolderType(returnValueType), returnValue.name, JExpr._new(g.getHolderType(returnValueType)));
+    JVar internalOutput = sub.decl(JMod.FINAL, g.getHolderType(returnValueType), getReturnValue().getName(), JExpr._new(g.getHolderType(returnValueType)));
     addProtectedBlock(g, sub, body, inputVariables, workspaceJVars, false);
     if (sub != topSub) {
       sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
@@ -145,7 +145,7 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder {
       sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
     }
 
-    g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", registeredNames[0]));
+    g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", getRegisteredNames()[0]));
 
     return out;
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionAttributes.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionAttributes.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionAttributes.java
index df8876d..4fd5be7 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionAttributes.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionAttributes.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -17,63 +17,58 @@
  */
 package org.apache.drill.exec.expr.fn;
 
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionCostCategory;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-import org.apache.drill.exec.expr.fn.DrillFuncHolder.ValueReference;
-import org.apache.drill.exec.expr.fn.DrillFuncHolder.WorkspaceReference;
 
 /**
  * Attributes of a function
  * Those are used in code generation and optimization.
  */
 public class FunctionAttributes {
-  private final FunctionScope scope;
-  private final NullHandling nullHandling;
-  private final boolean isBinaryCommutative;
-  private final boolean isDeterministic;
+
+  private final FunctionTemplate template;
   private final String[] registeredNames;
   private final ValueReference[] parameters;
   private final ValueReference returnValue;
   private final WorkspaceReference[] workspaceVars;
-  private final FunctionCostCategory costCategory;
-  private final boolean isNiladic;
-
-  public FunctionAttributes(FunctionScope scope, NullHandling nullHandling, boolean isBinaryCommutative,
-      boolean isDeteministic, String[] registeredNames, ValueReference[] parameters, ValueReference returnValue,
-      WorkspaceReference[] workspaceVars, FunctionCostCategory costCategory, boolean isNiladic) {
-    super();
-    this.scope = scope;
-    this.nullHandling = nullHandling;
-    this.isBinaryCommutative = isBinaryCommutative;
-    this.isDeterministic = isDeteministic;
-    this.registeredNames = registeredNames;
+
+
+  public FunctionAttributes (FunctionTemplate template,
+                             ValueReference[] parameters,
+                             ValueReference returnValue,
+                             WorkspaceReference[] workspaceVars) {
+    this.template = template;
+    this.registeredNames = ((template.name().isEmpty()) ? template.names() : new String[] {template.name()});
     this.parameters = parameters;
     this.returnValue = returnValue;
     this.workspaceVars = workspaceVars;
-    this.costCategory = costCategory;
-    this.isNiladic = isNiladic;
   }
 
   public FunctionScope getScope() {
-    return scope;
+    return template.scope();
+  }
+
+  public FunctionTemplate.ReturnType getReturnType() {
+    return template.returnType();
   }
 
   public NullHandling getNullHandling() {
-    return nullHandling;
+    return template.nulls();
   }
 
   public boolean isBinaryCommutative() {
-    return isBinaryCommutative;
+    return template.isBinaryCommutative();
   }
 
   @Deprecated
   public boolean isRandom() {
-    return !isDeterministic;
+    return template.isRandom();
   }
 
   public boolean isDeterministic() {
-    return isDeterministic;
+    return !template.isRandom();
   }
 
   public String[] getRegisteredNames() {
@@ -93,10 +88,12 @@ public class FunctionAttributes {
   }
 
   public FunctionCostCategory getCostCategory() {
-    return costCategory;
+    return template.costCategory();
   }
 
   public boolean isNiladic() {
-    return isNiladic;
+    return template.isNiladic();
   }
+
+  public boolean checkPrecisionRange() { return template.checkPrecisionRange(); }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6741e68a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
index b793095..ca5605a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -34,8 +34,6 @@ import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
 import org.apache.drill.exec.expr.annotations.Output;
 import org.apache.drill.exec.expr.annotations.Param;
 import org.apache.drill.exec.expr.annotations.Workspace;
-import org.apache.drill.exec.expr.fn.DrillFuncHolder.ValueReference;
-import org.apache.drill.exec.expr.fn.DrillFuncHolder.WorkspaceReference;
 import org.apache.drill.exec.expr.holders.ValueHolder;
 import org.apache.drill.exec.ops.UdfUtilities;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
@@ -174,54 +172,24 @@ public class FunctionConverter {
     }
 
     FunctionInitializer initializer = new FunctionInitializer(func.getClassName(), classLoader);
-    try{
+    try {
       // return holder
       ValueReference[] ps = params.toArray(new ValueReference[params.size()]);
       WorkspaceReference[] works = workspaceFields.toArray(new WorkspaceReference[workspaceFields.size()]);
 
+      FunctionAttributes functionAttributes = new FunctionAttributes(template, ps, outputField, works);
 
-      String[] registeredNames = ((template.name().isEmpty()) ? template.names() : new String[] {template.name()} );
-      boolean isDeteministic = ! template.isRandom();
-      FunctionAttributes functionAttributes = new FunctionAttributes(
-          template.scope(),
-          template.nulls(),
-          template.isBinaryCommutative(),
-          isDeteministic, registeredNames, ps, outputField, works, template.costCategory(), template.isNiladic());
       switch (template.scope()) {
-      case POINT_AGGREGATE:
-        return new DrillAggFuncHolder(functionAttributes, initializer);
-      case DECIMAL_AGGREGATE:
-        return new DrillDecimalAggFuncHolder(functionAttributes, initializer);
-      case DECIMAL_SUM_AGGREGATE:
-        return new DrillDecimalSumAggFuncHolder(functionAttributes, initializer);
-      case SIMPLE:
-        if (outputField.isComplexWriter) {
-          return new DrillComplexWriterFuncHolder(functionAttributes, initializer);
-        } else {
-          return new DrillSimpleFuncHolder(functionAttributes, initializer);
-        }
-      case SC_BOOLEAN_OPERATOR:
-        return new DrillBooleanOPHolder(functionAttributes, initializer);
-      case DECIMAL_MAX_SCALE:
-          return new DrillDecimalMaxScaleFuncHolder(functionAttributes, initializer);
-      case DECIMAL_MUL_SCALE:
-          return new DrillDecimalSumScaleFuncHolder(functionAttributes, initializer);
-      case DECIMAL_ADD_SCALE:
-          return new DrillDecimalAddFuncHolder(functionAttributes, initializer);
-      case DECIMAL_CAST:
-          return new DrillDecimalCastFuncHolder(functionAttributes, initializer);
-      case DECIMAL_DIV_SCALE:
-          return new DrillDecimalDivScaleFuncHolder(functionAttributes, initializer);
-      case DECIMAL_MOD_SCALE:
-          return new DrillDecimalModScaleFuncHolder(functionAttributes, initializer);
-      case DECIMAL_SET_SCALE:
-          return new DrillDecimalSetScaleFuncHolder(functionAttributes, initializer);
-      case DECIMAL_ZERO_SCALE:
-          return new DrillDecimalZeroScaleFuncHolder(functionAttributes, initializer);
-      case HOLISTIC_AGGREGATE:
-      case RANGE_AGGREGATE:
-      default:
-        return failure("Unsupported Function Type.", func);
+        case POINT_AGGREGATE:
+          return new DrillAggFuncHolder(functionAttributes, initializer);
+        case SIMPLE:
+          return outputField.isComplexWriter() ?
+              new DrillComplexWriterFuncHolder(functionAttributes, initializer) :
+              new DrillSimpleFuncHolder(functionAttributes, initializer);
+        case HOLISTIC_AGGREGATE:
+        case RANGE_AGGREGATE:
+        default:
+          return failure("Unsupported Function Type.", func);
       }
     } catch (Exception | NoSuchFieldError | AbstractMethodError ex) {
       return failure("Failure while creating function holder.", ex, func);


Mime
View raw message