DRILL-2406: part 1 - Remove interpreter generation, add new reflection based 
expression interpretation.

Changed interpreted evaluation to run the setup method after the input 
parameters have been set using reflection
so they are available in the case where the inputs are constant and are used in 
the setup method.

Changes that were originally committed in later patches for 2060 and 2173, as 
they are needed for this to run on its own:
    - Change to DrillSimpleFuncHolder that belongs with the interpreter 
refactoring.
    - ValueHolderHelper changes needed for interpreter refactoring.

Updates after review comments from Jinfeng:
Change the DrillSimpleFunc creation in the new interpreter to use a direct 
reference to the class type of the Function rather than the class name.

Add test case for 'like' function evaluated in the interpreter (has a 
meaningful setup method that uses one of the inputs to initialize a pattern 
matcher)

Update from Aman's review:
Add a test case for using a cast in interpreted expression evaluation.


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/0aa8b19d
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/0aa8b19d
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/0aa8b19d

Branch: refs/heads/master
Commit: 0aa8b19d624d173da51de36aa164f3435d3366a4
Parents: 1c5decc
Author: Jason Altekruse <[email protected]>
Authored: Tue Mar 3 15:58:04 2015 -0800
Committer: Jason Altekruse <[email protected]>
Committed: Tue Mar 17 12:20:54 2015 -0700

----------------------------------------------------------------------
 exec/interpreter/pom.xml                        | 109 --------
 .../exec/expr/ExpressionInterpreterTest.java    | 239 -----------------
 .../drill/exec/expr/DrillFuncHolderExpr.java    |   7 +-
 .../exec/expr/fn/DrillBooleanOPHolder.java      |   6 +-
 .../exec/expr/fn/DrillDecimalAddFuncHolder.java |   6 +-
 .../expr/fn/DrillDecimalCastFuncHolder.java     |   6 +-
 .../expr/fn/DrillDecimalDivScaleFuncHolder.java |   6 +-
 .../expr/fn/DrillDecimalMaxScaleFuncHolder.java |   7 +-
 .../expr/fn/DrillDecimalModScaleFuncHolder.java |   6 +-
 .../expr/fn/DrillDecimalSetScaleFuncHolder.java |   6 +-
 .../expr/fn/DrillDecimalSumScaleFuncHolder.java |   6 +-
 .../fn/DrillDecimalZeroScaleFuncHolder.java     |   6 +-
 .../exec/expr/fn/DrillSimpleFuncHolder.java     |  25 +-
 .../drill/exec/expr/fn/FunctionConverter.java   |  40 ++-
 .../fn/interpreter/DrillFuncInterpreter.java    |  26 --
 .../interpreter/DrillSimpleFuncInterpreter.java |  30 ---
 .../expr/fn/interpreter/InterpreterBuilder.java |  69 -----
 .../fn/interpreter/InterpreterEvaluator.java    | 180 ++++++++++---
 .../fn/interpreter/InterpreterGenerator.java    | 136 ----------
 .../drill/exec/vector/ValueHolderHelper.java    |  29 +++
 .../fn/interp/ExpressionInterpreterTest.java    | 260 +++++++++++++++++++
 .../resources/functions/interp/test_input.csv   |   3 +
 exec/pom.xml                                    |  11 -
 23 files changed, 515 insertions(+), 704 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/interpreter/pom.xml
----------------------------------------------------------------------
diff --git a/exec/interpreter/pom.xml b/exec/interpreter/pom.xml
deleted file mode 100644
index 20539a8..0000000
--- a/exec/interpreter/pom.xml
+++ /dev/null
@@ -1,109 +0,0 @@
-<?xml version="1.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. -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.apache.drill.exec</groupId>
-    <artifactId>exec-parent</artifactId>
-    <version>0.8.0-SNAPSHOT</version>
-  </parent>
-  <artifactId>drill-interpreter</artifactId>
-  <name>exec/Drill expression interpreter</name>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.drill</groupId>
-      <artifactId>drill-common</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.drill.exec</groupId>
-      <artifactId>drill-java-exec</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.drill</groupId>
-      <artifactId>drill-common</artifactId>
-      <classifier>tests</classifier>
-      <version>${project.version}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.drill.exec</groupId>
-      <artifactId>drill-java-exec</artifactId>
-      <version>${project.version}</version>
-      <classifier>tests</classifier>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.janino</groupId>
-      <artifactId>janino</artifactId>
-      <version>2.6.1</version>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>exec-maven-plugin</artifactId>
-        <dependencies>
-          <dependency>
-            <groupId>org.apache.drill.exec</groupId>
-            <artifactId>drill-java-exec</artifactId>
-            <version>${project.version}</version>
-          </dependency>
-        </dependencies>
-        <executions>
-          <execution>
-            <id>generate-sources</id>
-            <phase>generate-sources</phase>
-            <goals>
-              <goal>exec</goal>
-            </goals>
-            <configuration>
-              <executable>java</executable>
-              <arguments>
-                <argument>-Xmx1024m</argument>
-                <argument>-XX:MaxPermSize=256m</argument>
-                <argument>-classpath</argument>
-                <classpath/>
-                
<argument>org.apache.drill.exec.expr.fn.interpreter.InterpreterBuilder</argument>
-                
<argument>${project.build.directory}/generated-sources</argument>
-              </arguments>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>build-helper-maven-plugin</artifactId>
-        <version>1.9.1</version>
-        <executions>
-          <execution>
-            <id>add-generated-source</id>
-            <phase>generate-sources</phase>
-            <goals>
-              <goal>add-source</goal>
-            </goals>
-            <configuration>
-              <sources>
-                <source>${project.build.directory}/generated-sources</source>
-              </sources>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-</project>

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java
----------------------------------------------------------------------
diff --git 
a/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java
 
