You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2013/07/20 03:58:04 UTC

[43/53] [abbrv] Types transition

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/SchemaPath.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/SchemaPath.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/SchemaPath.java
index dfae6fd..19d1069 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/SchemaPath.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/SchemaPath.java
@@ -17,133 +17,123 @@
  ******************************************************************************/
 package org.apache.drill.common.expression;
 
+import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.drill.common.expression.ValueExpressions.CollisionBehavior;
-import org.apache.drill.common.expression.types.DataType;
 import org.apache.drill.common.expression.visitors.ExprVisitor;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.Types;
 
-public class SchemaPath extends LogicalExpressionBase{
+import com.google.protobuf.DescriptorProtos.UninterpretedOption.NamePart;
+
+public class SchemaPath extends LogicalExpressionBase {
 
   // reads well in RegexBuddy
-  private static final String ENTIRE_REGEX = "^\n" +
-      "(?:                # first match required\n" +
-      "\\[\\d+\\]             # array index only\n" +
-      "|\n" +
-      "'?\n" +
-      "[^\\.\\[\\+\\-\\!\\]\\}]+  # identifier\n" +
-      "'?\n" +
-      "(?:\\[\\d+\\])?\n" +
-      ")\n" +
-      "[\\+\\-\\!\\]\\}]?\n" +
-
-      "# secondary matches (starts with dot)\n" +
-      "(?:\n" +
-      "\\.\n" +
-      "(?:                # first match required\n" +
-      "\\[\\d+\\]             # array index only\n" +
-      "|\n" +
-      "'?\n" +
-      "[^\\.\\[\\+\\-\\!\\]\\}]+  # identifier\n" +
-      "'?\n" +
-      "(?:\\[\\d+\\])?\n" +
-      ")\n" +
-      "[\\+\\-\\!\\]\\}]?\n" +
+  private static final String ENTIRE_REGEX = "^\n" + "(?:                # first match required\n"
+      + "\\[\\d+\\]             # array index only\n" + "|\n" + "'?\n" + "[^\\.\\[\\+\\-\\!\\]\\}]+  # identifier\n"
+      + "'?\n" + "(?:\\[\\d+\\])?\n" + ")\n" + "[\\+\\-\\!\\]\\}]?\n" +
+
+      "# secondary matches (starts with dot)\n" + "(?:\n" + "\\.\n" + "(?:                # first match required\n"
+      + "\\[\\d+\\]             # array index only\n" + "|\n" + "'?\n" + "[^\\.\\[\\+\\-\\!\\]\\}]+  # identifier\n"
+      + "'?\n" + "(?:\\[\\d+\\])?\n" + ")\n" + "[\\+\\-\\!\\]\\}]?\n" +
 
       ")*$";
-  
+
   // reads well in RegexBuddy
-  private static final String SEGMENT_REGEX = "(?:\n" +
-      "(\\[\\d+\\])\n" +
-      "|\n" +
-      "'?\n" +
-      "([^\\.\\[\\+\\-\\!\\]\\}]+)  # identifier\n" +
-      "'?\n" +
-      ")\n" +
-      "([\\+\\-\\!\\]\\}]?)         # collision type";
+  private static final String SEGMENT_REGEX = "(?:\n" + "(\\[\\d+\\])\n" + "|\n" + "'?\n"
+      + "([^\\.\\[\\+\\-\\!\\]\\}]+)  # identifier\n" + "'?\n" + ")\n"
+      + "([\\+\\-\\!\\]\\}]?)         # collision type";
   private static final int GROUP_INDEX = 1;
   private static final int GROUP_PATH_SEGMENT = 2;
   private static final int GROUP_COLLISION = 3;
-  
-  
+
   private final static Pattern SEGMENT_PATTERN = Pattern.compile(SEGMENT_REGEX, Pattern.COMMENTS);
   private final static Pattern ENTIRE_PATTERN = Pattern.compile(ENTIRE_REGEX, Pattern.COMMENTS);
-  
+
   private final CharSequence originalPath;
   private final PathSegment rootSegment;
-  
-  
-  
-	public SchemaPath(CharSequence str) {
-	  if(!ENTIRE_PATTERN.matcher(str).matches()) throw new IllegalArgumentException("Identifier doesn't match expected pattern.");
-	  this.originalPath = str;
-	  Matcher m = SEGMENT_PATTERN.matcher(str);
-		PathSegment r = null;
-		PathSegment previous = null;
-		PathSegment current;
-		while(m.find()){
-		  CollisionBehavior col =  (m.start(GROUP_COLLISION) != -1) ? CollisionBehavior.find(m.group(GROUP_COLLISION)) : CollisionBehavior.DEFAULT;
-
-      if(m.start(GROUP_INDEX) != -1){
+
+  public SchemaPath(CharSequence str, ExpressionPosition pos) {
+    super(pos);
+
+    if (!ENTIRE_PATTERN.matcher(str).matches())
+      throw new IllegalArgumentException("Identifier doesn't match expected pattern.");
+    this.originalPath = str;
+    Matcher m = SEGMENT_PATTERN.matcher(str);
+    PathSegment r = null;
+    PathSegment previous = null;
+    PathSegment current;
+    while (m.find()) {
+      CollisionBehavior col = (m.start(GROUP_COLLISION) != -1) ? CollisionBehavior.find(m.group(GROUP_COLLISION))
+          : CollisionBehavior.DEFAULT;
+
+      if (m.start(GROUP_INDEX) != -1) {
         String d = m.group(GROUP_INDEX);
         current = new PathSegment.ArraySegment(Integer.parseInt(d), col);
-      }else{
+      } else {
         String i = m.group(GROUP_PATH_SEGMENT);
         current = new PathSegment.NameSegment(i, col);
       }
-		  if(previous == null){
-		    r = current;
-		  }else{
-		    previous.setChild(current);
-		  }
-		  previous = current;
-		}
-		
-		rootSegment = r;
-		
-
-	}
-		
-
-	
-	@Override
-  public <T> T accept(ExprVisitor<T> visitor) {
-    return visitor.visitSchemaPath(this);
+      if (previous == null) {
+        r = current;
+      } else {
+        previous.setChild(current);
+      }
+      previous = current;
+    }
+
+    rootSegment = r;
+
   }
 
+  @Override
+  public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E> visitor, V value) throws E {
+    return visitor.visitSchemaPath(this, value);
+  }
 
-  public PathSegment getRootSegment(){
-	  return rootSegment;
-	}
-	
-	public CharSequence getPath(){
-	  return originalPath;
-	}
+  public PathSegment getRootSegment() {
+    return rootSegment;
+  }
 
-    @Override
-    public DataType getDataType() {
-        return DataType.LATEBIND;
-    }
+  public CharSequence getPath() {
+    return originalPath;
+  }
 
-    @Override
-  public void addToString(StringBuilder sb) {
-    sb.append("'");
-    sb.append(originalPath);
-    sb.append("'");
+  @Override
+  public MajorType getMajorType() {
+    return Types.LATE_BIND_TYPE;
   }
 
-    @Override
-    public void resolveAndValidate(String expr, ErrorCollector errors) {
-    }
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((rootSegment == null) ? 0 : rootSegment.hashCode());
+    return result;
+  }
 
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    SchemaPath other = (SchemaPath) obj;
+    if (rootSegment == null) {
+      if (other.rootSegment != null)
+        return false;
+    } else if (!rootSegment.equals(other.rootSegment))
+      return false;
+    return true;
+  }
 
-    @Override
+  @Override
   public String toString() {
     return "SchemaPath [rootSegment=" + rootSegment + "]";
   }
-  
-  
-  
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
index f07f2a7..1acffcb 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
@@ -17,197 +17,181 @@
  ******************************************************************************/
 package org.apache.drill.common.expression;
 
-import org.apache.drill.common.expression.types.DataType;
 import org.apache.drill.common.expression.visitors.ExprVisitor;
-
-
-
-
+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;
 
 public class ValueExpressions {
 
-  public static LogicalExpression getNumericExpression(String s){
-    try{
+  public static LogicalExpression getNumericExpression(String s, ExpressionPosition ep) {
+    try {
       long l = Long.parseLong(s);
-      return new LongExpression(l);
-    }catch(Exception e){
-      
+      return new LongExpression(l, ep);
+    } catch (Exception e) {
+
     }
-    
-    try{
+
+    try {
       double d = Double.parseDouble(s);
-      return new DoubleExpression(d);
-    }catch(Exception e){
-      
+      return new DoubleExpression(d, ep);
+    } catch (Exception e) {
+
     }
+
+    throw new IllegalArgumentException(String.format("Unable to parse string %s as integer or floating point number.",
+        s));
+
+  }
+
+  protected static abstract class ValueExpression<V> extends LogicalExpressionBase {
+    public final V value;
+
+    protected ValueExpression(String value, ExpressionPosition pos) {
+      super(pos);
+      this.value = parseValue(value);
+    }
+
+    protected abstract V parseValue(String s);
+
+  }
+
+  public static class BooleanExpression extends ValueExpression<Boolean> {
     
-    throw new IllegalArgumentException(String.format("Unable to parse string %s as integer or floating point number.", s));
     
+    public BooleanExpression(String value, ExpressionPosition pos) {
+      super(value, pos);
+    }
+
+    @Override
+    protected Boolean parseValue(String s) {
+      return Boolean.parseBoolean(s);
+    }
+
+    @Override
+    public MajorType getMajorType() {
+      return Types.REQUIRED_BOOLEAN;
+    }
+
+    @Override
+    public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E> visitor, V value) throws E {
+      return visitor.visitBooleanConstant(this, value);
+    }
+
+    public boolean getBoolean() {
+      return value;
+    }
+
   }
-  
-	protected static abstract class ValueExpression<V> extends LogicalExpressionBase {
-		public final V value;
 
-		protected ValueExpression(String value) {
-			this.value = parseValue(value);
-		}
+  public static class DoubleExpression extends LogicalExpressionBase {
+    private double d;
 
-		protected abstract V parseValue(String s);
+    private static final MajorType DOUBLE_CONSTANT = MajorType.newBuilder().setMinorType(MinorType.FLOAT8)
+        .setMode(DataMode.REQUIRED).build();
 
+    public DoubleExpression(double d, ExpressionPosition pos) {
+      super(pos);
+      this.d = d;
+    }
 
-	}
+    public double getDouble() {
+      return d;
+    }
+
+    @Override
+    public MajorType getMajorType() {
+      return DOUBLE_CONSTANT;
+    }
+
+    @Override
+    public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E> visitor, V value) throws E {
+      return visitor.visitDoubleConstant(this, value);
+    }
+
+  }
 
-	public static class BooleanExpression extends ValueExpression<Boolean> {
-		public BooleanExpression(String value) {
-			super(value);
-		}
+  public static class LongExpression extends LogicalExpressionBase {
 
-		@Override
-		protected Boolean parseValue(String s) {
-			return Boolean.parseBoolean(s);
-		}
+    private static final MajorType LONG_CONSTANT = MajorType.newBuilder().setMinorType(MinorType.BIGINT)
+        .setMode(DataMode.REQUIRED).build();
 
-        @Override
-        public DataType getDataType() {
-            return DataType.BOOLEAN;
-        }
+    private long l;
 
-        @Override
-    public void addToString(StringBuilder sb) {
-      sb.append(value.toString());
+    public LongExpression(long l, ExpressionPosition pos) {
+      super(pos);
+      this.l = l;
     }
 
-        @Override
-        public void resolveAndValidate(String expr, ErrorCollector errors) {
-        }
+    public long getLong() {
+      return l;
+    }
 
+    @Override
+    public MajorType getMajorType() {
+      return LONG_CONSTANT;
+    }
 
-        @Override
-    public <T> T accept(ExprVisitor<T> visitor) {
-      return visitor.visitBoolean(this);
+    @Override
+    public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E> visitor, V value) throws E {
+      return visitor.visitLongConstant(this, value);
     }
-    
-    public boolean getBoolean(){
-      return value;
+  }
+
+  public static class QuotedString extends ValueExpression<String> {
+
+    private static final MajorType QUOTED_STRING_CONSTANT = MajorType.newBuilder().setMinorType(MinorType.VARCHAR2)
+        .setMode(DataMode.REQUIRED).build();
+
+    public QuotedString(String value, ExpressionPosition pos) {
+      super(value, pos);
     }
-		
-	}
-
-	 public static class DoubleExpression extends LogicalExpressionBase  {
-	   private double d;
-	    public DoubleExpression(double d) {
-	      this.d = d;
-	    }
-
-	    public double getDouble(){
-	      return d;
-	    }
-
-         @Override
-         public DataType getDataType() {
-             return DataType.FLOAT32;
-         }
-
-         @Override
-	    public void addToString(StringBuilder sb) {
-	      sb.append(d);
-	    }
-
-         @Override
-         public void resolveAndValidate(String expr, ErrorCollector errors) {
-         }
-
-         @Override
-	    public <T> T accept(ExprVisitor<T> visitor) {
-	      return visitor.visitDoubleExpression(this);
-	    }
-	  }
-	 
-	public static class LongExpression extends LogicalExpressionBase {
-	  private long l;
-		public LongExpression(long l) {
-		  this.l = l;
-		}
-		
-		public long getLong(){
-		  return l;
-		}
-
-        @Override
-        public DataType getDataType() {
-            return DataType.INT64;
-        }
-
-        @Override
-    public void addToString(StringBuilder sb) {
-      sb.append(l);
-    }
-
-        @Override
-        public void resolveAndValidate(String expr, ErrorCollector errors) {
-        }
-
-        @Override
-    public <T> T accept(ExprVisitor<T> visitor) {
-      return visitor.visitLongExpression(this);
-    }
-	}
-
-	public static class QuotedString extends ValueExpression<String> {
-		public QuotedString(String value) {
-			super(value);
-		}
-
-		@Override
-		protected String parseValue(String s) {
-			return s;
-		}
-
-        @Override
-        public DataType getDataType() {
-            return DataType.NVARCHAR;
-        }
-
-        @Override
-    public void addToString(StringBuilder sb) {
-      sb.append("\"");
-      sb.append(value.toString());
-      sb.append("\"");
-    }
-
-        @Override
-        public void resolveAndValidate(String expr, ErrorCollector errors) {
-        }
-
-        @Override
-    public <T> T accept(ExprVisitor<T> visitor) {
-      return visitor.visitQuotedString(this);
-    }
-	}
-
-	
-	public static enum CollisionBehavior{
-	  SKIP("-"),  // keep the old value.
-	  FAIL("!"), // give up on the record
-	  REPLACE("+"), // replace the old value with the new value.
-	  ARRAYIFY("]"), // replace the current position with an array.  Then place the old and new value in the array. 
-	  OBJECTIFY("}"),  // replace the current position with a map.  Give the two values names of 'old' and 'new'. 
-	  MERGE_OVERRIDE("%"); // do your best to do a deep merge of the old and new values.
-	  
-	  private String identifier;
-	  
-	  private CollisionBehavior(String identifier){
-	    this.identifier = identifier;
-	  }
-	  public static final CollisionBehavior DEFAULT = FAIL;
-	  
-	  public static final CollisionBehavior find(String c){
-	    if(c == null || c.isEmpty()) return DEFAULT;
-	    
-	    for(CollisionBehavior b : values()){
-	      if(b.identifier.equals(c)) return b;
-	    }
-	    return DEFAULT;
-	  }
-	}
+
+    @Override
+    protected String parseValue(String s) {
+      return s;
+    }
+
+    @Override
+    public MajorType getMajorType() {
+      return QUOTED_STRING_CONSTANT;
+    }
+
+    @Override
+    public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E> visitor, V value) throws E {
+      return visitor.visitQuotedStringConstant(this, value);
+    }
+  }
+
+  public static enum CollisionBehavior {
+    SKIP("-"), // keep the old value.
+    FAIL("!"), // give up on the record
+    REPLACE("+"), // replace the old value with the new value.
+    ARRAYIFY("]"), // replace the current position with an array. Then place the
+                   // old and new value in the array.
+    OBJECTIFY("}"), // replace the current position with a map. Give the two
+                    // values names of 'old' and 'new'.
+    MERGE_OVERRIDE("%"); // do your best to do a deep merge of the old and new
+                         // values.
+
+    private String identifier;
+
+    private CollisionBehavior(String identifier) {
+      this.identifier = identifier;
+    }
+
+    public static final CollisionBehavior DEFAULT = FAIL;
+
+    public static final CollisionBehavior find(String c) {
+      if (c == null || c.isEmpty())
+        return DEFAULT;
+
+      for (CollisionBehavior b : values()) {
+        if (b.identifier.equals(c))
+          return b;
+      }
+      return DEFAULT;
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/BooleanFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/BooleanFunctions.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/BooleanFunctions.java
index 9163a5b..65d4c76 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/BooleanFunctions.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/BooleanFunctions.java
@@ -22,7 +22,7 @@ import org.apache.drill.common.expression.ArgumentValidators.ComparableArguments
 import org.apache.drill.common.expression.CallProvider;
 import org.apache.drill.common.expression.FunctionDefinition;
 import org.apache.drill.common.expression.OutputTypeDeterminer;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.Types;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,8 +32,8 @@ public class BooleanFunctions implements CallProvider {
   @Override
   public FunctionDefinition[] getFunctionDefintions() {
     return new FunctionDefinition[] {
-        FunctionDefinition.operator("or", new AllowedTypeList(2, Integer.MAX_VALUE, DataType.BOOLEAN), OutputTypeDeterminer.FIXED_BOOLEAN, "or", "||"),
-        FunctionDefinition.operator("and", new AllowedTypeList(2, Integer.MAX_VALUE, DataType.BOOLEAN), OutputTypeDeterminer.FIXED_BOOLEAN, "and", "&&"),
+        FunctionDefinition.operator("or", new AllowedTypeList(2, Integer.MAX_VALUE, Types.REQUIRED_BOOLEAN), OutputTypeDeterminer.FIXED_BOOLEAN, "or", "||"),
+        FunctionDefinition.operator("and", new AllowedTypeList(2, Integer.MAX_VALUE, Types.REQUIRED_BOOLEAN), OutputTypeDeterminer.FIXED_BOOLEAN, "and", "&&"),
         FunctionDefinition.operator("greater than", new ComparableArguments(2), OutputTypeDeterminer.FIXED_BOOLEAN, ">"),
         FunctionDefinition.operator("less than", new ComparableArguments(2), OutputTypeDeterminer.FIXED_BOOLEAN, "<"),
         FunctionDefinition.operator("equal", new ComparableArguments(2), OutputTypeDeterminer.FIXED_BOOLEAN, "==", "<>"),

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java
index 75f8cdb..4e530b8 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java
@@ -30,11 +30,11 @@ public class MathFunctions implements CallProvider{
   @Override
   public FunctionDefinition[] getFunctionDefintions() {
     return new FunctionDefinition[]{
-        FunctionDefinition.operator("add", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsFirstInput(), "+"),
-        FunctionDefinition.operator("subtract", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsFirstInput(), "-"),
-        FunctionDefinition.operator("divide", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsFirstInput(), "/"),
-        FunctionDefinition.operator("multiply", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsFirstInput(), "*"),
-        FunctionDefinition.operator("modulo", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsFirstInput(), "%"),
+        FunctionDefinition.operator("add", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "+"),
+        FunctionDefinition.operator("subtract", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "-"),
+        FunctionDefinition.operator("divide", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "/"),
+        FunctionDefinition.operator("multiply", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "*"),
+        FunctionDefinition.operator("modulo", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "%"),
         
     };
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/StringFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/StringFunctions.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/StringFunctions.java
index 494ba38..568b209 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/StringFunctions.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/StringFunctions.java
@@ -22,7 +22,7 @@ import org.apache.drill.common.expression.BasicArgumentValidator;
 import org.apache.drill.common.expression.CallProvider;
 import org.apache.drill.common.expression.FunctionDefinition;
 import org.apache.drill.common.expression.OutputTypeDeterminer.FixedType;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
 
 public class StringFunctions implements CallProvider{
 
@@ -30,8 +30,9 @@ public class StringFunctions implements CallProvider{
   @Override
   public FunctionDefinition[] getFunctionDefintions() {
     return new FunctionDefinition[]{
-        FunctionDefinition.simple("regex_like", new BasicArgumentValidator(new Arg(true, "pattern", DataType.NVARCHAR), new Arg("value", DataType.NVARCHAR) ), new FixedType(DataType.BOOLEAN)),
-        //new FunctionDefinition("startsWith", new ArgumentValidators.BasicArgumentValidator(DataTypeImpls.NVARCHAR), new FixedType(DataTypeImpls.BOOLEAN), false, false),
+        FunctionDefinition.simple("regex_like", new BasicArgumentValidator( //
+            new Arg(true, false, "pattern", MinorType.VARCHAR1, MinorType.VARCHAR2, MinorType.VARCHAR4), //
+            new Arg(false, true, "value", MinorType.FIXEDCHAR, MinorType.VARCHAR1, MinorType.VARCHAR2, MinorType.VARCHAR4) ), FixedType.FIXED_BOOLEAN),
     };
 
   }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/UnaryFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/UnaryFunctions.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/UnaryFunctions.java
index 8660c5f..5570d10 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/UnaryFunctions.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/fn/UnaryFunctions.java
@@ -22,15 +22,15 @@ import org.apache.drill.common.expression.BasicArgumentValidator;
 import org.apache.drill.common.expression.CallProvider;
 import org.apache.drill.common.expression.FunctionDefinition;
 import org.apache.drill.common.expression.OutputTypeDeterminer;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.Types;
 
 public class UnaryFunctions implements CallProvider{
 
   @Override
   public FunctionDefinition[] getFunctionDefintions() {
     return new FunctionDefinition[]{
-        FunctionDefinition.operator("isNull", new ArgumentValidators.AnyTypeAllowed(1), new OutputTypeDeterminer.FixedType(DataType.BOOLEAN)),
-        FunctionDefinition.operator("not", new BasicArgumentValidator(DataType.BOOLEAN), new OutputTypeDeterminer.FixedType(DataType.BOOLEAN), "!"),
+        FunctionDefinition.operator("isNull", new ArgumentValidators.AnyTypeAllowed(1), new OutputTypeDeterminer.FixedType(Types.REQUIRED_BOOLEAN)),
+        FunctionDefinition.operator("not", new BasicArgumentValidator(Types.REQUIRED_BOOLEAN), new OutputTypeDeterminer.FixedType(Types.REQUIRED_BOOLEAN), "!"),
         FunctionDefinition.operator("negative", new ArgumentValidators.NumericTypeAllowed(1, true), new OutputTypeDeterminer.SameAsFirstInput(), "u-"),
     };
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/AtomType.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/AtomType.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/AtomType.java
new file mode 100644
index 0000000..f21ddb9
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/AtomType.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.common.expression.types;
+
+
+public class AtomType extends DataType {
+  private String name;
+  private Comparability comparability;
+  private boolean isNumericType;
+  
+  public AtomType(String name, Comparability comparability, boolean isNumericType) {
+    super();
+    this.name = name;
+    this.comparability = comparability;
+    this.isNumericType = isNumericType;
+  }
+
+  
+  public boolean isNumericType() {
+    return isNumericType;
+  }
+
+
+  @Override
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public boolean isLateBind() {
+    return false;
+  }
+
+  @Override
+  public boolean hasChildType() {
+    return false;
+  }
+
+  @Override
+  public DataType getChildType() {
+    return null;
+  }
+
+  @Override
+  public Comparability getComparability() {
+    return comparability;
+  }
+  
+  
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/DataType.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/DataType.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/DataType.java
index 56e2485..84ff054 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/DataType.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/types/DataType.java
@@ -37,7 +37,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
 
 @JsonSerialize(using = DataType.Se.class)
 @JsonDeserialize(using = DataType.De.class)
-public abstract class DataType {
+abstract class DataType {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DataType.class);
   
   public static enum Comparability{

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java
new file mode 100644
index 0000000..d561f7e
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AbstractExprVisitor.java
@@ -0,0 +1,56 @@
+package org.apache.drill.common.expression.visitors;
+
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.expression.IfExpression;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.expression.ValueExpressions.BooleanExpression;
+import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
+import org.apache.drill.common.expression.ValueExpressions.LongExpression;
+import org.apache.drill.common.expression.ValueExpressions.QuotedString;
+
+public abstract class AbstractExprVisitor<T, VAL, EXCEP extends Exception> implements ExprVisitor<T, VAL, EXCEP> {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractExprVisitor.class);
+
+  @Override
+  public T visitFunctionCall(FunctionCall call, VAL value) throws EXCEP {
+    return null;
+  }
+
+  @Override
+  public T visitIfExpression(IfExpression ifExpr, VAL value) throws EXCEP {
+    return visitUnknown(ifExpr, value);
+  }
+
+  @Override
+  public T visitSchemaPath(SchemaPath path, VAL value) throws EXCEP {
+    return visitUnknown(path, value);
+  }
+
+  @Override
+  public T visitLongConstant(LongExpression intExpr, VAL value) throws EXCEP {
+    return visitUnknown(intExpr, value);
+  }
+
+  @Override
+  public T visitDoubleConstant(DoubleExpression dExpr, VAL value) throws EXCEP {
+    return visitUnknown(dExpr, value);
+  }
+
+  @Override
+  public T visitBooleanConstant(BooleanExpression e, VAL value) throws EXCEP {
+    return visitUnknown(e, value);
+  }
+
+  @Override
+  public T visitQuotedStringConstant(QuotedString e, VAL value) throws EXCEP {
+    return visitUnknown(e, value);
+  }
+
+  @Override
+  public T visitUnknown(LogicalExpression e, VAL value) throws EXCEP {
+    throw new UnsupportedOperationException(String.format("Expression of type %s not handled by visitor type %s.", e.getClass().getCanonicalName(), this.getClass().getCanonicalName()));
+  }
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
index 9860bdf..4d99b15 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/AggregateChecker.java
@@ -27,26 +27,26 @@ import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
 import org.apache.drill.common.expression.ValueExpressions.LongExpression;
 import org.apache.drill.common.expression.ValueExpressions.QuotedString;
 
-public final class AggregateChecker implements ExprVisitor<Boolean>{
+public final class AggregateChecker extends SimpleExprVisitor<Boolean>{
 	
   public static final AggregateChecker INSTANCE = new AggregateChecker();
   
   private AggregateChecker(){};
   
   public static boolean isAggregating(LogicalExpression e){
-    return e.accept(INSTANCE);
+    return e.accept(INSTANCE, null);
   }
 
   @Override
   public Boolean visitFunctionCall(FunctionCall call) {
     if(call.getDefinition().isAggregating()){
       for(LogicalExpression e : call){
-        if(e.accept(this)) throw new IllegalArgumentException(String.format("Your aggregating function call %s also includes arguments that contain aggregations.  This isn't allowed.", call.getDefinition().toString()));
+        if(e.accept(this, null)) throw new IllegalArgumentException(String.format("Your aggregating function call %s also includes arguments that contain aggregations.  This isn't allowed.", call.getDefinition().toString()));
       }
       return true;
     }else{
       for(LogicalExpression e : call){
-        if(e.accept(this)) return true;
+        if(e.accept(this, null)) return true;
       }
       return false;
     }
@@ -55,9 +55,9 @@ public final class AggregateChecker implements ExprVisitor<Boolean>{
   @Override
   public Boolean visitIfExpression(IfExpression ifExpr) {
     for(IfCondition c : ifExpr){
-      if(c.condition.accept(this) || c.expression.accept(this)) return true;
+      if(c.condition.accept(this, null) || c.expression.accept(this, null)) return true;
     }
-    return ifExpr.elseExpression.accept(this);
+    return ifExpr.elseExpression.accept(this, null);
   }
 
   @Override
@@ -66,22 +66,27 @@ public final class AggregateChecker implements ExprVisitor<Boolean>{
   }
 
   @Override
-  public Boolean visitLongExpression(LongExpression intExpr) {
+  public Boolean visitLongConstant(LongExpression intExpr) {
     return false;
   }
 
   @Override
-  public Boolean visitDoubleExpression(DoubleExpression dExpr) {
+  public Boolean visitDoubleConstant(DoubleExpression dExpr) {
     return false;
   }
 
   @Override
-  public Boolean visitBoolean(BooleanExpression e) {
+  public Boolean visitBooleanConstant(BooleanExpression e) {
     return false;
   }
 
   @Override
-  public Boolean visitQuotedString(QuotedString e) {
+  public Boolean visitQuotedStringConstant(QuotedString e) {
+    return false;
+  }
+
+  @Override
+  public Boolean visitUnknown(LogicalExpression e, Void value) throws RuntimeException {
     return false;
   }
 	

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
index 307b2cf..038fb85 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ConstantChecker.java
@@ -27,20 +27,20 @@ import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
 import org.apache.drill.common.expression.ValueExpressions.LongExpression;
 import org.apache.drill.common.expression.ValueExpressions.QuotedString;
 
-public final class ConstantChecker implements ExprVisitor<Boolean>{
+public final class ConstantChecker extends SimpleExprVisitor<Boolean>{
 	
   private final static ConstantChecker INSTANCE = new ConstantChecker();
   
   private ConstantChecker(){}
   
   public static boolean onlyIncludesConstants(LogicalExpression e){
-    return e.accept(INSTANCE);
+    return e.accept(INSTANCE, null);
   }
 
   @Override
   public Boolean visitFunctionCall(FunctionCall call) {
     for(LogicalExpression e : call){
-      if(!e.accept(this)) return false;
+      if(!e.accept(this, null)) return false;
     }
     return true;
   }
@@ -48,7 +48,7 @@ public final class ConstantChecker implements ExprVisitor<Boolean>{
   @Override
   public Boolean visitIfExpression(IfExpression ifExpr) {
     for(IfCondition c : ifExpr){
-      if(!c.condition.accept(this) || !c.expression.accept(this)) return false;
+      if(!c.condition.accept(this, null) || !c.expression.accept(this, null)) return false;
     }
     return true;
   }
@@ -59,24 +59,29 @@ public final class ConstantChecker implements ExprVisitor<Boolean>{
   }
 
   @Override
-  public Boolean visitLongExpression(LongExpression intExpr) {
+  public Boolean visitLongConstant(LongExpression intExpr) {
     return true;
   }
 
   @Override
-  public Boolean visitDoubleExpression(DoubleExpression dExpr) {
+  public Boolean visitDoubleConstant(DoubleExpression dExpr) {
     return true;
   }
 
   @Override
-  public Boolean visitBoolean(BooleanExpression e) {
+  public Boolean visitBooleanConstant(BooleanExpression e) {
     return true;
   }
 
   @Override
-  public Boolean visitQuotedString(QuotedString e) {
+  public Boolean visitQuotedStringConstant(QuotedString e) {
     return true;
   }
+
+  @Override
+  public Boolean visitUnknown(LogicalExpression e, Void value) throws RuntimeException {
+    return false;
+  }
 	
   
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
index 5ce0ef5..cd27157 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/ExprVisitor.java
@@ -19,18 +19,20 @@ package org.apache.drill.common.expression.visitors;
 
 import org.apache.drill.common.expression.FunctionCall;
 import org.apache.drill.common.expression.IfExpression;
+import org.apache.drill.common.expression.LogicalExpression;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.common.expression.ValueExpressions.BooleanExpression;
 import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
 import org.apache.drill.common.expression.ValueExpressions.LongExpression;
 import org.apache.drill.common.expression.ValueExpressions.QuotedString;
 
-public interface ExprVisitor<T> {
-	public T visitFunctionCall(FunctionCall call);
-	public T visitIfExpression(IfExpression ifExpr);
-	public T visitSchemaPath(SchemaPath path);
-	public T visitLongExpression(LongExpression intExpr);
-	public T visitDoubleExpression(DoubleExpression dExpr);
-	public T visitBoolean(BooleanExpression e);
-	public T visitQuotedString(QuotedString e);	
+public interface ExprVisitor<T, VAL, EXCEP extends Exception> {
+	public T visitFunctionCall(FunctionCall call, VAL value) throws EXCEP;
+	public T visitIfExpression(IfExpression ifExpr, VAL value) throws EXCEP;
+	public T visitSchemaPath(SchemaPath path, VAL value) throws EXCEP;	
+	public T visitLongConstant(LongExpression intExpr, VAL value) throws EXCEP;
+	public T visitDoubleConstant(DoubleExpression dExpr, VAL value) throws EXCEP;
+	public T visitBooleanConstant(BooleanExpression e, VAL value) throws EXCEP;
+	public T visitQuotedStringConstant(QuotedString e, VAL value) throws EXCEP;	
+	public T visitUnknown(LogicalExpression e, VAL value) throws EXCEP;
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/SimpleExprVisitor.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/SimpleExprVisitor.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/SimpleExprVisitor.java
new file mode 100644
index 0000000..434bdaf
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/visitors/SimpleExprVisitor.java
@@ -0,0 +1,56 @@
+package org.apache.drill.common.expression.visitors;
+
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.expression.IfExpression;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.expression.ValueExpressions.BooleanExpression;
+import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
+import org.apache.drill.common.expression.ValueExpressions.LongExpression;
+import org.apache.drill.common.expression.ValueExpressions.QuotedString;
+
+public abstract class SimpleExprVisitor<T> implements ExprVisitor<T, Void, RuntimeException>{
+
+  @Override
+  public T visitFunctionCall(FunctionCall call, Void value) throws RuntimeException {
+    return visitFunctionCall(call);
+  }
+
+  @Override
+  public T visitIfExpression(IfExpression ifExpr, Void value) throws RuntimeException {
+    return visitIfExpression(ifExpr);
+  }
+
+  @Override
+  public T visitSchemaPath(SchemaPath path, Void value) throws RuntimeException {
+    return visitSchemaPath(path);
+  }
+
+  @Override
+  public T visitLongConstant(LongExpression intExpr, Void value) throws RuntimeException {
+    return visitLongConstant(intExpr);
+  }
+
+  @Override
+  public T visitDoubleConstant(DoubleExpression dExpr, Void value) throws RuntimeException {
+    return visitDoubleConstant(dExpr);
+  }
+
+  @Override
+  public T visitBooleanConstant(BooleanExpression e, Void value) throws RuntimeException {
+    return visitBooleanConstant(e);
+  }
+
+  @Override
+  public T visitQuotedStringConstant(QuotedString e, Void value) throws RuntimeException {
+    return visitQuotedStringConstant(e);
+  }
+
+  
+  public abstract T visitFunctionCall(FunctionCall call);
+  public abstract T visitIfExpression(IfExpression ifExpr);
+  public abstract T visitSchemaPath(SchemaPath path);
+  public abstract T visitLongConstant(LongExpression intExpr);
+  public abstract T visitDoubleConstant(DoubleExpression dExpr);
+  public abstract T visitBooleanConstant(BooleanExpression e);
+  public abstract T visitQuotedStringConstant(QuotedString e); 
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/java/org/apache/drill/common/types/Types.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/types/Types.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/types/Types.java
new file mode 100644
index 0000000..e1343ab
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/types/Types.java
@@ -0,0 +1,134 @@
+package org.apache.drill.common.types;
+
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+
+public class Types {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Types.class);
+  
+  public static final MajorType NULL = required(MinorType.NULL);
+  public static final MajorType LATE_BIND_TYPE = optional(MinorType.LATE);
+  public static final MajorType REQUIRED_BOOLEAN = required(MinorType.BOOLEAN);
+  
+  public static enum Comparability{
+    UNKNOWN, NONE, EQUAL, ORDERED;
+  }
+  
+  public static boolean isNumericType(MajorType type){
+    if(type.getMode() == DataMode.REPEATED) return false;
+    
+    switch(type.getMinorType()){
+    case BIGINT:
+    case DECIMAL16:
+    case DECIMAL4:
+    case DECIMAL8:
+    case FLOAT4:
+    case FLOAT8:
+    case INT:
+    case MONEY:
+    case SMALLINT:
+    case TINYINT:
+    case UINT1:
+    case UINT2:
+    case UINT4:
+    case UINT8:
+      return true;
+      default:
+        return false;
+    }
+  }
+  
+  public static boolean isStringScalarType(MajorType type){
+    if(type.getMode() == DataMode.REPEATED) return false;
+    switch(type.getMinorType()){
+    case FIXEDCHAR:
+    case VARCHAR1:
+    case VARCHAR2:
+    case VARCHAR4:
+      return true;
+    default: 
+      return false;
+    }
+  }
+  
+  public static boolean isBytesScalarType(MajorType type){
+    if(type.getMode() == DataMode.REPEATED) return false;
+    switch(type.getMinorType()){
+    case FIXEDBINARY:
+    case VARBINARY1:
+    case VARBINARY2:
+    case VARBINARY4:
+      return true;
+    default: 
+      return false;
+    }
+  }
+  
+  public static Comparability getComparability(MajorType type){
+    if(type.getMode() == DataMode.REPEATED) return Comparability.NONE;
+    if(type.getMinorType() == MinorType.LATE) return Comparability.UNKNOWN;
+    
+    switch(type.getMinorType()){
+    case LATE:
+      return Comparability.UNKNOWN;
+    case MAP:
+    case REPEATMAP:
+      return Comparability.NONE;
+    case INTERVAL:
+    case BOOLEAN:
+    case MSGPACK2:
+    case MSGPACK4:
+    case PROTO2:
+    case PROTO4:
+      return Comparability.EQUAL;
+    default:
+      return Comparability.ORDERED;
+    }
+    
+  }
+  
+  
+  public static boolean softEquals(MajorType a, MajorType b, boolean allowNullSwap){
+    if(a.getMinorType() != b.getMinorType()) return false;
+    if(allowNullSwap){
+      switch(a.getMode()){
+      case OPTIONAL:
+      case REQUIRED:
+        switch(b.getMode()){
+        case OPTIONAL:
+        case REQUIRED:
+          return true;
+        default:
+          return false;
+        }
+      default:
+        return false;
+      }
+    }else{
+      if(a.getMode() != b.getMode()){
+        return false;
+      }else{
+        return true;
+      }
+    }
+  }
+  
+  public static boolean isLateBind(MajorType type){
+    return type.getMinorType() == MinorType.LATE;
+  }
+  
+  public static MajorType required(MinorType type){
+    return MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(type).build();
+  }
+  
+  public static MajorType repeated(MinorType type){
+    return MajorType.newBuilder().setMode(DataMode.REPEATED).setMinorType(type).build();
+  }
+  
+  public static MajorType optional(MinorType type){
+    return MajorType.newBuilder().setMode(DataMode.OPTIONAL).setMinorType(type).build();
+  }
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/common/src/main/protobuf/Types.proto
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/protobuf/Types.proto b/sandbox/prototype/common/src/main/protobuf/Types.proto
new file mode 100644
index 0000000..58399de
--- /dev/null
+++ b/sandbox/prototype/common/src/main/protobuf/Types.proto
@@ -0,0 +1,64 @@
+package common;
+
+option java_package = "org.apache.drill.common.types";
+option java_outer_classname = "TypeProtos";
+option optimize_for = SPEED;
+
+
+enum MinorType {
+    LATE = 0;   //  late binding type
+    MAP = 1;   //  an empty map column.  Useful for conceptual setup.  Children listed within here
+    REPEATMAP = 2;   //  a repeated map column (means that multiple children sit below this)
+    TINYINT = 3;   //  single byte signed integer
+    SMALLINT = 4;   //  two byte signed integer
+    INT = 5;   //  four byte signed integer
+    BIGINT = 6;   //  eight byte signed integer
+    DECIMAL4 = 7;   //  a decimal supporting precision between 1 and 8 (4 bits for decimal location, 1 sign)
+    DECIMAL8 = 8;   //  a decimal supporting precision between 9 and 18 (5 bits for decimal location, 1 sign)
+    DECIMAL16 = 10;   //  a decimal supporting precision between 19 and 37 (6 bits for decimal location, 1 sign)
+    MONEY = 11;   //  signed decimal with two digit precision
+    DATE = 12;   //  days since 4713bc 
+    TIME = 13;   //  time in micros before or after 2000/1/1
+    TIMETZ = 14;   //  time in micros before or after 2000/1/1 with timezone
+    TIMESTAMP = 15;   //  unix epoch time in millis
+    DATETIME = 16;   //  TBD
+    INTERVAL = 17;   //  TBD
+    FLOAT4 = 18;   //  4 byte ieee 754 
+    FLOAT8 = 19;   //  8 byte ieee 754
+    BOOLEAN = 20;   //  single bit value
+    FIXEDCHAR = 21;   //  utf8 fixed length string, padded with spaces
+    VARCHAR1 = 22;   //  utf8 variable length string (up to 2^8 in length)
+    VARCHAR2 = 23;   //  utf8 variable length string (up to 2^16 in length)
+    VARCHAR4 = 24;   //  utf8 variable length string (up to 2^32 in length)
+    FIXEDBINARY = 25;   //  fixed length binary, padded with 0 bytes
+    VARBINARY1 = 26;   //  variable length binary (up to 2^8 in length)
+    VARBINARY2 = 27;   //  variable length binary (up to 2^16 in length)
+    VARBINARY4 = 28;   //  variable length binary (up to 2^32 in length)
+    UINT1 = 29;   //  unsigned 1 byte integer
+    UINT2 = 30;   //  unsigned 2 byte integer
+    UINT4 = 31;   //  unsigned 4 byte integer
+    UINT8 = 32;   //  unsigned 8 byte integer
+    PROTO2 = 33;   //  protobuf encoded complex type. (up to 2^16 in length)
+    PROTO4 = 34;   //  protobuf encoded complex type. (up to 2^32 in length)
+    MSGPACK2 = 35;   //  msgpack encoded complex type. (up to 2^16 in length)
+    MSGPACK4 = 36;   //  msgpack encoded complex type. (up to 2^32 in length)
+    NULL = 37; // a value of unknown type (e.g. a missing reference).
+    
+}
+
+message MajorType {
+  optional MinorType minor_type = 1;
+  optional DataMode mode = 2;
+  optional int32 width = 3; // optional width for fixed size values.
+  optional int32 precision = 4; // used for decimal types
+  optional int32 scale = 5; // used for decimal types 
+}
+
+
+
+enum DataMode {
+  OPTIONAL = 0; // nullable
+  REQUIRED = 1; // non-nullable
+  REPEATED = 2; // single, repeated-field
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/pom.xml b/sandbox/prototype/exec/java-exec/pom.xml
index 1b6dac0..e348bc7 100644
--- a/sandbox/prototype/exec/java-exec/pom.xml
+++ b/sandbox/prototype/exec/java-exec/pom.xml
@@ -1,161 +1,186 @@
 <?xml version="1.0"?>
 <project
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<artifactId>exec-parent</artifactId>
-		<groupId>org.apache.drill.exec</groupId>
-		<version>1.0-SNAPSHOT</version>
-	</parent>
-	<artifactId>java-exec</artifactId>
-	<name>java-exec</name>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>exec-parent</artifactId>
+    <groupId>org.apache.drill.exec</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>java-exec</artifactId>
+  <name>java-exec</name>
 
-	<properties>
-		<target.gen.source.path>${project.basedir}/target/generated-sources</target.gen.source.path>
-		<proto.cas.path>${project.basedir}/src/main/protobuf/</proto.cas.path>
-	</properties>
+  <dependencies>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-util</artifactId>
+      <version>3.3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-commons</artifactId>
+      <version>3.3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>com.sun.codemodel</groupId>
+      <artifactId>codemodel</artifactId>
+      <version>2.6</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.janino</groupId>
+      <artifactId>commons-compiler-jdk</artifactId>
+      <version>2.6.1</version>
+    </dependency>
+    <dependency>
+      <groupId>net.hydromatic</groupId>
+      <artifactId>optiq</artifactId>
+      <version>0.3.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.freemarker</groupId>
+      <artifactId>freemarker</artifactId>
+      <version>2.3.19</version>
+    </dependency>
+    <dependency>
+      <groupId>com.google.caliper</groupId>
+      <artifactId>caliper</artifactId>
+      <version>1.0-beta-1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.twitter</groupId>
+      <artifactId>parquet-column</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>com.yammer.metrics</groupId>
+      <artifactId>metrics-core</artifactId>
+      <version>3.0.0-BETA1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.drill</groupId>
+      <artifactId>common</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.drill</groupId>
+      <artifactId>common</artifactId>
+      <version>1.0-SNAPSHOT</version>
+      <classifier>tests</classifier>
+    </dependency>
+    <dependency>
+      <groupId>com.beust</groupId>
+      <artifactId>jcommander</artifactId>
+      <version>1.30</version>
+    </dependency>
+    <dependency>
+      <groupId>com.netflix.curator</groupId>
+      <artifactId>curator-x-discovery</artifactId>
+      <version>1.1.9</version>
+      <exclusions>
+        <!-- <exclusion> -->
+        <!-- <artifactId>netty</artifactId> -->
+        <!-- <groupId>org.jboss.netty</groupId> -->
+        <!-- </exclusion> -->
+        <exclusion>
+          <artifactId>slf4j-log4j12</artifactId>
+          <groupId>org.slf4j</groupId>
+        </exclusion>
+        <exclusion>
+          <artifactId>log4j</artifactId>
+          <groupId>log4j</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.xerial.snappy</groupId>
+      <artifactId>snappy-java</artifactId>
+      <version>1.0.5-M3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-core</artifactId>
+      <version>1.1.0</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>jets3t</artifactId>
+          <groupId>net.java.dev.jets3t</groupId>
+        </exclusion>
+        <exclusion>
+          <artifactId>commons-logging</artifactId>
+          <groupId>commons-logging</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>com.carrotsearch</groupId>
+      <artifactId>hppc</artifactId>
+      <version>0.4.2</version>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-all</artifactId>
+      <version>4.0.0.CR2</version>
+    </dependency>
+    <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+      <version>2.5.0</version>
+    </dependency>
+    <dependency>
+      <groupId>com.hazelcast</groupId>
+      <artifactId>hazelcast</artifactId>
+      <version>2.5.1</version>
+    </dependency>
+  </dependencies>
 
-	<dependencies>
-		<dependency>
-			<groupId>asm</groupId>
-			<artifactId>asm-util</artifactId>
-			<version>3.3.1</version>
-		</dependency>
-		<dependency>
-			<groupId>asm</groupId>
-			<artifactId>asm-commons</artifactId>
-			<version>3.3.1</version>
-		</dependency>
-		<dependency>
-			<groupId>org.codehaus.janino</groupId>
-			<artifactId>commons-compiler-jdk</artifactId>
-			<version>2.6.1</version>
-		</dependency>
-		<dependency>
-			<groupId>net.hydromatic</groupId>
-			<artifactId>optiq</artifactId>
-			<version>0.3.2</version>
-		</dependency>
-		<dependency>
-			<groupId>com.twitter</groupId>
-			<artifactId>parquet-column</artifactId>
-			<version>1.0.0-SNAPSHOT</version>
-		</dependency>
-		<dependency>
-			<groupId>com.yammer.metrics</groupId>
-			<artifactId>metrics-core</artifactId>
-			<version>3.0.0-BETA1</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.drill</groupId>
-			<artifactId>common</artifactId>
-			<version>1.0-SNAPSHOT</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.drill</groupId>
-			<artifactId>common</artifactId>
-			<version>1.0-SNAPSHOT</version>
-			<classifier>tests</classifier>
-		</dependency>
-		<dependency>
-			<groupId>com.beust</groupId>
-			<artifactId>jcommander</artifactId>
-			<version>1.30</version>
-		</dependency>
-		<dependency>
-			<groupId>com.netflix.curator</groupId>
-			<artifactId>curator-x-discovery</artifactId>
-			<version>1.1.9</version>
-			<exclusions>
-				<!-- <exclusion> -->
-				<!-- <artifactId>netty</artifactId> -->
-				<!-- <groupId>org.jboss.netty</groupId> -->
-				<!-- </exclusion> -->
-				<exclusion>
-					<artifactId>slf4j-log4j12</artifactId>
-					<groupId>org.slf4j</groupId>
-				</exclusion>
-				<exclusion>
-					<artifactId>log4j</artifactId>
-					<groupId>log4j</groupId>
-				</exclusion>
-			</exclusions>
-		</dependency>
-		<dependency>
-			<groupId>org.xerial.snappy</groupId>
-			<artifactId>snappy-java</artifactId>
-			<version>1.0.5-M3</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.hadoop</groupId>
-			<artifactId>hadoop-core</artifactId>
-			<version>1.1.0</version>
-			<exclusions>
-				<exclusion>
-					<artifactId>jets3t</artifactId>
-					<groupId>net.java.dev.jets3t</groupId>
-				</exclusion>
-				<exclusion>
-					<artifactId>commons-logging</artifactId>
-					<groupId>commons-logging</groupId>
-				</exclusion>
-			</exclusions>
-		</dependency>
-		<dependency>
-			<groupId>com.carrotsearch</groupId>
-			<artifactId>hppc</artifactId>
-			<version>0.4.2</version>
-		</dependency>
-		<dependency>
-			<groupId>io.netty</groupId>
-			<artifactId>netty-all</artifactId>
-			<version>4.0.0.CR2</version>
-		</dependency>
-		<dependency>
-			<groupId>com.google.protobuf</groupId>
-			<artifactId>protobuf-java</artifactId>
-			<version>2.5.0</version>
-		</dependency>
-		<dependency>
-			<groupId>com.hazelcast</groupId>
-			<artifactId>hazelcast</artifactId>
-			<version>2.5.1</version>
-		</dependency>
-	</dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.6</version>
+        <executions>
+          <execution>
+            <id>copy-resources</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>${basedir}/target/classes/</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>src/main/java</directory>
+                  <filtering>true</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>generate-sources</id>
+            <phase>generate-sources</phase>
+            <configuration>
+              <tasks>
+                <mkdir dir="${target.gen.source.path}" />
+                <path id="proto.path.files">
+                  <fileset dir="${proto.cas.path}">
+                    <include name="*.proto" />
+                  </fileset>
+                </path>
+                <pathconvert pathsep=" " property="proto.files"
+                  refid="proto.path.files" />
 
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.codehaus.mojo</groupId>
-				<artifactId>native-maven-plugin</artifactId>
-				<version>1.0-alpha-7</version>
-				<configuration>
-					<javahClassNames>
-						<javahClassName>org.apache.drill.exec.mem.ByteBufferAllocator</javahClassName>
-					</javahClassNames>
-				</configuration>
-			</plugin>
-			<plugin>
-				<artifactId>maven-antrun-plugin</artifactId>
-				<executions>
-					<execution>
-						<id>generate-sources</id>
-						<phase>generate-sources</phase>
-						<configuration>
-							<tasks>
-								<mkdir dir="${target.gen.source.path}" />
-								<path id="proto.path.files">
-									<fileset dir="${proto.cas.path}">
-										<include name="*.proto" />
-									</fileset>
-								</path>
-								<pathconvert pathsep=" " property="proto.files"
-									refid="proto.path.files" />
-
-								<exec executable="protoc">
-									<arg value="--java_out=${target.gen.source.path}" />
-									<arg value="--proto_path=${proto.cas.path}" />
+                <exec executable="protoc">
+                  <arg value="--java_out=${target.gen.source.path}" />
+                  <arg value="--proto_path=${proto.cas.path}" />
+<<<<<<< HEAD
+                  <arg value="--proto_path=${project.basedir}/../../common/src/main/protobuf/" />
 									<arg line="${proto.files}" />
 								</exec>
 							</tasks>
@@ -201,5 +226,34 @@
 			<!-- </plugin> -->
 		</plugins>
 	</build>
+=======
+                  <arg
+                    value="--proto_path=${project.basedir}/../../common/src/main/protobuf/" />
+                  <arg line="${proto.files}" />
+                </exec>
+              </tasks>
+              <sourceRoot>${target.gen.source.path}</sourceRoot>
+            </configuration>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <!-- <plugin> -->
+      <!-- <groupId>com.github.igor-petruk.protobuf</groupId> -->
+      <!-- <artifactId>protobuf-maven-plugin</artifactId> -->
+      <!-- <version>0.6.2</version> -->
+      <!-- <executions> -->
+      <!-- <execution> -->
+      <!-- <goals> -->
+      <!-- <goal>run</goal> -->
+      <!-- </goals> -->
+      <!-- </execution> -->
+      <!-- </executions> -->
+      <!-- </plugin> -->
+    </plugins>
+  </build>
+>>>>>>> Build working
 
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
index 0ccaa22..4eb0f4c 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
@@ -29,4 +29,5 @@ public interface ExecConstants {
   public static final String INITIAL_BIT_PORT = "drill.exec.rpc.bit.port";
   public static final String INITIAL_USER_PORT = "drill.exec.rpc.user.port";
   public static final String METRICS_CONTEXT_NAME = "drill.exec.metrics.context";
+  public static final String FUNCTION_PACKAGES = "drill.exec.functions";
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
index 814b239..079ab6c 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
@@ -79,6 +79,7 @@ public class ClassTransformer {
   }
 
   
+  
   @SuppressWarnings("unchecked")
   public <T, I> T getImplementationClass(QueryClassLoader classLoader,
       TemplateClassDefinition<T, I> templateDefinition, String internalClassBody, I initObject)

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/CodeModelTools.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/CodeModelTools.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/CodeModelTools.java
new file mode 100644
index 0000000..5e7f1bd
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/compile/CodeModelTools.java
@@ -0,0 +1,31 @@
+package org.apache.drill.exec.compile;
+
+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.exec.expr.CodeGenerator;
+
+import com.sun.codemodel.JType;
+
+public class CodeModelTools {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CodeModelTools.class);
+  
+  public static JType getType(MinorType mt, DataMode mode, CodeGenerator g){
+    switch (mt) {
+    case BOOLEAN:
+      return g.getModel().BOOLEAN;
+    case INT:
+      return g.getModel().INT;
+    case BIGINT:
+      return g.getModel().LONG;
+    default:
+      throw new UnsupportedOperationException();
+    }
+  }
+  
+  
+  public static JType getType(MajorType mt, CodeGenerator g) {
+    return getType(mt.getMinorType(), mt.getMode(), g);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/CodeGenerator.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/CodeGenerator.java
new file mode 100644
index 0000000..77ae77d
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/CodeGenerator.java
@@ -0,0 +1,201 @@
+package org.apache.drill.exec.expr;
+
+import java.io.IOException;
+
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
+import org.apache.drill.exec.expr.holders.ValueHolderImplmenetations.BooleanHolder;
+import org.apache.drill.exec.expr.holders.ValueHolderImplmenetations.IntHolder;
+import org.apache.drill.exec.expr.holders.ValueHolderImplmenetations.LongHolder;
+import org.apache.drill.exec.expr.holders.ValueHolderImplmenetations.NullableBooleanHolder;
+import org.apache.drill.exec.expr.holders.ValueHolderImplmenetations.NullableIntHolder;
+import org.apache.drill.exec.expr.holders.ValueHolderImplmenetations.NullableLongHolder;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.record.RecordBatch;
+
+import com.google.common.base.Preconditions;
+import com.sun.codemodel.JBlock;
+import com.sun.codemodel.JClassAlreadyExistsException;
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JDefinedClass;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JFieldRef;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JMod;
+import com.sun.codemodel.JType;
+import com.sun.codemodel.JVar;
+
+public class CodeGenerator {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CodeGenerator.class);
+  
+  public JDefinedClass clazz;
+  private JBlock parentEvalBlock;
+  private JBlock parentSetupBlock;
+  private JBlock currentEvalBlock;
+  private JBlock currentSetupBlock;
+  private final EvaluationVisitor evaluationVisitor;
+  private final String setupName;
+  private final String perRecordName;
+  
+  private JCodeModel model;
+  private int index = 0;
+
+  public CodeGenerator(String setupName, String perRecordName, FunctionImplementationRegistry funcRegistry) {
+    super();
+    try{
+      this.setupName = setupName;
+      this.perRecordName = perRecordName;
+      this.model = new JCodeModel();
+      this.clazz = model._package("org.apache.drill.exec.test.generated")._class("Test1");
+      this.parentEvalBlock = new JBlock();
+      this.parentSetupBlock = new JBlock();
+      this.evaluationVisitor = new EvaluationVisitor(funcRegistry);
+    } catch (JClassAlreadyExistsException e) {
+      throw new IllegalStateException(e);
+    }
+  }
+
+  public void addNextWrite(ValueVectorWriteExpression ex){
+    currentEvalBlock = new JBlock();
+    parentEvalBlock.add(currentEvalBlock);
+    currentSetupBlock = new JBlock();
+    parentSetupBlock.add(currentSetupBlock);
+    ex.accept(evaluationVisitor, this);
+  }
+  
+  public JBlock getBlock() {
+    return currentEvalBlock;
+  }
+
+  public JBlock getSetupBlock(){
+    return currentSetupBlock;
+  }
+  
+  public String generate() throws IOException{
+
+    {
+      //setup method
+      JMethod m = clazz.method(JMod.PUBLIC, model.VOID, this.setupName);
+      m.param(model._ref(FragmentContext.class), "context");
+      m.param(model._ref(RecordBatch.class), "incoming");
+      m.param(model._ref(RecordBatch.class), "outgoing");
+      m.body().add(parentSetupBlock);
+    }
+    
+    {
+      // eval method.
+      JMethod m = clazz.method(JMod.PUBLIC, model.VOID, this.perRecordName);
+      m.param(model.INT, "inIndex");
+      m.param(model.INT, "outIndex");
+      m.body().add(parentEvalBlock);
+    }
+    
+    SingleClassStringWriter w = new SingleClassStringWriter();
+    model.build(w);
+    return w.getCode().toString();
+  }
+  
+  
+  public JCodeModel getModel() {
+    return model;
+  }
+
+  public String getNextVar() {
+    return "v" + index++;
+  }
+  
+  public String getNextVar(String prefix){
+    return prefix + index++;
+  }
+  
+  public JVar declareClassField(String prefix, JType t){
+    return clazz.field(JMod.NONE, t, prefix + index++);
+  }
+  
+  public HoldingContainer declare(MajorType t){
+    return declare(t, true);
+  }
+  
+  public HoldingContainer declare(MajorType t, boolean includeNewInstance){
+    JType holderType = getHolderType(t);
+    JVar var;
+    if(includeNewInstance){
+      var = currentEvalBlock.decl(holderType, "out" + index, JExpr._new(holderType));
+    }else{
+      var = currentEvalBlock.decl(holderType, "out" + index);
+    }
+    JFieldRef outputSet = null;
+    if(t.getMode() == DataMode.OPTIONAL){
+      outputSet = var.ref("isSet");  
+    }
+    index++;
+    return new HoldingContainer(t, var, var.ref("value"), outputSet);
+  }
+  
+  
+  public class HoldingContainer{
+    private final JVar holder;
+    private final JFieldRef value;
+    private final JFieldRef isSet;
+    private final MajorType type;
+    
+    public HoldingContainer(MajorType t, JVar holder, JFieldRef value, JFieldRef isSet) {
+      super();
+      this.holder = holder;
+      this.value = value;
+      this.isSet = isSet;
+      this.type = t;
+    }
+
+    public JVar getHolder() {
+      return holder;
+    }
+
+    public JFieldRef getValue() {
+      return value;
+    }
+
+    public JFieldRef getIsSet() {
+      Preconditions.checkNotNull(isSet, "You cannot access the isSet variable when operating on a non-nullable output value.");
+      return isSet;
+    }
+    
+    public boolean isOptional(){
+      return type.getMode() == DataMode.OPTIONAL;
+    }
+    
+    public boolean isRepeated(){
+      return type.getMode() == DataMode.REPEATED;
+    }
+  }
+  
+  public JType getHolderType(MajorType t){
+    switch(t.getMode()){
+    case REQUIRED:
+      switch(t.getMinorType()){
+      case BOOLEAN:
+        return model._ref(BooleanHolder.class);
+      case INT:
+        return model._ref(IntHolder.class);
+      case BIGINT:  
+        return model._ref(LongHolder.class);
+      
+      }
+      
+    case OPTIONAL:
+      switch(t.getMinorType()){
+      case BOOLEAN:
+        return model._ref(NullableBooleanHolder.class);
+      case INT:
+        return model._ref(NullableIntHolder.class);
+      case BIGINT:  
+        return model._ref(NullableLongHolder.class);
+      }
+
+    }
+    
+    
+    throw new UnsupportedOperationException();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillAggrFunc.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillAggrFunc.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillAggrFunc.java
new file mode 100644
index 0000000..d4433e4
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillAggrFunc.java
@@ -0,0 +1,9 @@
+package org.apache.drill.exec.expr;
+
+import org.apache.drill.exec.record.RecordBatch;
+
+public interface DrillAggrFunc {
+  public void setup(RecordBatch incoming);
+  public void add();
+  public void eval();
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFunc.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFunc.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFunc.java
new file mode 100644
index 0000000..83c5ed9
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/DrillFunc.java
@@ -0,0 +1,9 @@
+package org.apache.drill.exec.expr;
+
+import org.apache.drill.exec.record.RecordBatch;
+
+public interface DrillFunc {
+  public void setup(RecordBatch incoming);
+  public void eval();
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
new file mode 100644
index 0000000..a5bc5fa
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
@@ -0,0 +1,201 @@
+package org.apache.drill.exec.expr;
+
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.expression.IfExpression;
+import org.apache.drill.common.expression.IfExpression.IfCondition;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.expression.ValueExpressions.BooleanExpression;
+import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
+import org.apache.drill.common.expression.ValueExpressions.LongExpression;
+import org.apache.drill.common.expression.ValueExpressions.QuotedString;
+import org.apache.drill.common.expression.visitors.AbstractExprVisitor;
+import org.apache.drill.exec.expr.CodeGenerator.HoldingContainer;
+import org.apache.drill.exec.expr.fn.FunctionHolder;
+import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
+import org.apache.drill.exec.record.vector.TypeHelper;
+
+import com.sun.codemodel.JBlock;
+import com.sun.codemodel.JClass;
+import com.sun.codemodel.JConditional;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JInvocation;
+import com.sun.codemodel.JType;
+import com.sun.codemodel.JVar;
+
+public class EvaluationVisitor extends AbstractExprVisitor<HoldingContainer, CodeGenerator, RuntimeException> {
+
+  private FunctionImplementationRegistry registry;
+  
+  
+  public EvaluationVisitor(FunctionImplementationRegistry registry) {
+    this.registry = registry;
+  }
+
+  @Override
+  public HoldingContainer visitFunctionCall(FunctionCall call, CodeGenerator generator) throws RuntimeException {
+    HoldingContainer[] args = new HoldingContainer[call.args.size()];
+    for(int i = 0; i < call.args.size(); i++){
+      args[i] = call.args.get(i).accept(this, generator);
+    }
+    FunctionHolder holder = registry.getFunction(call);
+    return holder.generateEvalBody(generator, args);
+  }
+  
+  @Override
+  public HoldingContainer visitIfExpression(IfExpression ifExpr, CodeGenerator generator) throws RuntimeException {
+    JBlock local = generator.getBlock();
+    
+    HoldingContainer output = generator.declare(ifExpr.getMajorType());
+    
+    JConditional jc = null;
+    JBlock conditionalBlock = new JBlock();
+    for (IfCondition c : ifExpr.conditions) {
+      HoldingContainer HoldingContainer = c.condition.accept(this, generator);
+      if (jc == null) {
+        if (HoldingContainer.isOptional()) {
+          jc = conditionalBlock._if(HoldingContainer.getIsSet().cand(HoldingContainer.getValue()));
+        } else {
+          jc = conditionalBlock._if(HoldingContainer.getValue());
+        }
+      } else {
+        if (HoldingContainer.isOptional()) {
+          jc = jc._else()._if(HoldingContainer.getIsSet().cand(HoldingContainer.getValue()));
+        } else {
+          jc = jc._else()._if(HoldingContainer.getValue());
+        }
+      }
+
+      HoldingContainer thenExpr = c.expression.accept(this, generator);
+      if (thenExpr.isOptional()) {
+        JConditional newCond = jc._then()._if(thenExpr.getIsSet());
+        JBlock b = newCond._then();
+        b.assign(output.getValue(), thenExpr.getValue());
+        b.assign(output.getIsSet(), thenExpr.getIsSet());
+      } else {
+        jc._then().assign(output.getValue(), thenExpr.getValue());
+      }
+
+    }
+
+    HoldingContainer elseExpr = ifExpr.elseExpression.accept(this, generator);
+    if (elseExpr.isOptional()) {
+      JConditional newCond = jc._else()._if(elseExpr.getIsSet());
+      JBlock b = newCond._then();
+      b.assign(output.getValue(), elseExpr.getValue());
+      b.assign(output.getIsSet(), elseExpr.getIsSet());
+    } else {
+      jc._else().assign(output.getValue(), elseExpr.getValue());
+
+    }
+    local.add(conditionalBlock);
+    return output;
+  }
+
+  @Override
+  public HoldingContainer visitSchemaPath(SchemaPath path, CodeGenerator generator) throws RuntimeException {
+    throw new UnsupportedOperationException("All schema paths should have been replaced with ValueVectorExpressions.");
+  }
+
+  @Override
+  public HoldingContainer visitLongConstant(LongExpression e, CodeGenerator generator) throws RuntimeException {
+    HoldingContainer out = generator.declare(e.getMajorType());
+    generator.getBlock().assign(out.getValue(), JExpr.lit(e.getLong()));
+    return out;
+  }
+
+  @Override
+  public HoldingContainer visitDoubleConstant(DoubleExpression e, CodeGenerator generator) throws RuntimeException {
+    HoldingContainer out = generator.declare(e.getMajorType());
+    generator.getBlock().assign(out.getValue(), JExpr.lit(e.getDouble()));
+    return out;
+  }
+
+  @Override
+  public HoldingContainer visitBooleanConstant(BooleanExpression e, CodeGenerator generator) throws RuntimeException {
+    HoldingContainer out = generator.declare(e.getMajorType());
+    generator.getBlock().assign(out.getValue(), JExpr.lit(e.getBoolean()));
+    return out;
+  }
+
+  
+  
+  @Override
+  public HoldingContainer visitUnknown(LogicalExpression e, CodeGenerator generator) throws RuntimeException {
+    if(e instanceof ValueVectorReadExpression){
+      return visitValueVectorExpression((ValueVectorReadExpression) e, generator);
+    }else if(e instanceof ValueVectorWriteExpression){
+      return visitValueVectorWriteExpression((ValueVectorWriteExpression) e, generator);
+    }else{
+      return super.visitUnknown(e, generator);  
+    }
+    
+  }
+
+  private HoldingContainer visitValueVectorWriteExpression(ValueVectorWriteExpression e, CodeGenerator generator){
+    LogicalExpression child = e.getChild();
+    HoldingContainer hc = child.accept(this, generator);
+    JBlock block = generator.getBlock();
+    
+    Class<?> vvClass = TypeHelper.getValueVectorClass(child.getMajorType().getMinorType(), child.getMajorType().getMode());
+    JType vvType = generator.getModel()._ref(vvClass);
+    JVar vv = generator.declareClassField("vv", vvType);
+    
+    // get value vector in setup block.
+    generator.getSetupBlock().assign(vv, JExpr.direct("outgoing").invoke("getValueVector") //
+      .arg(JExpr.lit(e.getFieldId())) //
+      .arg( ((JClass)vvType).dotclass()));
+    
+    if(hc.isOptional()){
+      vv.invoke("set").arg(JExpr.direct("outIndex"));
+      JConditional jc = block._if(hc.getIsSet().eq(JExpr.lit(0)).not());
+      block = jc._then();
+    }
+    block.add(vv.invoke("set").arg(JExpr.direct("outIndex")).arg(hc.getValue()));
+
+    return null;
+  }
+  
+  private HoldingContainer visitValueVectorExpression(ValueVectorReadExpression e, CodeGenerator generator) throws RuntimeException{
+    // declare value vector
+    Class<?> vvClass = TypeHelper.getValueVectorClass(e.getMajorType().getMinorType(), e.getMajorType().getMode());
+    JType vvType = generator.getModel()._ref(vvClass);
+    JVar vv1 = generator.declareClassField("vv", vvType);
+    
+    // get value vector from incoming batch and 
+    JInvocation getValue = JExpr //
+        .invoke(JExpr.direct("incoming"), "getValueVector") //
+        .arg(JExpr.lit(e.getFieldId())) //
+        .arg( ((JClass)vvType).dotclass());
+    generator.getSetupBlock().assign(vv1, getValue);
+
+    // evaluation work.
+    HoldingContainer out = generator.declare(e.getMajorType());
+    
+    
+    if(out.isOptional()){
+      JBlock blk = generator.getBlock();
+      blk.assign(out.getIsSet(), vv1.invoke("isSet").arg(JExpr.direct("index")));
+      JConditional jc = blk._if(out.getIsSet());
+      jc._then() //
+        .assign(out.getValue(), vv1.invoke("get").arg(JExpr.direct("index"))); //
+        //.assign(out.getIsSet(), JExpr.lit(1));
+      //jc._else()
+        //.assign(out.getIsSet(), JExpr.lit(0));
+      
+    }else{
+      generator.getBlock().assign(out.getValue(), vv1.invoke("get").arg(JExpr.direct("index")));
+    }
+    return out;
+  }
+  
+  
+  
+  @Override
+  public HoldingContainer visitQuotedStringConstant(QuotedString e, CodeGenerator CodeGenerator) throws RuntimeException {
+    throw new UnsupportedOperationException("We don't yet support string literals as we need to use the valuevector classes and internal vectors.");
+//    JExpr stringLiteral = JExpr.lit(e.value);
+//    CodeGenerator.block.decl(stringLiteral.invoke("getBytes").arg(JExpr.ref(Charsets.UTF_8));
+  }
+
+}