b/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java
deleted file mode 100644
index 9df7472..0000000
--- 
a/exec/interpreter/src/test/java/org/apache/drill/exec/expr/ExpressionInterpreterTest.java
+++ /dev/null
@@ -1,239 +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;
-
-
-import com.google.common.collect.Lists;
-import org.antlr.runtime.ANTLRStringStream;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.RecognitionException;
-import org.apache.drill.common.exceptions.DrillRuntimeException;
-import org.apache.drill.common.expression.ErrorCollector;
-import org.apache.drill.common.expression.ErrorCollectorImpl;
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.expression.parser.ExprLexer;
-import org.apache.drill.common.expression.parser.ExprParser;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.common.util.DrillStringUtils;
-import org.apache.drill.exec.expr.fn.interpreter.InterpreterEvaluator;
-import org.apache.drill.exec.expr.holders.TimeStampTZHolder;
-import org.apache.drill.exec.ops.FragmentContext;
-import org.apache.drill.exec.ops.QueryDateTimeInfo;
-import org.apache.drill.exec.pop.PopUnitTestBase;
-import org.apache.drill.exec.proto.BitControl;
-import org.apache.drill.exec.record.MaterializedField;
-import org.apache.drill.exec.record.RecordBatch;
-import org.apache.drill.exec.server.Drillbit;
-import org.apache.drill.exec.server.RemoteServiceSet;
-import org.apache.drill.exec.store.mock.MockGroupScanPOP;
-import org.apache.drill.exec.store.mock.MockScanBatchCreator;
-import org.apache.drill.exec.store.mock.MockSubScanPOP;
-import org.apache.drill.exec.vector.ValueVector;
-import org.joda.time.DateTime;
-import org.junit.Test;
-
-import java.nio.ByteBuffer;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
-public class ExpressionInterpreterTest  extends PopUnitTestBase {
-  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ExpressionInterpreterTest.class);
-
-  @Test
-  public void interpreterNullableStrExpr() throws Exception {
-    String[] colNames = {"col1"};
-    TypeProtos.MajorType[] colTypes = 
{Types.optional(TypeProtos.MinorType.VARCHAR)};
-    String expressionStr =  "substr(col1, 1, 3)";
-    String[] expectedFirstTwoValues = {"aaa", "null"};
-
-    doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues);
-  }
-
-
-  @Test
-  public void interpreterNullableBooleanExpr() throws Exception {
-    String[] colNames = {"col1"};
-    TypeProtos.MajorType[] colTypes = 
{Types.optional(TypeProtos.MinorType.VARCHAR)};
-    String expressionStr =  "col1 < 'abc' and col1 > 'abc'";
-    String[] expectedFirstTwoValues = {"false", "null"};
-
-    doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues);
-  }
-
-
-  @Test
-  public void interpreterNullableIntegerExpr() throws Exception {
-    String[] colNames = {"col1"};
-    TypeProtos.MajorType[] colTypes = 
{Types.optional(TypeProtos.MinorType.INT)};
-    String expressionStr = "col1 + 100 - 1 * 2 + 2";
-    String[] expectedFirstTwoValues = {"-2147483548", "null"};
-
-    doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues);
-  }
-
-  @Test
-  public void interpreterCaseExpr() throws Exception {
-    String[] colNames = {"col1"};
-    TypeProtos.MajorType[] colTypes = 
{Types.optional(TypeProtos.MinorType.VARCHAR)};
-    String expressionStr =  "case when substr(col1, 1, 3)='aaa' then 'ABC' 
else 'XYZ' end";
-    String[] expectedFirstTwoValues = {"ABC", "XYZ"};
-
-    doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues);
-  }
-
-  @Test
-  public void interpreterDateTest() throws Exception {
-    String[] colNames = {"col1"};
-    TypeProtos.MajorType[] colTypes = 
{Types.optional(TypeProtos.MinorType.INT)};
-    String expressionStr = "now()";
-    BitControl.PlanFragment planFragment = 
BitControl.PlanFragment.getDefaultInstance();
-    QueryDateTimeInfo dateTime = new 
QueryDateTimeInfo(planFragment.getQueryStartTime(), planFragment.getTimeZone());
-    int                        timeZoneIndex = 
dateTime.getRootFragmentTimeZone();
-    org.joda.time.DateTimeZone timeZone = 
org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
-    org.joda.time.DateTime     now = new 
org.joda.time.DateTime(dateTime.getQueryStartTime(), timeZone);
-
-    long queryStartDate = now.getMillis();
-    int timezoneIndex = 
org.apache.drill.exec.expr.fn.impl.DateUtility.getIndex(now.getZone().toString());
-
-    TimeStampTZHolder out = new TimeStampTZHolder();
-
-    out.value = queryStartDate;
-    out.index = timezoneIndex;
-
-    ByteBuffer buffer = ByteBuffer.allocate(12);
-    buffer.putLong(out.value);
-    buffer.putInt(out.index);
-    long l = buffer.getLong(0);
-    DateTime t = new DateTime(l);
-
-    String[] expectedFirstTwoValues = {t.toString(), t.toString()};
-
-    doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues, 
planFragment);
-  }
-
-
-  protected void doTest(String expressionStr, String[] colNames, 
TypeProtos.MajorType[] colTypes, String[] expectFirstTwoValues) throws 
Exception {
-    doTest(expressionStr, colNames, colTypes, expectFirstTwoValues, 
BitControl.PlanFragment.getDefaultInstance());
-  }
-
-  protected void doTest(String expressionStr, String[] colNames, 
TypeProtos.MajorType[] colTypes, String[] expectFirstTwoValues, 
BitControl.PlanFragment planFragment) throws Exception {
-    RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
-
-    Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
-
-    bit1.run();
-
-    // Create a mock scan batch as input for evaluation.
-    assert(colNames.length == colTypes.length);
-
-    MockGroupScanPOP.MockColumn[] columns = new 
MockGroupScanPOP.MockColumn[colNames.length];
-
-    for (int i = 0; i < colNames.length; i++ ) {
-      columns[i] = new MockGroupScanPOP.MockColumn(colNames[i], 
colTypes[i].getMinorType(), colTypes[i].getMode(),0,0,0);
-    }
-
-    MockGroupScanPOP.MockScanEntry entry = new 
MockGroupScanPOP.MockScanEntry(10, columns);
-    MockSubScanPOP scanPOP = new MockSubScanPOP("testTable", 
java.util.Collections.singletonList(entry));
-
-    RecordBatch batch = createMockScanBatch(bit1, scanPOP, planFragment);
-
-    batch.next();
-
-    ValueVector vv = evalExprWithInterpreter(expressionStr, batch, bit1);
-
-    // Verify the first 2 values in the output of evaluation.
-    assert(expectFirstTwoValues.length == 2);
-    assertEquals(expectFirstTwoValues[0], getValueFromVector(vv, 0));
-    assertEquals(expectFirstTwoValues[1], getValueFromVector(vv, 1));
-
-    showValueVectorContent(vv);
-
-    vv.clear();
-    batch.cleanup();
-    batch.getContext().close();
-    bit1.close();
-  }
-
-
-  private RecordBatch createMockScanBatch(Drillbit bit, MockSubScanPOP 
scanPOP, BitControl.PlanFragment planFragment) {
-    List<RecordBatch> children = Lists.newArrayList();
-    MockScanBatchCreator creator = new MockScanBatchCreator();
-
-    try {
-      FragmentContext context = new FragmentContext(bit.getContext(), 
planFragment, null, bit.getContext().getFunctionImplementationRegistry());
-      return creator.getBatch(context,scanPOP, children);
-    } catch (Exception ex) {
-      throw new DrillRuntimeException("Error when setup fragment context" + 
ex);
-    }
-  }
-
-  private LogicalExpression parseExpr(String expr) throws RecognitionException 
{
-    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
-    CommonTokenStream tokens = new CommonTokenStream(lexer);
-    ExprParser parser = new ExprParser(tokens);
-    ExprParser.parse_return ret = parser.parse();
-    return ret.e;
-  }
-
-  private ValueVector evalExprWithInterpreter(String expression, RecordBatch 
batch, Drillbit bit) throws Exception {
-    LogicalExpression expr = parseExpr(expression);
-    ErrorCollector error = new ErrorCollectorImpl();
-    LogicalExpression materializedExpr = 
ExpressionTreeMaterializer.materialize(expr, batch, error, 
bit.getContext().getFunctionImplementationRegistry());
-    if (error.getErrorCount() != 0) {
-      logger.error("Failure while materializing expression [{}].  Errors: {}", 
expression, error);
-      assertEquals(0, error.getErrorCount());
-    }
-
-    final MaterializedField outputField = MaterializedField.create("outCol", 
materializedExpr.getMajorType());
-
-    ValueVector vector = TypeHelper.getNewVector(outputField, 
bit.getContext().getAllocator());
-
-    vector.allocateNewSafe();
-
-    InterpreterEvaluator.evaluate(batch, vector, materializedExpr);
-
-    return vector;
-  }
-
-  private void showValueVectorContent(ValueVector vw) {
-    for (int row = 0; row < vw.getAccessor().getValueCount(); row ++ ) {
-      Object o = vw.getAccessor().getObject(row);
-      String cellString;
-      if (o instanceof byte[]) {
-        cellString = DrillStringUtils.toBinaryString((byte[]) o);
-      } else {
-        cellString = DrillStringUtils.escapeNewLines(String.valueOf(o));
-      }
-      System.out.printf(row + "th value: " + cellString + "\n");
-    }
-  }
-
-  private String getValueFromVector(ValueVector vw, int index) {
-    Object o = vw.getAccessor().getObject(index);
-    String cellString;
-    if (o instanceof byte[]) {
-      cellString = DrillStringUtils.toBinaryString((byte[]) o);
-    } else {
-      cellString = DrillStringUtils.escapeNewLines(String.valueOf(o));
-    }
-    return cellString;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFuncHolderExpr.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFuncHolderExpr.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFuncHolderExpr.java
index bc631b8..0dba609 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFuncHolderExpr.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFuncHolderExpr.java
@@ -27,12 +27,11 @@ import org.apache.drill.common.expression.fn.FuncHolder;
 import org.apache.drill.common.types.TypeProtos.MajorType;
 import org.apache.drill.exec.expr.fn.DrillComplexWriterFuncHolder;
 import org.apache.drill.exec.expr.fn.DrillFuncHolder;
-import org.apache.drill.exec.expr.fn.interpreter.DrillSimpleFuncInterpreter;
 
 public class DrillFuncHolderExpr extends FunctionHolderExpression implements 
Iterable<LogicalExpression>{
   static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillFuncHolderExpr.class);
   private DrillFuncHolder holder;
-  private DrillSimpleFuncInterpreter interpreter;
+  private DrillSimpleFunc interpreter;
 
   public DrillFuncHolderExpr(String nameUsed, DrillFuncHolder holder, 
List<LogicalExpression> args, ExpressionPosition pos) {
     super(nameUsed, pos, args);
@@ -94,11 +93,11 @@ public class DrillFuncHolderExpr extends 
FunctionHolderExpression implements Ite
     return new DrillFuncHolderExpr(this.nameUsed, this.holder, args, 
this.getPosition());
   }
 
-  public void setInterpreter(DrillSimpleFuncInterpreter interpreter) {
+  public void setInterpreter(DrillSimpleFunc interpreter) {
     this.interpreter = interpreter;
   }
 
-  public DrillSimpleFuncInterpreter getInterpreter() {
+  public DrillSimpleFunc getInterpreter() {
     return this.interpreter;
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index 743598a..d270888 100644
--- 
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
@@ -21,6 +21,7 @@ package org.apache.drill.exec.expr.fn;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.drill.exec.expr.DrillSimpleFunc;
 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;
@@ -29,8 +30,9 @@ public class DrillBooleanOPHolder extends 
DrillSimpleFuncHolder{
 
   public DrillBooleanOPHolder(FunctionScope scope, NullHandling nullHandling, 
boolean isBinaryCommutative, boolean isRandom,
       String[] registeredNames, ValueReference[] parameters, ValueReference 
returnValue, WorkspaceReference[] workspaceVars,
-      Map<String, String> methods, List<String> imports) {
-    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports);
+      Map<String, String> methods, List<String> imports, FunctionCostCategory 
costCategory, Class<? extends DrillSimpleFunc> drillFuncClass) {
+    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars,
+        methods, imports, costCategory, drillFuncClass);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index 3871cd7..aae7da8 100644
--- 
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
@@ -24,6 +24,8 @@ 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;
@@ -33,8 +35,8 @@ public class DrillDecimalAddFuncHolder extends 
DrillSimpleFuncHolder{
 
   public DrillDecimalAddFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
                                         String[] registeredNames, 
ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] 
workspaceVars,
-                                        Map<String, String> methods, 
List<String> imports) {
-    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports);
+                                        Map<String, String> methods, 
List<String> imports, FunctionTemplate.FunctionCostCategory costCategory, 
Class<? extends DrillSimpleFunc> drillFuncClass) {
+    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports, costCategory, 
drillFuncClass);
   }
 
   /*

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index db49173..73151c9 100644
--- 
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
@@ -25,6 +25,8 @@ 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.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;
 
@@ -33,8 +35,8 @@ public class DrillDecimalCastFuncHolder extends 
DrillSimpleFuncHolder {
 
     public DrillDecimalCastFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
                                           String[] registeredNames, 
ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] 
workspaceVars,
-                                          Map<String, String> methods, 
List<String> imports) {
-        super(scope, nullHandling, isBinaryCommutative, isRandom, 
registeredNames, parameters, returnValue, workspaceVars, methods, imports);
+                                          Map<String, String> methods, 
List<String> imports, FunctionTemplate.FunctionCostCategory costCategory, 
Class<? extends DrillSimpleFunc> drillFuncClass) {
+        super(scope, nullHandling, isBinaryCommutative, isRandom, 
registeredNames, parameters, returnValue, workspaceVars, methods, imports, 
costCategory, drillFuncClass);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index 683a04f..cee7312 100644
--- 
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
@@ -24,6 +24,8 @@ 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.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;
@@ -33,8 +35,8 @@ public class DrillDecimalDivScaleFuncHolder extends 
DrillSimpleFuncHolder{
 
   public DrillDecimalDivScaleFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
                                         String[] registeredNames, 
ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] 
workspaceVars,
-                                        Map<String, String> methods, 
List<String> imports) {
-    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports);
+                                        Map<String, String> methods, 
List<String> imports, FunctionTemplate.FunctionCostCategory costCategory, 
Class<? extends DrillSimpleFunc> drillFuncClass) {
+    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports, costCategory, 
drillFuncClass);
   }
 
   /*

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index aa8e2b5..2aff09f 100644
--- 
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
@@ -23,6 +23,8 @@ 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;
 
@@ -31,8 +33,9 @@ public class DrillDecimalMaxScaleFuncHolder extends 
DrillSimpleFuncHolder{
 
     public DrillDecimalMaxScaleFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
     String[] registeredNames, ValueReference[] parameters, ValueReference 
returnValue, WorkspaceReference[] workspaceVars,
-    Map<String, String> methods, List<String> imports) {
-        super(scope, nullHandling, isBinaryCommutative, isRandom, 
registeredNames, parameters, returnValue, workspaceVars, methods, imports);
+    Map<String, String> methods, List<String> imports, 
FunctionTemplate.FunctionCostCategory costCategory, Class<? extends 
DrillSimpleFunc> drillFuncClass) {
+        super(scope, nullHandling, isBinaryCommutative, isRandom, 
registeredNames, parameters, returnValue, workspaceVars,
+            methods, imports, costCategory, drillFuncClass);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index b5e754e..5faec84 100644
--- 
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
@@ -24,6 +24,8 @@ 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;
@@ -33,8 +35,8 @@ public class DrillDecimalModScaleFuncHolder extends 
DrillSimpleFuncHolder{
 
   public DrillDecimalModScaleFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
                                         String[] registeredNames, 
ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] 
workspaceVars,
-                                        Map<String, String> methods, 
List<String> imports) {
-    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports);
+                                        Map<String, String> methods, 
List<String> imports, FunctionTemplate.FunctionCostCategory costCategory, 
Class<? extends DrillSimpleFunc> drillFuncClass) {
+    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports, costCategory, 
drillFuncClass);
   }
 
   /*

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index 47b8507..8e6bdb5 100644
--- 
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
@@ -24,6 +24,8 @@ 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.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;
 
@@ -32,8 +34,8 @@ public class DrillDecimalSetScaleFuncHolder extends 
DrillSimpleFuncHolder{
 
   public DrillDecimalSetScaleFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
                                         String[] registeredNames, 
ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] 
workspaceVars,
-                                        Map<String, String> methods, 
List<String> imports) {
-    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports);
+                                        Map<String, String> methods, 
List<String> imports, FunctionTemplate.FunctionCostCategory costCategory, 
Class<? extends DrillSimpleFunc> drillFuncClass) {
+    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports, costCategory, 
drillFuncClass);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index cb8bfed..24b1eb0 100644
--- 
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
@@ -24,6 +24,8 @@ 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.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;
@@ -33,8 +35,8 @@ public class DrillDecimalSumScaleFuncHolder extends 
DrillSimpleFuncHolder{
 
     public DrillDecimalSumScaleFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
                                           String[] registeredNames, 
ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] 
workspaceVars,
-                                          Map<String, String> methods, 
List<String> imports) {
-        super(scope, nullHandling, isBinaryCommutative, isRandom, 
registeredNames, parameters, returnValue, workspaceVars, methods, imports);
+                                          Map<String, String> methods, 
List<String> imports, FunctionTemplate.FunctionCostCategory costCategory, 
Class<? extends DrillSimpleFunc> drillFuncClass) {
+        super(scope, nullHandling, isBinaryCommutative, isRandom, 
registeredNames, parameters, returnValue, workspaceVars, methods, imports, 
costCategory, drillFuncClass);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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
index 674fc87..6fb9ed6 100644
--- 
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
@@ -23,6 +23,8 @@ 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;
 
@@ -31,8 +33,8 @@ public class DrillDecimalZeroScaleFuncHolder extends 
DrillSimpleFuncHolder{
 
   public DrillDecimalZeroScaleFuncHolder(FunctionScope scope, NullHandling 
nullHandling, boolean isBinaryCommutative, boolean isRandom,
                                         String[] registeredNames, 
ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] 
workspaceVars,
-                                        Map<String, String> methods, 
List<String> imports) {
-    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports);
+                                        Map<String, String> methods, 
List<String> imports, FunctionTemplate.FunctionCostCategory costCategory, 
Class<? extends DrillSimpleFunc> drillFuncClass) {
+    super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports, costCategory, 
drillFuncClass);
   }
 
   /* This function scope is used when we need to remove the scale part.

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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 ec284a7..7e0f9c8 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
@@ -26,6 +26,7 @@ import org.apache.drill.common.types.TypeProtos.MajorType;
 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.DrillSimpleFunc;
 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;
@@ -37,8 +38,6 @@ import com.sun.codemodel.JExpr;
 import com.sun.codemodel.JExpression;
 import com.sun.codemodel.JMod;
 import com.sun.codemodel.JVar;
-import org.apache.drill.exec.expr.fn.interpreter.DrillSimpleFuncInterpreter;
-import org.apache.drill.exec.expr.fn.interpreter.InterpreterGenerator;
 
 public class DrillSimpleFuncHolder extends DrillFuncHolder{
   static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DrillSimpleFuncHolder.class);
@@ -47,7 +46,7 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder{
   private final String evalBody;
   private final String resetBody;
   private final String cleanupBody;
-  private final String interpreterClassName;
+  private final Class<? extends DrillSimpleFunc> drillFuncClass;
 
   public DrillSimpleFuncHolder(FunctionScope scope, NullHandling nullHandling, 
boolean isBinaryCommutative, boolean isRandom,
       String[] registeredNames, ValueReference[] parameters, ValueReference 
returnValue, WorkspaceReference[] workspaceVars,
@@ -57,7 +56,7 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder{
 
   public DrillSimpleFuncHolder(FunctionScope scope, NullHandling nullHandling, 
boolean isBinaryCommutative, boolean isRandom,
       String[] registeredNames, ValueReference[] parameters, ValueReference 
returnValue, WorkspaceReference[] workspaceVars,
-      Map<String, String> methods, List<String> imports, FunctionCostCategory 
costCategory, String interpreterClassName) {
+      Map<String, String> methods, List<String> imports, FunctionCostCategory 
costCategory, Class<? extends DrillSimpleFunc> drillFuncClass) {
     super(scope, nullHandling, isBinaryCommutative, isRandom, registeredNames, 
parameters, returnValue, workspaceVars, methods, imports, costCategory);
     setupBody = methods.get("setup");
     evalBody = methods.get("eval");
@@ -65,7 +64,7 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder{
     cleanupBody = methods.get("cleanup");
     Preconditions.checkNotNull(evalBody);
 
-    this.interpreterClassName = interpreterClassName;
+    this.drillFuncClass = drillFuncClass;
   }
 
   @Override
@@ -73,11 +72,9 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder{
     return false;
   }
 
-  public DrillSimpleFuncInterpreter createInterpreter() throws Exception {
-    Preconditions.checkArgument(this.interpreterClassName != null, 
"interpreterClassName should not be null!");
-
-    String className = InterpreterGenerator.PACKAGE_NAME + "." + 
this.interpreterClassName;
-    return (DrillSimpleFuncInterpreter) Class.forName(className).newInstance();
+  public DrillSimpleFunc createInterpreter() throws Exception {
+    Preconditions.checkArgument(this.drillFuncClass != null, "drillFuncClass 
should not be null!");
+    return drillFuncClass.newInstance();
   }
 
   public HoldingContainer renderEnd(ClassGenerator<?> g, HoldingContainer[] 
inputVariables, JVar[]  workspaceJVars){
@@ -150,12 +147,4 @@ public class DrillSimpleFuncHolder extends DrillFuncHolder{
 
     return out;
   }
-
-  public String getSetupBody() {
-    return setupBody;
-  }
-
-  public String getEvalBody() {
-    return evalBody;
-  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/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 60e7893..ab121b0 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
@@ -34,6 +34,7 @@ import javax.inject.Inject;
 import org.apache.drill.common.types.TypeProtos.MajorType;
 import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.exec.expr.DrillFunc;
+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.Output;
@@ -41,7 +42,6 @@ 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.fn.interpreter.InterpreterGenerator;
 import org.apache.drill.exec.expr.holders.ValueHolder;
 import org.apache.drill.exec.ops.QueryDateTimeInfo;
 import org.apache.drill.exec.ops.UdfUtilities;
@@ -99,6 +99,15 @@ public class FunctionConverter {
 
   }
 
+  /**
+   * Get the name of the class used for interpreted expression evaluation.
+   *
+   * @return - class name of interpreted evaluator
+   */
+  private String getInterpreterClassName(Class clazz)  {
+    return clazz.getName();
+  }
+
   public <T extends DrillFunc> DrillFuncHolder getHolder(Class<T> clazz) {
     FunctionTemplate template = clazz.getAnnotation(FunctionTemplate.class);
     if (template == null) {
@@ -264,38 +273,47 @@ public class FunctionConverter {
                                            template.isBinaryCommutative(),
                                            template.isRandom(), 
registeredNames,
                                            ps, outputField, works, methods, 
imports, template.costCategory(),
-                                           clazz.getSimpleName() + 
InterpreterGenerator.INTERPRETER_CLASSNAME_POSTFIX);
+                                           (Class<DrillSimpleFunc>)clazz
+                                           );
         }
       case SC_BOOLEAN_OPERATOR:
         return new DrillBooleanOPHolder(template.scope(), template.nulls(),
             template.isBinaryCommutative(),
             template.isRandom(), registeredNames,
-            ps, outputField, works, methods, imports);
+            ps, outputField, works, methods, imports, 
FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
 
       case DECIMAL_MAX_SCALE:
           return new DrillDecimalMaxScaleFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case DECIMAL_MUL_SCALE:
           return new DrillDecimalSumScaleFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case DECIMAL_ADD_SCALE:
           return new DrillDecimalAddFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case DECIMAL_CAST:
           return new DrillDecimalCastFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case DECIMAL_DIV_SCALE:
           return new DrillDecimalDivScaleFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case DECIMAL_MOD_SCALE:
           return new DrillDecimalModScaleFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case DECIMAL_SET_SCALE:
           return new DrillDecimalSetScaleFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case DECIMAL_ZERO_SCALE:
           return new DrillDecimalZeroScaleFuncHolder(template.scope(), 
template.nulls(), template.isBinaryCommutative(),
-                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports);
+                  template.isRandom(), registeredNames, ps, outputField, 
works, methods, imports,
+              FunctionTemplate.FunctionCostCategory.getDefault(), 
(Class<DrillSimpleFunc>)clazz);
       case HOLISTIC_AGGREGATE:
       case RANGE_AGGREGATE:
       default:

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillFuncInterpreter.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillFuncInterpreter.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillFuncInterpreter.java
deleted file mode 100644
index 3a83542..0000000
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillFuncInterpreter.java
+++ /dev/null
@@ -1,26 +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.interpreter;
-
-import org.apache.drill.exec.expr.holders.ValueHolder;
-import org.apache.drill.exec.record.RecordBatch;
-
-public interface DrillFuncInterpreter {
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillSimpleFuncInterpreter.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillSimpleFuncInterpreter.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillSimpleFuncInterpreter.java
deleted file mode 100644
index c6dd43b..0000000
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/DrillSimpleFuncInterpreter.java
+++ /dev/null
@@ -1,30 +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.interpreter;
-
-import org.apache.drill.exec.expr.holders.ValueHolder;
-import org.apache.drill.exec.record.RecordBatch;
-
-public interface DrillSimpleFuncInterpreter extends DrillFuncInterpreter {
-
-  public void doSetup(ValueHolder[] args);
-
-  public ValueHolder doEval(ValueHolder [] args) ;
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterBuilder.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterBuilder.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterBuilder.java
deleted file mode 100644
index 3dac818..0000000
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterBuilder.java
+++ /dev/null
@@ -1,69 +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.interpreter;
-
-import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.common.util.PathScanner;
-import org.apache.drill.exec.ExecConstants;
-import org.apache.drill.exec.expr.DrillFunc;
-import org.apache.drill.exec.expr.fn.DrillFuncHolder;
-import org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder;
-import org.apache.drill.exec.expr.fn.FunctionConverter;
-import org.apache.drill.exec.server.options.SystemOptionManager;
-
-import java.util.Set;
-
-public class InterpreterBuilder {
-  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(InterpreterBuilder.class);
-
-
-  public static void main(String args[])  {
-    InterpreterBuilder builder = new InterpreterBuilder();
-    if (args.length != 1) {
-      System.err.println("Usage: InterpreterBuilder  targetSrcDir\n");
-      System.exit(-1);
-    }
-    builder.build(DrillConfig.create(), args[0]);
-  }
-
-  private void build(DrillConfig config, String targetSrcDir) {
-    FunctionConverter converter = new FunctionConverter();
-    Set<Class<? extends DrillFunc>> providerClasses = 
PathScanner.scanForImplementations(DrillFunc.class, 
config.getStringList(ExecConstants.FUNCTION_PACKAGES));
-
-    int count = 0;
-    for (Class<? extends DrillFunc> clazz : providerClasses) {
-      try {
-        DrillFuncHolder holder = converter.getHolder(clazz);
-
-        if (holder != null && holder instanceof DrillSimpleFuncHolder) {
-          InterpreterGenerator generator = new 
InterpreterGenerator((DrillSimpleFuncHolder)holder, clazz.getSimpleName() + 
InterpreterGenerator.INTERPRETER_CLASSNAME_POSTFIX, targetSrcDir);
-          generator.build();
-          count ++;
-        }
-      } catch (Exception ex) {
-        failure("Failure while creating function interpreter.", ex, clazz);
-      }
-    }
-
-    logger.debug("Total interpreter class generated : " + count);
-  }
-
-  private void failure(String message, Throwable t, Class<?> clazz) {
-    logger.error("Failure loading function class [{}]. Message: {}", 
clazz.getName(), message, t);
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterEvaluator.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterEvaluator.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterEvaluator.java
index ab3ad8b..4f8e126 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterEvaluator.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterEvaluator.java
@@ -18,32 +18,38 @@
 package org.apache.drill.exec.expr.fn.interpreter;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
 import io.netty.buffer.DrillBuf;
 import org.apache.drill.common.exceptions.DrillRuntimeException;
 import org.apache.drill.common.expression.BooleanOperator;
+import org.apache.drill.common.expression.CastExpression;
+import org.apache.drill.common.expression.ConvertExpression;
+import org.apache.drill.common.expression.FunctionCall;
 import org.apache.drill.common.expression.FunctionHolderExpression;
 import org.apache.drill.common.expression.IfExpression;
 import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.NullExpression;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.expression.TypedNullConstant;
 import org.apache.drill.common.expression.ValueExpressions;
 import org.apache.drill.common.expression.visitors.AbstractExprVisitor;
 import org.apache.drill.common.types.TypeProtos;
 import org.apache.drill.exec.expr.DrillFuncHolderExpr;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
 import org.apache.drill.exec.expr.TypeHelper;
 import org.apache.drill.exec.expr.ValueVectorReadExpression;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
 import org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder;
 import org.apache.drill.exec.expr.holders.BitHolder;
 import org.apache.drill.exec.expr.holders.NullableBitHolder;
 import org.apache.drill.exec.expr.holders.ValueHolder;
-import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.OutOfMemoryException;
 import org.apache.drill.exec.ops.QueryDateTimeInfo;
 import org.apache.drill.exec.ops.UdfUtilities;
 import org.apache.drill.exec.record.RecordBatch;
+import org.apache.drill.exec.record.VectorAccessible;
 import org.apache.drill.exec.vector.ValueHolderHelper;
 import org.apache.drill.exec.vector.ValueVector;
-import org.reflections.Reflections;
 
 import javax.inject.Inject;
 import java.lang.reflect.Field;
@@ -52,8 +58,8 @@ import java.lang.reflect.Method;
 public class InterpreterEvaluator {
 
   public static ValueHolder evaluateConstantExpr(UdfUtilities udfUtilities, 
LogicalExpression expr) {
-    InterpreterInitVisitor initVisitor = new 
InterpreterInitVisitor(udfUtilities);
-    InterEvalVisitor evalVisitor = new InterEvalVisitor(null, udfUtilities);
+    InitVisitor initVisitor = new InitVisitor(udfUtilities);
+    EvalVisitor evalVisitor = new EvalVisitor(null, udfUtilities);
     expr.accept(initVisitor, null);
     return expr.accept(evalVisitor, -1);
   }
@@ -62,10 +68,10 @@ public class InterpreterEvaluator {
     evaluate(incoming.getRecordCount(), incoming.getContext(), incoming, 
outVV, expr);
   }
 
-  public static void evaluate(int recordCount, UdfUtilities udfUtilities, 
RecordBatch incoming, ValueVector outVV, LogicalExpression expr) {
+  public static void evaluate(int recordCount, UdfUtilities udfUtilities, 
VectorAccessible incoming, ValueVector outVV, LogicalExpression expr) {
 
-    InterpreterInitVisitor initVisitor = new 
InterpreterInitVisitor(udfUtilities);
-    InterEvalVisitor evalVisitor = new InterEvalVisitor(incoming, 
udfUtilities);
+    InitVisitor initVisitor = new InitVisitor(udfUtilities);
+    EvalVisitor evalVisitor = new EvalVisitor(incoming, udfUtilities);
 
     expr.accept(initVisitor, incoming);
 
@@ -75,18 +81,20 @@ public class InterpreterEvaluator {
     }
 
     outVV.getMutator().setValueCount(recordCount);
+
   }
 
-  public static class InterpreterInitVisitor extends 
AbstractExprVisitor<LogicalExpression, RecordBatch, RuntimeException> {
+  private static class InitVisitor extends 
AbstractExprVisitor<LogicalExpression, VectorAccessible, RuntimeException> {
 
     private UdfUtilities udfUtilities;
 
-    protected InterpreterInitVisitor(UdfUtilities udfUtilities) {
+    protected InitVisitor(UdfUtilities udfUtilities) {
       super();
       this.udfUtilities = udfUtilities;
     }
+
     @Override
-    public LogicalExpression 
visitFunctionHolderExpression(FunctionHolderExpression holderExpr, RecordBatch 
incoming) {
+    public LogicalExpression 
visitFunctionHolderExpression(FunctionHolderExpression holderExpr, 
VectorAccessible incoming) {
       if (! (holderExpr.getHolder() instanceof DrillSimpleFuncHolder)) {
         throw new UnsupportedOperationException("Only Drill simple UDF can be 
used in interpreter mode!");
       }
@@ -98,12 +106,10 @@ public class InterpreterEvaluator {
       }
 
       try {
-        DrillSimpleFuncInterpreter interpreter = holder.createInterpreter();
+        DrillSimpleFunc interpreter = holder.createInterpreter();
         Field[] fields = interpreter.getClass().getDeclaredFields();
         for (Field f : fields) {
-          // the current interpreter strips off annotations, so we just need 
to assume
-          // the type available as injectable are only used as injectable
-//          if ( f.getAnnotation(Inject.class) != null ) {
+          if ( f.getAnnotation(Inject.class) != null ) {
             f.setAccessible(true);
             Class fieldType = f.getType();
             if (UdfUtilities.INJECTABLE_GETTER_METHODS.get(fieldType) != null) 
{
@@ -113,21 +119,21 @@ public class InterpreterEvaluator {
               // Invalid injectable type provided, this should have been 
caught in FunctionConverter
               throw new DrillRuntimeException("Invalid injectable type 
requested in UDF: " + fieldType.getSimpleName());
             }
-//          } else { // do nothing with non-inject fields here
-//            continue;
-//          }
+          } else { // do nothing with non-inject fields here
+            continue;
+          }
         }
 
         ((DrillFuncHolderExpr) holderExpr).setInterpreter(interpreter);
         return holderExpr;
 
       } catch (Exception ex) {
-        throw new RuntimeException("Error in evaluating function of " + 
holderExpr.getName() + ": " + ex);
+        throw new RuntimeException("Error in evaluating function of " + 
holderExpr.getName() + ": ", ex);
       }
     }
 
     @Override
-    public LogicalExpression visitUnknown(LogicalExpression e, RecordBatch 
incoming) throws RuntimeException {
+    public LogicalExpression visitUnknown(LogicalExpression e, 
VectorAccessible incoming) throws RuntimeException {
       for (LogicalExpression child : e) {
         child.accept(this, incoming);
       }
@@ -137,24 +143,99 @@ public class InterpreterEvaluator {
   }
 
 
-  public static class InterEvalVisitor extends 
AbstractExprVisitor<ValueHolder, Integer, RuntimeException> {
-    private RecordBatch incoming;
+  public static class EvalVisitor extends AbstractExprVisitor<ValueHolder, 
Integer, RuntimeException> {
+    private VectorAccessible incoming;
     private UdfUtilities udfUtilities;
 
-    protected InterEvalVisitor(RecordBatch incoming, UdfUtilities 
udfUtilities) {
+    protected EvalVisitor(VectorAccessible incoming, UdfUtilities 
udfUtilities) {
       super();
       this.incoming = incoming;
       this.udfUtilities = udfUtilities;
     }
 
     public DrillBuf getManagedBufferIfAvailable() {
-      if (incoming != null) {
-        return incoming.getContext().getManagedBuffer();
-      } else {
-        return udfUtilities.getManagedBuffer();
-      }
+      return udfUtilities.getManagedBuffer();
+    }
+
+    @Override
+    public ValueHolder visitFunctionCall(FunctionCall call, Integer value) 
throws RuntimeException {
+      return visitUnknown(call, value);
+    }
+
+    @Override
+    public ValueHolder visitSchemaPath(SchemaPath path,Integer value) throws 
RuntimeException {
+      return visitUnknown(path, value);
+    }
+
+    @Override
+    public ValueHolder 
visitDecimal9Constant(ValueExpressions.Decimal9Expression decExpr,Integer 
value) throws RuntimeException {
+      return ValueHolderHelper.getDecimal9Holder(decExpr.getIntFromDecimal(), 
decExpr.getScale(), decExpr.getPrecision());
     }
 
+    @Override
+    public ValueHolder 
visitDecimal18Constant(ValueExpressions.Decimal18Expression decExpr,Integer 
value) throws RuntimeException {
+      return 
ValueHolderHelper.getDecimal18Holder(decExpr.getLongFromDecimal(), 
decExpr.getScale(), decExpr.getPrecision());
+    }
+
+    @Override
+    public ValueHolder 
visitDecimal28Constant(ValueExpressions.Decimal28Expression decExpr,Integer 
value) throws RuntimeException {
+      return 
ValueHolderHelper.getDecimal28Holder(getManagedBufferIfAvailable(), 
decExpr.getBigDecimal().toString());
+    }
+
+    @Override
+    public ValueHolder 
visitDecimal38Constant(ValueExpressions.Decimal38Expression decExpr,Integer 
value) throws RuntimeException {
+      return 
ValueHolderHelper.getDecimal28Holder(getManagedBufferIfAvailable(), 
decExpr.getBigDecimal().toString());
+    }
+
+    @Override
+    public ValueHolder visitDateConstant(ValueExpressions.DateExpression 
dateExpr,Integer value) throws RuntimeException {
+      return ValueHolderHelper.getDateHolder(dateExpr.getDate());
+    }
+
+    @Override
+    public ValueHolder visitTimeConstant(ValueExpressions.TimeExpression 
timeExpr,Integer value) throws RuntimeException {
+      return ValueHolderHelper.getTimeHolder(timeExpr.getTime());
+    }
+
+    @Override
+    public ValueHolder 
visitTimeStampConstant(ValueExpressions.TimeStampExpression 
timestampExpr,Integer value) throws RuntimeException {
+      return 
ValueHolderHelper.getTimeStampHolder(timestampExpr.getTimeStamp());
+    }
+
+    @Override
+    public ValueHolder 
visitIntervalYearConstant(ValueExpressions.IntervalYearExpression 
intExpr,Integer value) throws RuntimeException {
+      return 
ValueHolderHelper.getIntervalYearHolder(intExpr.getIntervalYear());
+    }
+
+    @Override
+    public ValueHolder 
visitIntervalDayConstant(ValueExpressions.IntervalDayExpression intExpr,Integer 
value) throws RuntimeException {
+      return ValueHolderHelper.getIntervalDayHolder(intExpr.getIntervalDay(), 
intExpr.getIntervalMillis());
+    }
+
+    @Override
+    public ValueHolder visitBooleanConstant(ValueExpressions.BooleanExpression 
e,Integer value) throws RuntimeException {
+      return ValueHolderHelper.getBitHolder(e.getBoolean() == false ? 0 : 1);
+    }
+
+    @Override
+    public ValueHolder visitNullConstant(TypedNullConstant e,Integer value) 
throws RuntimeException {
+      // create a value holder for the given type, defaults to NULL value if 
not set
+      return TypeHelper.createValueHolder(e.getMajorType());
+    }
+
+    // TODO - review what to do with these
+    // **********************************
+    @Override
+    public ValueHolder visitConvertExpression(ConvertExpression e,Integer 
value) throws RuntimeException {
+      return visitUnknown(e, value);
+    }
+
+    @Override
+    public ValueHolder visitNullExpression(NullExpression e,Integer value) 
throws RuntimeException {
+      return visitUnknown(e, value);
+    }
+    // TODO - review what to do with these (2 functions above)
+    //********************************************
 
     @Override
     public ValueHolder visitFunctionHolderExpression(FunctionHolderExpression 
holderExpr, Integer inIndex) {
@@ -186,12 +267,46 @@ public class InterpreterEvaluator {
       }
 
       try {
-        DrillSimpleFuncInterpreter interpreter =  ((DrillFuncHolderExpr) 
holderExpr).getInterpreter();
+        DrillSimpleFunc interpreter =  ((DrillFuncHolderExpr) 
holderExpr).getInterpreter();
 
         Preconditions.checkArgument(interpreter != null, "interpreter could 
not be null when use interpreted model to evaluate function " + 
holder.getRegisteredNames()[0]);
 
-        interpreter.doSetup(args);
-        ValueHolder out = interpreter.doEval(args);
+        // the current input index to assign into the next available 
parameter, found using the @Param notation
+        // the order parameters are declared in the java class for the 
DrillFunc is meaningful
+        int currParameterIndex = 0;
+        Field outField = null;
+        try {
+          Field[] fields = interpreter.getClass().getDeclaredFields();
+          for (Field f : fields) {
+            // if this is annotated as a parameter to the function
+            if ( f.getAnnotation(Param.class) != null ) {
+              f.setAccessible(true);
+              if (currParameterIndex < args.length) {
+                f.set(interpreter, args[currParameterIndex]);
+              }
+              currParameterIndex++;
+            } else if ( f.getAnnotation(Output.class) != null ) {
+              f.setAccessible(true);
+              outField = f;
+              // create an instance of the holder for the output to be stored 
in
+              f.set(interpreter, f.getType().newInstance());
+            }
+          }
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+        if (args.length != currParameterIndex ) {
+          throw new DrillRuntimeException(
+              String.format("Wrong number of parameters provided to 
interpreted expression evaluation " +
+                  "for function %s, expected %d parameters, but received %d.",
+                  holderExpr.getName(), currParameterIndex, args.length));
+        }
+        if (outField == null) {
+          throw new DrillRuntimeException("Malformed DrillFunction without a 
return type: " + holderExpr.getName());
+        }
+        interpreter.setup();
+        interpreter.eval();
+        ValueHolder out = (ValueHolder) outField.get(interpreter);
 
         if (TypeHelper.getValueHolderType(out).getMode() == 
TypeProtos.DataMode.OPTIONAL &&
             holderExpr.getMajorType().getMode() == 
TypeProtos.DataMode.REQUIRED) {
@@ -343,7 +458,6 @@ public class InterpreterEvaluator {
     private ValueHolder visitBooleanOr(BooleanOperator op, Integer inIndex) {
       ValueHolder [] args = new ValueHolder [op.args.size()];
       boolean hasNull = false;
-      ValueHolder out = null;
       for (int i = 0; i < op.args.size(); i++) {
         args[i] = op.args.get(i).accept(this, inIndex);
 

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterGenerator.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterGenerator.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterGenerator.java
deleted file mode 100644
index 25b5ff2..0000000
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/interpreter/InterpreterGenerator.java
+++ /dev/null
@@ -1,136 +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.interpreter;
-
-import com.google.common.collect.Maps;
-import com.sun.codemodel.JBlock;
-import com.sun.codemodel.JClass;
-import com.sun.codemodel.JCodeModel;
-import com.sun.codemodel.JDefinedClass;
-import com.sun.codemodel.JExpr;
-import com.sun.codemodel.JFieldVar;
-import com.sun.codemodel.JMethod;
-import com.sun.codemodel.JMod;
-import com.sun.codemodel.JType;
-import com.sun.codemodel.JVar;
-import org.apache.drill.exec.expr.TypeHelper;
-import org.apache.drill.exec.expr.fn.DrillFuncHolder;
-import org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder;
-import org.apache.drill.exec.expr.holders.ValueHolder;
-import org.apache.drill.exec.record.RecordBatch;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
-
-public class InterpreterGenerator {
-  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(InterpreterGenerator.class);
-
-  public static final String PACKAGE_NAME = 
"org.apache.drill.exec.fn.interpreter.generated";
-  private static final String ARG_NAME = "args";
-  private static final String SETUP_METHOD = "doSetup";
-  private static final String EVAL_METHOD = "doEval";
-  public static final String INTERPRETER_CLASSNAME_POSTFIX = "Interpreter";
-
-  private JCodeModel model ;
-  private DrillSimpleFuncHolder holder;
-  private JDefinedClass clazz;
-  private String className;
-  private String genSourceDir;
-
-  public InterpreterGenerator (DrillSimpleFuncHolder holder, String className, 
String genSourceDir) {
-    this.model = new JCodeModel();
-    this.holder = holder;
-    this.className = className;
-    this.genSourceDir = genSourceDir;
-  }
-
-  public void build() throws Exception {
-    try {
-      this.clazz = model._class(PACKAGE_NAME + "." + className);
-      JClass iface = model.ref(DrillSimpleFuncInterpreter.class);
-      clazz._implements(iface);
-
-      Map<DrillFuncHolder.WorkspaceReference, JFieldVar> wsFieldVars = 
Maps.newHashMap();
-      for (DrillFuncHolder.WorkspaceReference ws : holder.getWorkspaceVars()) {
-        JFieldVar wsVar = clazz.field(JMod.PRIVATE, ws.getType(), 
ws.getName());
-        wsFieldVars.put(ws, wsVar);
-      }
-
-      generateSetup(wsFieldVars);
-
-      generateEval();
-
-      // generate the java source code for the function.
-      File file = new File(genSourceDir);
-      if (!file.exists()) {
-        file.mkdir();
-      }
-
-      model.build(file);
-
-    } catch (Exception e) {
-      logger.error("Error when generate code for " + className + " error " + 
e);
-      throw new IllegalStateException(e);
-    }
-  }
-
-  private void generateSetup(Map<DrillFuncHolder.WorkspaceReference, 
JFieldVar> wsFieldVars) {
-    JClass valueholderClass = model.ref(ValueHolder.class);
-
-    JMethod doSetupMethod = clazz.method(JMod.PUBLIC, Void.TYPE, SETUP_METHOD);
-    doSetupMethod.param(valueholderClass.array(), ARG_NAME);
-
-    if (holder.getSetupBody()!=null && ! 
holder.getSetupBody().trim().equals("{}")) {
-      declareAssignParm(model, doSetupMethod.body(), holder, ARG_NAME, true);
-    }
-
-    doSetupMethod.body().directStatement(holder.getSetupBody());
-  }
-
-  private void generateEval() {
-    JClass valueholderClass = model.ref(ValueHolder.class);
-
-    JMethod doEvalMethod = clazz.method(JMod.PUBLIC, ValueHolder.class, 
EVAL_METHOD);
-    doEvalMethod.param(valueholderClass.array(), ARG_NAME);
-
-    if (holder.getEvalBody()!=null && ! 
holder.getEvalBody().trim().equals("")) {
-      declareAssignParm(model, doEvalMethod.body(), holder, ARG_NAME, false);
-    }
-
-    DrillFuncHolder.ValueReference returnValue = holder.getReturnValue();
-    JType outType = TypeHelper.getHolderType(model, 
returnValue.getType().getMinorType(), returnValue.getType().getMode());
-
-    JVar outVar = doEvalMethod.body().decl(outType, returnValue.getName(), 
JExpr._new(outType));
-
-    doEvalMethod.body().directStatement(holder.getEvalBody());
-    doEvalMethod.body()._return(outVar);
-  }
-
-  private void declareAssignParm(JCodeModel model, JBlock block, 
DrillFuncHolder holder, String argName, boolean constantOnly) {
-
-    int index = 0;
-    DrillFuncHolder.ValueReference[] parameters = holder.getParameters();
-
-    for (DrillFuncHolder.ValueReference parm : parameters) {
-      JType type = TypeHelper.getHolderType(model, 
parm.getType().getMinorType(), parm.getType().getMode());
-      block.decl(type, parm.getName(), JExpr.cast(type, 
JExpr.component(JExpr.ref(argName), JExpr.lit(index++))));
-    }
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/drill/blob/0aa8b19d/exec/java-exec/src/main/java/org/apache/drill/exec/vector/ValueHolderHelper.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/ValueHolderHelper.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/ValueHolderHelper.java
index 2f5bf6a..42384cb 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/ValueHolderHelper.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/ValueHolderHelper.java
@@ -23,6 +23,7 @@ import java.math.BigDecimal;
 
 import org.apache.drill.exec.expr.holders.BigIntHolder;
 import org.apache.drill.exec.expr.holders.BitHolder;
+import org.apache.drill.exec.expr.holders.DateHolder;
 import org.apache.drill.exec.expr.holders.Decimal18Holder;
 import org.apache.drill.exec.expr.holders.Decimal28SparseHolder;
 import org.apache.drill.exec.expr.holders.Decimal38SparseHolder;
@@ -31,7 +32,10 @@ import org.apache.drill.exec.expr.holders.Float4Holder;
 import org.apache.drill.exec.expr.holders.Float8Holder;
 import org.apache.drill.exec.expr.holders.IntHolder;
 import org.apache.drill.exec.expr.holders.IntervalDayHolder;
+import org.apache.drill.exec.expr.holders.IntervalYearHolder;
 import org.apache.drill.exec.expr.holders.NullableBitHolder;
+import org.apache.drill.exec.expr.holders.TimeHolder;
+import org.apache.drill.exec.expr.holders.TimeStampHolder;
 import org.apache.drill.exec.expr.holders.VarCharHolder;
 import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.util.DecimalUtility;
@@ -70,6 +74,23 @@ public class ValueHolderHelper {
     return holder;
   }
 
+  public static DateHolder getDateHolder(long value) {
+    DateHolder holder = new DateHolder();
+    holder.value = value;
+    return holder;
+  }
+
+  public static TimeHolder getTimeHolder(int value) {
+    TimeHolder holder = new TimeHolder();
+    holder.value = value;
+    return holder;
+  }
+
+  public static TimeStampHolder getTimeStampHolder(long value) {
+    TimeStampHolder holder = new TimeStampHolder();
+    holder.value = value;
+    return holder;
+  }
 
   public static BitHolder getBitHolder(int value) {
     BitHolder holder = new BitHolder();
@@ -110,6 +131,14 @@ public class ValueHolderHelper {
     return vch;
   }
 
+
+  public static IntervalYearHolder getIntervalYearHolder(int intervalYear) {
+    IntervalYearHolder holder = new IntervalYearHolder();
+
+    holder.value = intervalYear;
+    return holder;
+  }
+
   public static IntervalDayHolder getIntervalDayHolder(int days, int millis) {
       IntervalDayHolder dch = new IntervalDayHolder();
 

Reply via email to