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

[6/6] git commit: Basic reference interpreter implementation

Updated Branches:
  refs/heads/master 39ccadae8 -> 238ca97d5


Basic reference interpreter implementation


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

Branch: refs/heads/master
Commit: 238ca97d5d7a34e35ac92226fb572e37f48ffc1f
Parents: 39ccada
Author: Jacques Nadeau <ja...@gmail.com>
Authored: Mon Jan 21 18:34:01 2013 -0800
Committer: Jacques Nadeau <ja...@gmail.com>
Committed: Mon Jan 21 18:34:01 2013 -0800

----------------------------------------------------------------------
 sandbox/prototype/common/pom.xml                   |   33 +
 .../drill/common/expression/parser/ExprParser.g    |   38 +-
 .../drill/common/storage/proto/ProtoLexer.g.bk     |  287 +++++++
 .../drill/common/storage/proto/ProtoParser.g.bk    |  605 +++++++++++++++
 .../java/com/google/protobuf/WireFormatProxy.java  |   10 +
 .../apache/drill/common/exceptions/DrillError.java |   44 +
 .../drill/common/exceptions/DrillException.java    |   42 +
 .../common/exceptions/DrillRuntimeException.java   |   44 +
 .../exceptions/ExpressionParsingException.java     |   45 ++
 .../org/apache/drill/common/expression/Arg.java    |   66 ++
 .../drill/common/expression/ArgumentValidator.java |   28 +
 .../common/expression/ArgumentValidators.java      |  179 +++++
 .../common/expression/BasicArgumentValidator.java  |   62 ++
 .../drill/common/expression/BooleanFunctions.java  |  141 ----
 .../drill/common/expression/CallProvider.java      |   22 +
 .../org/apache/drill/common/expression/Cast.java   |   44 -
 .../apache/drill/common/expression/DataType.java   |   53 --
 .../drill/common/expression/ErrorCollector.java    |   33 +
 .../common/expression/ExpressionFunction.java      |    9 +-
 .../expression/ExpressionValidationError.java      |   19 +-
 .../expression/ExpressionValidationException.java  |   38 +
 .../drill/common/expression/FieldReference.java    |    4 +-
 .../drill/common/expression/FunctionBase.java      |   38 +-
 .../drill/common/expression/FunctionCall.java      |   89 +++
 .../common/expression/FunctionDefinition.java      |   81 ++-
 .../drill/common/expression/FunctionInstance.java  |   34 +
 .../drill/common/expression/FunctionRegistry.java  |  108 +++
 .../drill/common/expression/IfExpression.java      |   15 +-
 .../drill/common/expression/LogicalExpression.java |   21 +-
 .../common/expression/LogicalExpressionBase.java   |   50 +-
 .../drill/common/expression/MathFunction.java      |   97 ---
 .../common/expression/OutputTypeDeterminer.java    |   55 ++
 .../drill/common/expression/PathSegment.java       |  133 ++++
 .../apache/drill/common/expression/SchemaPath.java |  140 ++++
 .../drill/common/expression/StringFunctions.java   |   69 --
 .../drill/common/expression/TypeFunctions.java     |   48 --
 .../drill/common/expression/UnaryFunctions.java    |   74 --
 .../drill/common/expression/ValidationError.java   |   22 +
 .../drill/common/expression/ValueExpressions.java  |  120 +++-
 .../common/expression/fn/AggregationFunctions.java |   35 +
 .../common/expression/fn/BooleanFunctions.java     |   47 ++
 .../drill/common/expression/fn/MathFunctions.java  |   44 +
 .../common/expression/fn/StringFunctions.java      |   39 +
 .../drill/common/expression/fn/TypeFunctions.java  |   35 +
 .../drill/common/expression/fn/UnaryFunctions.java |   39 +
 .../drill/common/expression/types/AtomType.java    |   67 ++
 .../drill/common/expression/types/DataType.java    |   50 ++
 .../common/expression/types/DataTypeFactory.java   |   25 +
 .../common/expression/types/LateBindType.java      |   53 ++
 .../expression/visitors/AggregateChecker.java      |   89 +++
 .../expression/visitors/ConstantChecker.java       |   82 ++
 .../common/expression/visitors/ExprVisitor.java    |   36 +
 .../expression/visitors/FunctionVisitor.java       |   28 -
 .../common/expression/visitors/OpVisitor.java      |    4 +-
 .../apache/drill/common/logical/JSONOptions.java   |   80 ++
 .../apache/drill/common/logical/LogicalPlan.java   |   56 +-
 .../apache/drill/common/logical/OperatorGraph.java |   96 ++-
 .../drill/common/logical/data/Aggregate.java       |    6 +-
 .../apache/drill/common/logical/data/Cogroup.java  |   38 -
 .../apache/drill/common/logical/data/Group.java    |   39 +
 .../apache/drill/common/logical/data/Grouping.java |   46 --
 .../drill/common/logical/data/LogicalOperator.java |    2 +-
 .../common/logical/data/LogicalOperatorBase.java   |   14 +-
 .../apache/drill/common/logical/data/Order.java    |    5 +-
 .../apache/drill/common/logical/data/Project.java  |   24 +-
 .../org/apache/drill/common/logical/data/Scan.java |   17 +-
 .../apache/drill/common/logical/data/Sequence.java |    1 -
 .../apache/drill/common/logical/data/Write.java    |   39 +
 .../drill/common/logical/graph/AdjacencyList.java  |   70 +-
 .../drill/common/logical/graph/GraphAlgos.java     |    8 +-
 .../apache/drill/common/logical/graph/Node.java    |    1 +
 .../drill/common/logical/sources/DataSource.java   |    2 +-
 .../logical/sources/FileBasedDataSource.java       |   31 +
 .../common/logical/sources/JSONDataSource.java     |   24 +
 .../apache/drill/common/logical/sources/Text.java  |    6 +-
 .../src/main/java/org/apache/drill/App.java        |   13 -
 .../src/test/java/org/apache/drill/AppTest.java    |   38 -
 .../src/main/java/org/apache/drill/App.java        |   13 -
 .../src/test/java/org/apache/drill/AppTest.java    |   38 -
 sandbox/prototype/exec/pom.xml                     |    1 +
 sandbox/prototype/exec/ref/pom.xml                 |   64 ++
 .../apache/drill/exec/ref/BasicStatusHandle.java   |   44 +
 .../apache/drill/exec/ref/IteratorRegistry.java    |   70 ++
 .../org/apache/drill/exec/ref/ROPConverter.java    |  151 ++++
 .../org/apache/drill/exec/ref/RecordIterator.java  |   50 ++
 .../org/apache/drill/exec/ref/RecordPointer.java   |   19 +
 .../drill/exec/ref/ReferenceInterpreter.java       |  115 +++
 .../apache/drill/exec/ref/ReferenceTransform.java  |   17 +
 .../java/org/apache/drill/exec/ref/RunOutcome.java |   52 ++
 .../org/apache/drill/exec/ref/UnbackedRecord.java  |   99 +++
 .../drill/exec/ref/eval/BaseBasicEvaluator.java    |   42 +
 .../drill/exec/ref/eval/BasicEvaluatorFactory.java |  105 +++
 .../drill/exec/ref/eval/BoundarySubscriber.java    |   22 +
 .../drill/exec/ref/eval/EvaluatorFactory.java      |   59 ++
 .../apache/drill/exec/ref/eval/EvaluatorTypes.java |   58 ++
 .../apache/drill/exec/ref/eval/FieldEvaluator.java |   46 ++
 .../apache/drill/exec/ref/eval/IfEvaluator.java    |   81 ++
 .../exec/ref/eval/SimpleEvaluationVisitor.java     |  139 ++++
 .../exec/ref/eval/fn/ComparisonEvaluators.java     |  133 ++++
 .../drill/exec/ref/eval/fn/FunctionArguments.java  |   87 ++
 .../drill/exec/ref/eval/fn/FunctionEvaluator.java  |   26 +
 .../ref/eval/fn/FunctionEvaluatorRegistry.java     |  110 +++
 .../drill/exec/ref/eval/fn/MathEvaluators.java     |  105 +++
 .../drill/exec/ref/eval/fn/StringEvaluators.java   |   52 ++
 .../eval/fn/agg/AggregatingWrapperEvaluator.java   |   54 ++
 .../exec/ref/eval/fn/agg/CountAggregator.java      |   75 ++
 .../drill/exec/ref/eval/fn/agg/SumAggregator.java  |  103 +++
 .../drill/exec/ref/exceptions/MajorException.java  |   46 ++
 .../drill/exec/ref/exceptions/RecordException.java |   48 ++
 .../drill/exec/ref/exceptions/SetupException.java  |   46 ++
 .../exec/ref/rops/AbstractBlockingOperator.java    |   66 ++
 .../drill/exec/ref/rops/AggregateSimpleROP.java    |  219 ++++++
 .../apache/drill/exec/ref/rops/BaseSinkROP.java    |  107 +++
 .../drill/exec/ref/rops/BoundaryListener.java      |   25 +
 .../org/apache/drill/exec/ref/rops/DataWriter.java |   45 ++
 .../org/apache/drill/exec/ref/rops/FilterROP.java  |   81 ++
 .../org/apache/drill/exec/ref/rops/GroupROP.java   |   75 ++
 .../apache/drill/exec/ref/rops/JSONDataWriter.java |  140 ++++
 .../apache/drill/exec/ref/rops/JSONScanner.java    |  183 +++++
 .../org/apache/drill/exec/ref/rops/JSONWriter.java |   62 ++
 .../apache/drill/exec/ref/rops/MultiLevelMap.java  |  200 +++++
 .../org/apache/drill/exec/ref/rops/OrderROP.java   |  165 ++++
 .../org/apache/drill/exec/ref/rops/ProjectROP.java |   95 +++
 .../drill/exec/ref/rops/ProxySimpleRecord.java     |   74 ++
 .../java/org/apache/drill/exec/ref/rops/ROP.java   |   12 +
 .../org/apache/drill/exec/ref/rops/ROPBase.java    |   62 ++
 .../drill/exec/ref/rops/ReferenceOperator.java     |    9 +
 .../drill/exec/ref/rops/ReferenceOperatorBase.java |   39 +
 .../drill/exec/ref/rops/SingleInputROPBase.java    |   49 ++
 .../org/apache/drill/exec/ref/rops/SinkROP.java    |   30 +
 .../apache/drill/exec/ref/rops/TransformROP.java   |   89 +++
 .../org/apache/drill/exec/ref/rops/UnionROP.java   |   82 ++
 .../apache/drill/exec/ref/rops/WindowingROP.java   |   56 ++
 .../apache/drill/exec/ref/util/BatchBreaker.java   |   29 +
 .../org/apache/drill/exec/ref/util/ByteRange.java  |   17 +
 .../drill/exec/ref/values/BaseArrayValue.java      |   72 ++
 .../drill/exec/ref/values/BaseDataValue.java       |   66 ++
 .../apache/drill/exec/ref/values/BaseMapValue.java |   90 +++
 .../apache/drill/exec/ref/values/BooleanValue.java |   22 +
 .../apache/drill/exec/ref/values/BytesValue.java   |   28 +
 .../drill/exec/ref/values/ComparableValue.java     |   38 +
 .../drill/exec/ref/values/ContainerValue.java      |   25 +
 .../apache/drill/exec/ref/values/DataValue.java    |   25 +
 .../apache/drill/exec/ref/values/NumericValue.java |  174 +++++
 .../apache/drill/exec/ref/values/ScalarValues.java |  507 ++++++++++++
 .../drill/exec/ref/values/SimpleArrayValue.java    |  143 ++++
 .../drill/exec/ref/values/SimpleMapValue.java      |   97 +++
 .../apache/drill/exec/ref/values/StringValue.java  |   22 +
 .../apache/drill/exec/ref/values/ValueReader.java  |   60 ++
 .../apache/drill/exec/ref/values/ValueUtils.java   |   78 ++
 .../exec/ref/src/main/resources/logback-test.xml   |   33 +
 .../exec/ref/src/test/resources/donuts.json        |  129 +++
 .../exec/ref/src/test/resources/simple_plan.json   |   76 ++
 .../src/main/java/org/apache/drill/App.java        |   13 -
 .../src/test/java/org/apache/drill/AppTest.java    |   38 -
 sandbox/prototype/pom.xml                          |    6 +
 .../src/main/java/org/apache/drill/App.java        |   13 -
 .../src/test/java/org/apache/drill/AppTest.java    |   38 -
 158 files changed, 9222 insertions(+), 1121 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/pom.xml b/sandbox/prototype/common/pom.xml
index 531c08e..82c2993 100644
--- a/sandbox/prototype/common/pom.xml
+++ b/sandbox/prototype/common/pom.xml
@@ -17,6 +17,25 @@
 	</properties>
 	<dependencies>
 
+<!-- 		<dependency> -->
+<!-- 			<groupId>net.hydromatic</groupId> -->
+<!-- 			<artifactId>optiq</artifactId> -->
+<!-- 			<version>0.1-SNAPSHOT</version> -->
+<!-- 		</dependency> -->
+
+
+		<dependency>
+			<groupId>com.google.protobuf</groupId>
+			<artifactId>protobuf-java</artifactId>
+			<version>2.4.1</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.hadoop</groupId>
+			<artifactId>hadoop-core</artifactId>
+			<version>1.1.0</version>
+		</dependency>
+
 		<dependency>
 			<groupId>ch.qos.logback</groupId>
 			<artifactId>logback-classic</artifactId>
@@ -28,6 +47,17 @@
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-api</artifactId>
 		</dependency>
+
+		<dependency>
+			<groupId>org.msgpack</groupId>
+			<artifactId>msgpack</artifactId>
+			<version>0.6.6</version>
+		</dependency>
+		<dependency>
+			<groupId>org.reflections</groupId>
+			<artifactId>reflections</artifactId>
+			<version>0.9.8</version>
+		</dependency>
 		<dependency>
 			<groupId>com.google.guava</groupId>
 			<artifactId>guava</artifactId>
@@ -64,6 +94,9 @@
 				<groupId>org.antlr</groupId>
 				<artifactId>antlr3-maven-plugin</artifactId>
 				<version>3.4</version>
+				<configuration>
+
+				</configuration>
 				<executions>
 					<execution>
 						<goals>

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g b/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
index 889243e..cb59791 100644
--- a/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
+++ b/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/expression/parser/ExprParser.g
@@ -28,12 +28,14 @@ options{
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-  package org.apache.drill.common.expression.parser;
+
+package org.apache.drill.common.expression.parser;
   
-  //Explicit import...
-  import org.antlr.runtime.BitSet;
-  import java.util.*;
-  import org.apache.drill.common.expression.*;
+//Explicit import...
+import org.antlr.runtime.BitSet;
+import java.util.*;
+import org.apache.drill.common.expression.*;
+
 }
 
 @members{
@@ -47,7 +49,7 @@ parse returns [LogicalExpression e]
   ;
  
 functionCall returns [LogicalExpression e]
-  :  Identifier OParen exprList? CParen {$e = ExpressionFunction.create($Identifier.text, $exprList.listE);  }
+  :  Identifier OParen exprList? CParen {$e = FunctionRegistry.createExpression($Identifier.text, $exprList.listE);  }
   ;
 
 ifStatement returns [LogicalExpression e]
@@ -110,7 +112,7 @@ orExpr returns [LogicalExpression e]
 	  if(exprs.size() == 1){
 	    $e = exprs.get(0);
 	  }else{
-	    $e = new BooleanFunctions.Or(exprs);
+	    $e = FunctionRegistry.createExpression("||", exprs);
 	  }
 	}
   :  a1=andExpr { exprs.add($a1.e); } (Or^ a2=andExpr { exprs.add($a2.e); })*
@@ -124,7 +126,7 @@ andExpr returns [LogicalExpression e]
 	  if(exprs.size() == 1){
 	    $e = exprs.get(0);
 	  }else{
-	    $e = new BooleanFunctions.And(exprs);
+	    $e = FunctionRegistry.createExpression("&&", exprs);
 	  }
 	}
   :  e1=equExpr { exprs.add($e1.e);  } (And^ e2=equExpr { exprs.add($e2.e);  })*
@@ -136,13 +138,13 @@ equExpr returns [LogicalExpression e]
 	  List<String> cmps = new ArrayList();
 	}
 	@after{
-	  $e = BooleanFunctions.Comparison.create(exprs, cmps);
+	  $e = FunctionRegistry.createByOp(exprs, cmps);
 	}
   :  r1=relExpr {exprs.add($r1.e);} ( cmpr= (Equals | NEquals ) r2=relExpr {exprs.add($r2.e); cmps.add($cmpr.text); })*
   ;
 
 relExpr returns [LogicalExpression e]
-  :  left=addExpr {$e = $left.e; } (cmpr = (GTEquals | LTEquals | GT | LT) right=addExpr {$e = new BooleanFunctions.Comparison($cmpr.text, $left.e, $right.e); } )? 
+  :  left=addExpr {$e = $left.e; } (cmpr = (GTEquals | LTEquals | GT | LT) right=addExpr {$e = FunctionRegistry.createExpression($cmpr.text, $left.e, $right.e); } )? 
   ;
 
 addExpr returns [LogicalExpression e]
@@ -151,7 +153,7 @@ addExpr returns [LogicalExpression e]
 	  List<String> ops = new ArrayList();
 	}
 	@after{
-	  $e = MathFunction.create(exprs, ops);
+	  $e = FunctionRegistry.createByOp(exprs, ops);
 	}
   :  m1=mulExpr  {exprs.add($m1.e);} ( op=(Plus|Minus) m2=mulExpr {exprs.add($m2.e); ops.add($op.text); })* 
   ;
@@ -162,7 +164,7 @@ mulExpr returns [LogicalExpression e]
 	  List<String> ops = new ArrayList();
 	}
 	@after{
-	  $e = MathFunction.create(exprs, ops);
+	  $e = FunctionRegistry.createByOp(exprs, ops);
 	}
   :  p1=powExpr  {exprs.add($p1.e);} (op=(Asterisk|ForwardSlash|Percent) p2=powExpr {exprs.add($p2.e); ops.add($op.text); } )*
   ;
@@ -173,19 +175,19 @@ powExpr returns [LogicalExpression e]
 	  List<String> ops = new ArrayList();
 	}
 	@after{
-	  $e = MathFunction.create(exprs, ops);
+	  $e = FunctionRegistry.createByOp(exprs, ops);
 	}
   :  u1=unaryExpr {exprs.add($u1.e);} (Caret u2=unaryExpr {exprs.add($u2.e); ops.add($Caret.text);} )*
   ;
   
 unaryExpr returns [LogicalExpression e]
-  :  Minus atom {$e = new UnaryFunctions.Negative($atom.e); }
-  |  Excl atom {$e= new UnaryFunctions.Not($atom.e); }
+  :  Minus atom {$e = FunctionRegistry.createExpression("u-", $atom.e); }
+  |  Excl atom {$e= FunctionRegistry.createExpression("!", $atom.e); }
   |  atom {$e = $atom.e; }
   ;
 
 atom returns [LogicalExpression e]
-  :  Number {$e = new ValueExpressions.NumberExpression($Number.text); }
+  :  Number {$e = ValueExpressions.getNumericExpression($Number.text); }
   |  Bool {$e = new ValueExpressions.BooleanExpression( $Bool.text ); }
   |  lookup {$e = $lookup.e; }
   ;
@@ -193,8 +195,8 @@ atom returns [LogicalExpression e]
 
 lookup returns [LogicalExpression e]
   :  functionCall {$e = $functionCall.e ;}
-  | Identifier {$e = new ValueExpressions.Identifier($Identifier.text); }
+  | Identifier {$e = new SchemaPath($Identifier.text); }
   | String {$e = new ValueExpressions.QuotedString($String.text); }
   | OParen expression CParen  {$e = $expression.e; }
-  | SingleQuote Identifier SingleQuote {$e = new ValueExpressions.Identifier($Identifier.text); }
+  | SingleQuote Identifier SingleQuote {$e = new SchemaPath($Identifier.text); }
   ;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoLexer.g.bk
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoLexer.g.bk b/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoLexer.g.bk
new file mode 100644
index 0000000..81b3e03
--- /dev/null
+++ b/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoLexer.g.bk
@@ -0,0 +1,287 @@
+//========================================================================
+//Copyright 2007-2009 David Yu dyuproject@gmail.com
+//------------------------------------------------------------------------
+//Licensed 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.
+//========================================================================
+
+/** Apache Drill notes: Based off r1586 of protostuff **/
+
+lexer grammar ProtoLexer;
+
+options {
+   language=Java;  // Default
+}
+
+@header {
+    package org.apache.drill.common.storage.proto;
+}
+    
+ASSIGN
+    :   '='
+    ;
+    
+AT
+    :   '@'
+    ;
+    
+LEFTCURLY
+    :   '{'
+    ;
+    
+RIGHTCURLY
+    :   '}'
+    ;
+    
+LEFTPAREN
+    :   '('
+    ;
+    
+RIGHTPAREN
+    :   ')'
+    ;
+    
+LEFTSQUARE
+    :   '['
+    ;
+    
+RIGHTSQUARE
+    :   ']'
+    ;
+
+SEMICOLON
+    :   ';'
+    ;
+    
+COMMA
+    :   ','
+    ;
+    
+PLUS
+    :   '+'
+    ;
+    
+MINUS
+    :   '-'
+    ;
+    
+TO
+    :   'to'
+    ;
+
+TRUE
+    :   'true'
+    ;
+    
+FALSE
+    :   'false'
+    ;
+    
+PKG 
+    :   'package'
+    ;
+
+SYNTAX
+    :   'syntax'
+    ;
+    
+IMPORT
+    :   'import'
+    ;
+    
+OPTION
+    :   'option'
+    ;
+    
+MESSAGE
+    :   'message'
+    ;
+
+SERVICE
+    :   'service'
+    ;
+    
+ENUM
+    :   'enum'
+    ;
+
+REQUIRED
+    :   'required'
+    ;
+    
+OPTIONAL
+    :   'optional'
+    ;
+
+REPEATED
+    :   'repeated'
+    ;
+    
+EXTENSIONS
+    :   'extensions'
+    ;
+    
+EXTEND
+    :   'extend'
+    ;
+    
+GROUP
+    :   'group'
+    ;
+    
+RPC
+    :   'rpc'
+    ;
+    
+RETURNS
+    :   'returns'
+    ;
+    
+INT32
+    :   'int32'
+    ;
+    
+INT64
+    :   'int64'
+    ;
+    
+UINT32
+    :   'uint32'
+    ;
+    
+UINT64
+    :   'uint64'
+    ;
+    
+SINT32
+    :   'sint32'
+    ;
+    
+SINT64
+    :   'sint64'
+    ;
+    
+FIXED32
+    :   'fixed32'
+    ;
+    
+FIXED64
+    :   'fixed64'
+    ;
+    
+SFIXED32
+    :   'sfixed32'
+    ;
+    
+SFIXED64
+    :   'sfixed64'
+    ;
+    
+FLOAT
+    :   'float'
+    ;
+    
+DOUBLE
+    :   'double'
+    ;
+    
+BOOL
+    :   'bool'
+    ;
+    
+STRING
+    :   'string'
+    ;
+    
+BYTES
+    :   'bytes'
+    ;
+    
+DEFAULT
+    :   'default'
+    ;
+
+MAX
+    :   'max'
+    ;    
+
+VOID
+    :   'void'
+    ;
+
+FULL_ID
+    : ID ('.' ID)+
+    ;
+
+ID  
+    :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
+    ;
+    
+EXP
+    :   NUMINT ('e'|'E') NUMINT
+    ;
+    
+NUMDOUBLE
+    :   (NUMFLOAT|NUMINT)
+        'e' '0'..'9'+
+    ;
+
+NUMFLOAT
+    :   NUMINT '.' '0'..'9'+ 'f'?
+    ;
+ 
+NUMINT
+    :   '0' | MINUS? '1'..'9' '0'..'9'*
+    ;
+    
+HEX
+    :   MINUS? '0' ('x'|'X') HEX_DIGIT+
+    ;
+    
+OCTAL
+    :   '0' ('0'..'7')+
+    ;
+    
+COMMENT
+    :   '//' ~('\n'|'\r')* '\r'? '\n' {skip();}
+    |   '/*' ( options {greedy=false;} : . )* '*/' {skip();}
+    ;
+
+WS  :   ( ' '
+        | '\t'
+        | '\r'
+        | '\n'
+        ) {skip();}
+    ;
+    
+STRING_LITERAL
+    :   '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
+    ;
+
+fragment HEX_DIGIT
+    :   ('0'..'9'|'a'..'f'|'A'..'F')
+    ;
+
+fragment ESC_SEQ
+    :   '\\' ('a'|'v'|'b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
+    |   '\\' ('x'|'X') HEX_DIGIT HEX_DIGIT
+    |   UNICODE_ESC
+    |   OCTAL_ESC
+    ;
+
+fragment OCTAL_ESC
+    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7')
+    ;
+
+fragment UNICODE_ESC
+    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+    ;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoParser.g.bk
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoParser.g.bk b/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoParser.g.bk
new file mode 100644
index 0000000..81b6eb6
--- /dev/null
+++ b/sandbox/prototype/common/src/main/antlr3/org/apache/drill/common/storage/proto/ProtoParser.g.bk
@@ -0,0 +1,605 @@
+//========================================================================
+//Copyright 2007-2009 David Yu dyuproject@gmail.com
+//------------------------------------------------------------------------
+//Licensed 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.
+//========================================================================
+
+/** Apache Drill notes: Based off r1586 of protostuff **/
+
+parser grammar ProtoParser;
+
+options {
+    language  = Java;
+    output    = AST;
+    tokenVocab = ProtoLexer;
+}
+
+@header {
+    package org.apache.drill.common.storage.proto;
+}
+
+parse [Proto proto]
+    :   (statement[proto])+ EOF! {
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+            
+            proto.postParse();
+        }
+    ;
+    
+statement [Proto proto]
+    :   header_syntax[proto]
+    |   header_package[proto]
+    |   header_import[proto]
+    |   message_block[proto, null]
+    |   enum_block[proto, null]
+    |   extend_block[proto, null]
+    |   service_block[proto]
+    |   annotation_entry[proto]
+    |   option_entry[proto, proto]
+    ;
+
+// some keywords that might possibly be used as a variable
+var
+    :   ID | TO | PKG | SYNTAX | IMPORT | OPTION | MESSAGE | SERVICE | ENUM |  
+        REQUIRED | OPTIONAL | REPEATED | EXTENSIONS | EXTEND | GROUP | RPC | 
+        RETURNS | INT32 | INT64 | UINT32 | UINT64 | SINT32 | SINT64 | 
+        FIXED32 | FIXED64 | SFIXED32 | SFIXED64 | FLOAT | DOUBLE | BOOL | 
+        STRING | BYTES | DEFAULT | MAX | VOID
+    ;
+
+annotation_entry [Proto proto]
+@init {
+    Annotation annotation = null;
+}
+    :   AT var { annotation = new Annotation($var.text); }
+        (LEFTPAREN 
+        annotation_keyval[proto, annotation] (COMMA annotation_keyval[proto, annotation])* 
+        RIGHTPAREN)? {
+            proto.add(annotation);
+        }
+    ;
+
+annotation_keyval [Proto proto, Annotation annotation]
+    :   k=var ASSIGN (
+                ID { annotation.putRef($k.text, $ID.text); }
+            |   fid=FULL_ID { annotation.putRef($k.text, $fid.text); }
+            |   NUMFLOAT { annotation.put($k.text, Float.valueOf($NUMFLOAT.text)); }
+            |   NUMINT { annotation.put($k.text, Integer.valueOf($NUMINT.text)); }
+            |   NUMDOUBLE { annotation.put($k.text, Double.valueOf($NUMDOUBLE.text)); }
+            |   TRUE { annotation.put($k.text, Boolean.TRUE); }
+            |   FALSE { annotation.put($k.text, Boolean.FALSE); }
+            |   STRING_LITERAL { annotation.put($k.text, getStringFromStringLiteral($STRING_LITERAL.text)); }
+            |   v=var { annotation.put($k.text, $v.text); }
+        )
+    ;
+
+header_syntax [Proto proto]
+    :   SYNTAX ASSIGN STRING_LITERAL SEMICOLON! {
+            if(!"proto2".equals(getStringFromStringLiteral($STRING_LITERAL.text))) {
+                throw new IllegalStateException("Syntax isn't proto2: '" +
+                  getStringFromStringLiteral($STRING_LITERAL.text)+"'");
+            }
+                  
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+        }
+    ;
+
+header_package [Proto proto] // ignore
+    :   PKG (FULL_ID  | var ) SEMICOLON! 
+    ;
+    
+header_import [Proto proto]
+    :   IMPORT STRING_LITERAL SEMICOLON! {
+            proto.importProto(getStringFromStringLiteral($STRING_LITERAL.text));
+            
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+        }
+    ;
+
+option_entry [Proto proto, HasOptions ho]
+    :   OPTION LEFTPAREN? k=(ID|FULL_ID) RIGHTPAREN? ASSIGN (
+                id=ID { ho.putStandardOption($k.text, $id.text); }
+            |   fid=FULL_ID { ho.putStandardOption($k.text, $fid.text); }
+            |   NUMFLOAT { ho.putExtraOption($k.text, Float.valueOf($NUMFLOAT.text)); }
+            |   NUMINT { ho.putExtraOption($k.text, Integer.valueOf($NUMINT.text)); }
+            |   NUMDOUBLE { ho.putExtraOption($k.text, Double.valueOf($NUMDOUBLE.text)); }
+            |   TRUE { ho.putExtraOption($k.text, Boolean.TRUE); }
+            |   FALSE { ho.putExtraOption($k.text, Boolean.FALSE); }
+            |   STRING_LITERAL { ho.putExtraOption($k.text, getStringFromStringLiteral($STRING_LITERAL.text)); }
+        ) SEMICOLON! {
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+        }
+    ;
+    
+message_block [Proto proto, Message parent]
+@init {
+    Message message = null;
+}
+    :   MESSAGE ID { 
+            message = new Message($ID.text);
+            if(parent==null)
+                proto.addMessage(message);
+            else
+                parent.addNestedMessage(message);
+                
+            proto.addAnnotationsTo(message);
+        } 
+        LEFTCURLY (message_body[proto, message])* RIGHTCURLY {
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+        }
+    ;
+
+message_body [Proto proto, Message message]
+    :   message_block[proto, message]
+    |   message_field[proto, message]
+    |   enum_block[proto, message]
+    |   extend_block[proto, message]
+    |   extensions_range[proto, message]
+    |   annotation_entry[proto]
+    |   option_entry[proto, message]
+    ;
+    
+extensions_range [Proto proto, Message message]
+@init {
+  int first = -1;
+  int last = -1;
+}
+    :   EXTENSIONS f=NUMINT { first = Integer.parseInt($f.text); last = first;}
+        ( TO ( l=NUMINT { last = Integer.parseInt($l.text); } | MAX {last = 536870911; } ) )?
+        SEMICOLON! {
+            message.defineExtensionRange(first, last);
+        }
+    ;
+    
+message_field [Proto proto, HasFields message]
+@init {
+    Field.Modifier modifier = null;
+    FieldHolder fieldHolder = null;
+}
+    :   (OPTIONAL { modifier = Field.Modifier.OPTIONAL;  } 
+        |   REQUIRED { modifier = Field.Modifier.REQUIRED; } 
+        |   REPEATED { modifier = Field.Modifier.REPEATED; }) {
+            fieldHolder = new FieldHolder();
+        }
+        field_type[proto, message, fieldHolder] 
+        var ASSIGN NUMINT {
+            if(fieldHolder.field != null) {
+                fieldHolder.field.modifier = modifier;
+                fieldHolder.field.name = $var.text;
+                fieldHolder.field.number = Integer.parseInt($NUMINT.text);
+            }
+        } 
+        (field_options[proto, message, fieldHolder.field])? {
+            if(fieldHolder.field != null) {
+                proto.addAnnotationsTo(fieldHolder.field, message.getEnclosingNamespace());
+                message.addField(fieldHolder.field);
+            }
+        }
+        (SEMICOLON! | ignore_block)
+    ;
+    
+field_type [Proto proto, HasFields message, FieldHolder fieldHolder]
+    :   INT32 { fieldHolder.setField(new Field.Int32()); }
+    |   UINT32 { fieldHolder.setField(new Field.UInt32()); }
+    |   SINT32 { fieldHolder.setField(new Field.SInt32()); }
+    |   FIXED32 { fieldHolder.setField(new Field.Fixed32()); }
+    |   SFIXED32 { fieldHolder.setField(new Field.SFixed32()); }
+    |   INT64 { fieldHolder.setField(new Field.Int64()); }
+    |   UINT64 { fieldHolder.setField(new Field.UInt64()); }
+    |   SINT64 { fieldHolder.setField(new Field.SInt64()); }
+    |   FIXED64 { fieldHolder.setField(new Field.Fixed64()); }
+    |   SFIXED64 { fieldHolder.setField(new Field.SFixed64()); }
+    |   FLOAT { fieldHolder.setField(new Field.Float()); }
+    |   DOUBLE { fieldHolder.setField(new Field.Double()); }
+    |   BOOL { fieldHolder.setField(new Field.Bool()); }
+    |   STRING { fieldHolder.setField(new Field.String()); }
+    |   BYTES { fieldHolder.setField(new Field.Bytes()); }
+    |   GROUP {
+            String suffix = proto.getFile()==null ? "" : " of " + proto.getFile().getName();
+            warn("'group' not supported @ line " + $GROUP.line + suffix);
+        }
+    |   FULL_ID {
+            String fullType = $FULL_ID.text;
+            int lastDot = fullType.lastIndexOf('.');
+            String packageName = fullType.substring(0, lastDot); 
+            String type = fullType.substring(lastDot+1);
+            fieldHolder.setField(new Field.Reference(packageName, type, message));
+        }
+    |   ID { 
+            String type = $ID.text;
+            fieldHolder.setField(new Field.Reference(null, type, message));
+        }
+    ;
+    
+field_options [Proto proto, HasFields message, Field field]
+    :   LEFTSQUARE field_options_keyval[proto, message, field] 
+        (COMMA field_options_keyval[proto, message, field])* RIGHTSQUARE
+    ;
+    
+field_options_keyval [Proto proto, HasFields message, Field field]
+    :   key=(DEFAULT|ID) ASSIGN (STRING_LITERAL {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.String)
+                    field.defaultValue = getStringFromStringLiteral($STRING_LITERAL.text);
+                else if(field instanceof Field.Bytes)
+                    field.defaultValue = getBytesFromStringLiteral($STRING_LITERAL.text);
+                else
+                    throw new IllegalStateException("Invalid string default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, getStringFromStringLiteral($STRING_LITERAL.text));
+        } 
+    |   NUMFLOAT {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.Float)
+                    field.defaultValue = Float.valueOf($NUMFLOAT.text);
+                else if(field instanceof Field.Double) 
+                    field.defaultValue = Double.valueOf($NUMFLOAT.text);
+                else
+                    throw new IllegalStateException("Invalid float default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, Float.valueOf($NUMFLOAT.text));
+        } 
+    |   NUMINT {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.Number) {
+                    if(field.getClass().getSimpleName().endsWith("32"))
+                        field.defaultValue = Integer.valueOf($NUMINT.text);
+                    else if(field.getClass().getSimpleName().endsWith("64"))
+                        field.defaultValue = Long.valueOf($NUMINT.text);
+                    else if(field instanceof Field.Float)
+                        field.defaultValue = Float.valueOf($NUMINT.text);
+                    else if(field instanceof Field.Double) 
+                        field.defaultValue = Double.valueOf($NUMINT.text);
+                    else
+                        throw new IllegalStateException("Invalid numeric default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+                }
+                else
+                    throw new IllegalStateException("Invalid numeric default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, Integer.valueOf($NUMINT.text));
+        }
+    |   NUMDOUBLE {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+
+                if(field instanceof Field.Float)
+                    field.defaultValue = Float.valueOf($NUMDOUBLE.text);
+                else if(field instanceof Field.Double) 
+                    field.defaultValue = Double.valueOf($NUMDOUBLE.text);
+                else
+                    throw new IllegalStateException("Invalid numeric default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, Double.valueOf($NUMDOUBLE.text));
+        }
+    |   HEX {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.Number) {
+                    if(field instanceof Field.Int32)
+                        field.defaultValue = new Integer(TextFormat.parseInt32($HEX.text));
+                    else if(field instanceof Field.UInt32)
+                        field.defaultValue = new Integer(TextFormat.parseUInt32($HEX.text));
+                    else if(field instanceof Field.Int64)
+                        field.defaultValue = new Long(TextFormat.parseInt64($HEX.text));
+                    else if(field instanceof Field.UInt64)
+                        field.defaultValue = new Long(TextFormat.parseUInt64($HEX.text));
+                    else if(field instanceof Field.Float)
+                        field.defaultValue = new Float(Long.decode($HEX.text).floatValue());
+                    else if(field instanceof Field.Double) 
+                        field.defaultValue = new Double(Long.decode($HEX.text).doubleValue());
+                }
+                else if(field instanceof Field.Bytes) {
+                    field.defaultValue = getBytesFromHexString($HEX.text);
+                }
+                else
+                    throw new IllegalStateException("Invalid numeric default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+                
+            }
+            
+            field.putExtraOption($key.text, $HEX.text);
+        }
+    |   OCTAL {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.Number) {
+                    if(field instanceof Field.Int32)
+                        field.defaultValue = new Integer(TextFormat.parseInt32($OCTAL.text));
+                    else if(field instanceof Field.UInt32)
+                        field.defaultValue = new Integer(TextFormat.parseUInt32($OCTAL.text));
+                    else if(field instanceof Field.Int64)
+                        field.defaultValue = new Long(TextFormat.parseInt64($OCTAL.text));
+                    else if(field instanceof Field.UInt64)
+                        field.defaultValue = new Long(TextFormat.parseUInt64($OCTAL.text));
+                    else if(field instanceof Field.Float)
+                        field.defaultValue = new Float(Long.decode($OCTAL.text).floatValue());
+                    else if(field instanceof Field.Double) 
+                        field.defaultValue = new Double(Long.decode($OCTAL.text).doubleValue());
+                }
+                else
+                    throw new IllegalStateException("Invalid numeric default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, $OCTAL.text);
+        }
+    |   TRUE {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.Bool)
+                    field.defaultValue = Boolean.TRUE;
+                else
+                    throw new IllegalStateException("invalid boolean default value for the non-boolean field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, Boolean.TRUE);
+        }    
+    |   FALSE {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.Bool)
+                    field.defaultValue = Boolean.FALSE;
+                else
+                    throw new IllegalStateException("invalid boolean default value for the non-boolean field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, Boolean.FALSE);
+        }
+    |   val=ID {
+            boolean refOption = false;
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                String refName = $val.text;
+                if(field instanceof Field.Reference)
+                    field.defaultValue = refName;
+                else if(field instanceof Field.Float) {
+                    if("inf".equals(refName)) {
+                        field.defaultValue = Float.POSITIVE_INFINITY;
+                        field.defaultValueConstant = "Float.POSITIVE_INFINITY";
+                    }
+                    else if("nan".equals(refName)) {
+                        field.defaultValue = Float.NaN;
+                        field.defaultValueConstant = "Float.NaN";
+                    }
+                    else
+                        throw new IllegalStateException("Invalid float default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+                }
+                else if(field instanceof Field.Double) {
+                    if("inf".equals(refName)) {
+                        field.defaultValue = Double.POSITIVE_INFINITY;
+                        field.defaultValueConstant = "Double.POSITIVE_INFINITY";
+                    }
+                    else if("nan".equals(refName)) {
+                        field.defaultValue = Double.NaN;
+                        field.defaultValueConstant = "Double.NaN";
+                    }
+                    else
+                        throw new IllegalStateException("Invalid double default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+                }   
+                else {
+                    refOption = true;
+                    //throw new IllegalStateException("invalid field value '" + refName + "' for the field: " + field.getClass().getSimpleName() + " " + field.name);
+                }
+            }
+            else {
+                refOption = true;
+            }
+            
+            if(refOption)
+                field.putStandardOption($key.text, $val.text);
+            else
+                field.putExtraOption($key.text, $val.text);
+        }
+    |   FULL_ID {
+            field.putStandardOption($key.text, $FULL_ID.text);
+        }
+    |   EXP {
+            if("default".equals($key.text)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                if(field instanceof Field.Float)
+                    field.defaultValue = Float.valueOf($EXP.text);
+                else if(field instanceof Field.Double) 
+                    field.defaultValue = Double.valueOf($EXP.text);
+                else
+                    throw new IllegalStateException("Invalid float default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+            
+            field.putExtraOption($key.text, $EXP.text);
+        }
+    |   signed_constant[proto, message, field, $key.text] {
+            field.putExtraOption($key.text, $signed_constant.text);
+        }
+        )
+    ;
+    
+signed_constant [Proto proto, HasFields message, Field field, String key]
+    :   MINUS ID {
+            if("default".equals(key)) {
+                if(field.defaultValue!=null || field.modifier == Field.Modifier.REPEATED)
+                    throw new IllegalStateException("a field can only have a single default value");
+                
+                String refName = $ID.text;
+                if(field instanceof Field.Float) {
+                    if("inf".equals(refName)) {
+                        field.defaultValue = Float.NEGATIVE_INFINITY;
+                        field.defaultValueConstant = "Float.NEGATIVE_INFINITY";
+                    }
+                    else
+                        throw new IllegalStateException("Invalid float default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+                }
+                else if(field instanceof Field.Double) {
+                    if("inf".equals(refName)) {
+                        field.defaultValue = Double.NEGATIVE_INFINITY;
+                        field.defaultValueConstant = "Double.NEGATIVE_INFINITY";
+                    }
+                    else
+                        throw new IllegalStateException("Invalid double default value for the field: " + field.getClass().getSimpleName() + " " + field.name);
+                }   
+                else
+                    throw new IllegalStateException("invalid field value '" + refName + "' for the field: " + field.getClass().getSimpleName() + " " + field.name);
+            }
+        }
+    ;
+    
+enum_block [Proto proto, Message message]
+@init {
+    EnumGroup enumGroup = null;
+}
+    :   ENUM ID { 
+            enumGroup = new EnumGroup($ID.text); 
+            if(message==null)
+                proto.addEnumGroup(enumGroup);
+            else
+                message.addNestedEnumGroup(enumGroup);
+            
+            proto.addAnnotationsTo(enumGroup);
+        } 
+        LEFTCURLY (enum_body[proto, message, enumGroup])* RIGHTCURLY {
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+        } (SEMICOLON?)!
+    ;
+    
+enum_body [Proto proto, Message message, EnumGroup enumGroup]
+    :   enum_field[proto, message, enumGroup]
+    |   annotation_entry[proto]
+    |   option_entry[proto, enumGroup]
+    ;
+
+enum_field [Proto proto, Message message, EnumGroup enumGroup]
+    :   ID ASSIGN NUMINT SEMICOLON! {
+            EnumGroup.Value v = new EnumGroup.Value($ID.text, Integer.parseInt($NUMINT.text));
+            enumGroup.add(v);
+            proto.addAnnotationsTo(v);
+        }
+    ;
+    
+service_block [Proto proto]
+@init {
+    Service service = null;
+}
+    :   SERVICE ID { 
+            service = new Service($ID.text, proto); 
+            proto.addAnnotationsTo(service);
+        } LEFTCURLY
+        (service_body[proto, service])+ RIGHTCURLY (SEMICOLON?)! {
+            if(service.rpcMethods.isEmpty())
+                throw new IllegalStateException("Empty Service block: " + service.getName());
+                
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+        }
+    ;
+    
+service_body [Proto proto, Service service]
+    :   rpc_block[proto, service]
+    |   annotation_entry[proto]
+    |   option_entry[proto, service]
+    ;
+    
+rpc_block [Proto proto, Service service]
+@init {
+    String argName = null, argPackage = null, retName = null, retPackage = null;
+    Service.RpcMethod rm = null;
+}
+    :   RPC n=ID LEFTPAREN (ap=FULL_ID {  
+            String argFull = $ap.text;
+            int lastDot = argFull.lastIndexOf('.');
+            argPackage = argFull.substring(0, lastDot); 
+            argName = argFull.substring(lastDot+1);
+        } | a=(VOID|ID) { argName = $a.text; }) RIGHTPAREN 
+        RETURNS LEFTPAREN (rp=FULL_ID {  
+            String retFull = $rp.text;
+            int lastDot = retFull.lastIndexOf('.');
+            retPackage = retFull.substring(0, lastDot); 
+            retName = retFull.substring(lastDot+1);
+        } | r=(VOID|ID) { retName = $r.text; }) RIGHTPAREN {
+            rm = service.addRpcMethod($n.text, argName, argPackage, retName, retPackage);
+            proto.addAnnotationsTo(rm);
+        } rpc_body_block[proto, rm]? SEMICOLON!
+    ;
+    
+rpc_body_block [Proto proto, Service.RpcMethod rm]
+    :   LEFTCURLY option_entry[proto, rm]* RIGHTCURLY {
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+        }
+    ;
+    
+extend_block [Proto proto, Message parent]
+@init {
+    Extension extension = null;
+}
+    :   EXTEND (
+        FULL_ID {
+            String fullType = $FULL_ID.text;
+            int lastDot = fullType.lastIndexOf('.');
+            String packageName = fullType.substring(0, lastDot); 
+            String type = fullType.substring(lastDot+1);
+            extension = new Extension(proto, parent, packageName, type);
+        } | ID { extension = new Extension(proto, parent, null, $ID.text); } ) {
+            if(parent==null)
+                proto.addExtension(extension);
+            else
+                parent.addNestedExtension(extension);
+                
+            proto.addAnnotationsTo(extension);
+        }
+        LEFTCURLY (extend_body[proto, extension])* RIGHTCURLY {
+            if(!proto.annotations.isEmpty())
+                throw new IllegalStateException("Misplaced annotations: " + proto.annotations);
+                
+        } (SEMICOLON?)!
+    ;
+    
+extend_body [Proto proto, Extension extension]
+    :   message_field[proto, extension]
+    |   annotation_entry[proto]
+    ;
+    
+ignore_block
+    :   LEFTCURLY ignore_block_body* RIGHTCURLY
+    ;
+    
+ignore_block_body
+    :   (LEFTCURLY)=> ignore_block
+    |   ~RIGHTCURLY
+    ;
+    

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/com/google/protobuf/WireFormatProxy.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/com/google/protobuf/WireFormatProxy.java b/sandbox/prototype/common/src/main/java/com/google/protobuf/WireFormatProxy.java
new file mode 100644
index 0000000..f560e9f
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/com/google/protobuf/WireFormatProxy.java
@@ -0,0 +1,10 @@
+package com.google.protobuf;
+
+public class WireFormatProxy {
+
+  WireFormatProxy(){};
+  
+  public static int getFieldType(int tag){
+    return WireFormat.getTagWireType(tag);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillError.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillError.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillError.java
new file mode 100644
index 0000000..95ededf
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillError.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.exceptions;
+
+public class DrillError extends Error {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillError.class);
+
+  public DrillError() {
+    super();
+  }
+
+  public DrillError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+    super(message, cause, enableSuppression, writableStackTrace);
+  }
+
+  public DrillError(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public DrillError(String message) {
+    super(message);
+  }
+
+  public DrillError(Throwable cause) {
+    super(cause);
+  }
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillException.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillException.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillException.java
new file mode 100644
index 0000000..6ae8300
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillException.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.exceptions;
+
+public class DrillException extends Exception {
+  public DrillException() {
+    super();
+  }
+
+  public DrillException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+    super(message, cause, enableSuppression, writableStackTrace);
+  }
+
+  public DrillException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public DrillException(String message) {
+    super(message);
+  }
+
+  public DrillException(Throwable cause) {
+    super(cause);
+  }
+
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillException.class);
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java
new file mode 100644
index 0000000..05961cd
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.exceptions;
+
+public class DrillRuntimeException extends RuntimeException {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillRuntimeException.class);
+
+  public DrillRuntimeException() {
+    super();
+  }
+
+  public DrillRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+    super(message, cause, enableSuppression, writableStackTrace);
+  }
+
+  public DrillRuntimeException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public DrillRuntimeException(String message) {
+    super(message);
+  }
+
+  public DrillRuntimeException(Throwable cause) {
+    super(cause);
+  }
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/ExpressionParsingException.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/ExpressionParsingException.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/ExpressionParsingException.java
new file mode 100644
index 0000000..3f2d29e
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/exceptions/ExpressionParsingException.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.exceptions;
+
+public class ExpressionParsingException extends DrillRuntimeException {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExpressionParsingException.class);
+
+  public ExpressionParsingException() {
+    super();
+  }
+
+  public ExpressionParsingException(String message, Throwable cause, boolean enableSuppression,
+      boolean writableStackTrace) {
+    super(message, cause, enableSuppression, writableStackTrace);
+  }
+
+  public ExpressionParsingException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public ExpressionParsingException(String message) {
+    super(message);
+  }
+
+  public ExpressionParsingException(Throwable cause) {
+    super(cause);
+  }
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Arg.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Arg.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Arg.java
new file mode 100644
index 0000000..7848cf7
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Arg.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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;
+
+import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.expression.visitors.ConstantChecker;
+
+
+public class Arg {
+  private final String name;
+  private final DataType[] allowedTypes;
+  private final boolean constantsOnly;
+  
+  public Arg(DataType... allowedTypes){
+    this(false, null, allowedTypes);
+  }
+  
+  public Arg(String name, DataType... allowedTypes) {
+    this(false, name, allowedTypes);
+  }
+
+  public Arg(boolean constantsOnly, String name, DataType... allowedTypes) {
+    this.name = name;
+    this.allowedTypes = allowedTypes;
+    this.constantsOnly = constantsOnly;
+  }
+
+  public String getName(){
+    return name;
+  }
+  
+  public void confirmDataType(int argIndex, LogicalExpression e, ErrorCollector errors){
+    if(constantsOnly){
+      if(ConstantChecker.onlyIncludesConstants(e)) errors.addExpectedConstantValue(argIndex, name);
+    }
+    DataType dt = e.getDataType();
+    if(dt.isLateBind()){
+      
+      // change among allowed types.
+      for(DataType a : allowedTypes){
+        if(dt == a) return;
+      }
+      
+      // didn't find an allowed type.
+      errors.addUnexpectedArgumentType(name, dt, allowedTypes, argIndex);
+      
+    }
+    
+    
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidator.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidator.java
new file mode 100644
index 0000000..8c374b2
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidator.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.List;
+
+/** 
+ * Validates whether the set of arguments are acceptable
+ */
+public interface ArgumentValidator {
+  public void validateArguments(List<LogicalExpression> expressions, ErrorCollector errors);
+  public String[] getArgumentNamesByPosition();
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidators.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidators.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidators.java
new file mode 100644
index 0000000..9c2b4b5
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ArgumentValidators.java
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.List;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.expression.types.DataType.Comparability;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Range;
+import com.google.common.collect.Ranges;
+
+public class ArgumentValidators {
+  
+  private static final String[] EMPTY_NAMES = new String[0];
+
+  public static class AnyTypeAllowed implements ArgumentValidator {
+
+    private final Range<Integer> argumentCount;
+
+    public AnyTypeAllowed(int argCount) {
+      super();
+      argumentCount = Ranges.singleton(argCount);
+    }
+
+    public AnyTypeAllowed(int minArguments, int maxArguments) {
+      super();
+      argumentCount = Ranges.closedOpen(minArguments, maxArguments);
+    }
+
+    @Override
+    public void validateArguments(List<LogicalExpression> expressions, ErrorCollector errors) {
+      // only need to check argument count since any type is allowed.
+      if (!argumentCount.contains(expressions.size()))
+        errors.addUnexpectedArgumentCount(expressions.size(), argumentCount);
+    }
+
+    @Override
+    public String[] getArgumentNamesByPosition() {
+      return EMPTY_NAMES;
+    }
+
+  }
+
+  private static class PredicateValidator implements ArgumentValidator {
+    private final Range<Integer> argumentCount;
+    private Predicate<DataType> predicate;
+    private boolean allSame;
+
+    public PredicateValidator(int argCount, Predicate<DataType> predicate, boolean allSame) {
+      super();
+      this.argumentCount = Ranges.singleton(argCount);
+      this.predicate = predicate;
+      this.allSame = allSame;
+    }
+
+    public PredicateValidator(int minArguments, int maxArguments, Predicate<DataType> predicate, boolean allSame) {
+      super();
+      this.argumentCount = Ranges.closedOpen(minArguments, maxArguments);
+      this.predicate = predicate;
+      this.allSame = allSame;
+    }
+
+    @Override
+    public void validateArguments(List<LogicalExpression> expressions, ErrorCollector errors) {
+      int i = -1;
+      DataType t = null;
+      for (LogicalExpression le : expressions) {
+        i++;
+        if (t == null) t = le.getDataType();
+
+        if (!predicate.apply(le.getDataType())) {
+          errors.addUnexpectedType(i, le.getDataType());
+          continue;
+        }
+
+        if (allSame && t != le.getDataType()) {
+          errors.addUnexpectedType(i, le.getDataType());
+        }
+
+      }
+      if (!argumentCount.contains(expressions.size()))
+        errors.addUnexpectedArgumentCount(expressions.size(), argumentCount);
+    }
+
+    @Override
+    public String[] getArgumentNamesByPosition() {
+      return EMPTY_NAMES;
+    }
+  }
+
+  public static class ComparableArguments extends PredicateValidator {
+
+    public ComparableArguments(int argCount, DataType... allowedTypes) {
+      super(argCount, new ComparableChecker(), true);
+    }
+
+    public ComparableArguments(int minArguments, int maxArguments, DataType... allowedTypes) {
+      super(minArguments, maxArguments, new ComparableChecker(), true);
+    }
+
+    public static class ComparableChecker implements Predicate<DataType> {
+
+      public boolean apply(DataType dt) {
+        return dt.getComparability().equals(Comparability.ORDERED);
+      }
+    }
+  }
+
+  public static class AllowedTypeList extends PredicateValidator {
+
+    public AllowedTypeList(int argCount, DataType... allowedTypes) {
+      super(argCount, new AllowedTypeChecker(allowedTypes), false);
+    }
+
+    public AllowedTypeList(int minArguments, int maxArguments, DataType... allowedTypes) {
+      super(minArguments, maxArguments, new AllowedTypeChecker(allowedTypes), false);
+    }
+
+    public AllowedTypeList(int argCount, boolean allSame, DataType... allowedTypes) {
+      super(argCount, new AllowedTypeChecker(allowedTypes), allSame);
+    }
+
+    public AllowedTypeList(int minArguments, int maxArguments, boolean allSame, DataType... allowedTypes) {
+      super(minArguments, maxArguments, new AllowedTypeChecker(allowedTypes), allSame);
+    }
+
+    public static class AllowedTypeChecker implements Predicate<DataType> {
+
+      private DataType[] allowedTypes;
+
+      public AllowedTypeChecker(DataType... allowedTypes) {
+        this.allowedTypes = allowedTypes;
+      }
+
+      public boolean apply(DataType dt) {
+        return ArrayUtils.contains(allowedTypes, dt);
+      }
+    }
+
+  }
+
+  public static class NumericTypeAllowed extends PredicateValidator {
+
+    public NumericTypeAllowed(int argCount, boolean allSame) {
+      super(argCount, new NumericTypeChecker(), allSame);
+
+    }
+
+    public NumericTypeAllowed(int minArguments, int maxArguments, boolean allSame) {
+      super(minArguments, maxArguments, new NumericTypeChecker(), allSame);
+    }
+
+    public static class NumericTypeChecker implements Predicate<DataType> {
+
+      public boolean apply(DataType dt) {
+        return dt.isNumericType();
+      }
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BasicArgumentValidator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BasicArgumentValidator.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BasicArgumentValidator.java
new file mode 100644
index 0000000..89b015a
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BasicArgumentValidator.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.List;
+
+import org.apache.drill.common.expression.types.DataType;
+
+public class BasicArgumentValidator implements ArgumentValidator {
+
+  private final Arg[] args;
+
+  public BasicArgumentValidator(DataType... types) {
+    this.args = new Arg[] { new Arg("single", types) };
+  }
+
+  public BasicArgumentValidator(Arg... args) {
+    this.args = args;
+  }
+
+  @Override
+  public void validateArguments(List<LogicalExpression> expressions, ErrorCollector errors) {
+    if (expressions.size() != args.length) errors.addUnexpectedArgumentCount(expressions.size(), args.length);
+
+    int i = 0;
+    for (LogicalExpression e : expressions) {
+      args[i].confirmDataType(i, e, errors);
+
+      i++;
+    }
+  }
+
+  public Arg arg(String name, DataType... allowedTypes) {
+    return new Arg(name, allowedTypes);
+  }
+
+  @Override
+  public String[] getArgumentNamesByPosition() {
+    String[] names = new String[args.length];
+    for(int i =0; i < names.length; i++){
+      names[i] = args[i].getName();
+    }
+    return names;
+  }
+
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BooleanFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BooleanFunctions.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BooleanFunctions.java
deleted file mode 100644
index 937414c..0000000
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/BooleanFunctions.java
+++ /dev/null
@@ -1,141 +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.common.expression;
-
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class BooleanFunctions {
-
-  static final Logger logger = LoggerFactory.getLogger(BooleanFunctions.class);
-
-  public static final Class<?>[] SUB_TYPES = { Or.class, And.class };
-
-  private static abstract class BooleanFunctionBase extends FunctionBase {
-
-    protected BooleanFunctionBase(List<LogicalExpression> expressions) {
-      super(expressions);
-    }
-
-    @Override
-    public DataType getDataType() {
-      return DataType.BOOLEAN;
-    }
-  }
-
-  public static class Or extends BooleanFunctionBase {
-    public Or(List<LogicalExpression> expressions) {
-      super(expressions);
-    }
-
-    @Override
-    public void addToString(StringBuilder sb) {
-      this.opToString(sb, "||");
-    }
-
-  }
-
-  public static class And extends BooleanFunctionBase {
-    public And(List<LogicalExpression> expressions) {
-      super(expressions);
-    }
-
-    @Override
-    public void addToString(StringBuilder sb) {
-      this.opToString(sb, "&&");
-    }
-
-  }
-
-  @FunctionName("isNull")
-  public static class IsNull extends BooleanFunctionBase {
-    public IsNull(List<LogicalExpression> expressions) {
-      super(expressions);
-    }
-
-    @Override
-    public void addToString(StringBuilder sb) {
-      this.funcToString(sb, "isNull");
-    }
-
-  }
-
-  public static class Comparison extends LogicalExpressionBase {
-
-    public final ComparisonType type;
-    public final LogicalExpression left;
-    public final LogicalExpression right;
-
-    public static enum ComparisonType {
-      GT(">"), LT("<"), EQ("=="), NOTEQ("!="), GTE(">="), LTE("<=");
-      public final String val;
-
-      ComparisonType(String str) {
-        this.val = str;
-      }
-    }
-
-    public Comparison(String s, LogicalExpression left, LogicalExpression right) {
-      this.left = left;
-      this.right = right;
-      ComparisonType temp = null;
-      for (ComparisonType ct : ComparisonType.values()) {
-        if (ct.val.equals(s)) {
-          temp = ct;
-          break;
-        }
-      }
-      if (temp == null)
-        throw new IllegalArgumentException("Unknown comparison type of " + s);
-      type = temp;
-
-    }
-
-    @Override
-    public void addToString(StringBuilder sb) {
-      sb.append(" ( ");
-      left.addToString(sb);
-      sb.append(" ");
-      sb.append(type.val);
-      sb.append(" ");
-      right.addToString(sb);
-      sb.append(" ) ");
-    }
-
-    public static LogicalExpression create(List<LogicalExpression> expressions, List<String> comparisonTypes) {
-      // logger.debug("Generating new comparison expressions.");
-      if (expressions.size() == 1) {
-        return expressions.get(0);
-      }
-
-      if (expressions.size() - 1 != comparisonTypes.size())
-        throw new IllegalArgumentException("Must receive one more expression then the provided number of comparisons.");
-
-      LogicalExpression first = expressions.get(0);
-      LogicalExpression second;
-      for (int i = 0; i < comparisonTypes.size(); i++) {
-        second = expressions.get(i + 1);
-        first = new Comparison(comparisonTypes.get(i), first, second);
-      }
-      return first;
-    }
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/CallProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/CallProvider.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/CallProvider.java
new file mode 100644
index 0000000..028a76c
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/CallProvider.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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;
+
+public interface CallProvider {
+  public FunctionDefinition[] getFunctionDefintions();
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Cast.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Cast.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Cast.java
deleted file mode 100644
index 594abbe..0000000
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/Cast.java
+++ /dev/null
@@ -1,44 +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.common.expression;
-
-
-@FunctionName("cast")
-public class Cast extends LogicalExpressionBase {
-  private DataType outputType;
-  private LogicalExpression sub;
-
-  public Cast(LogicalExpression subExpression, DataType outputType) throws ExpressionValidationError {
-    if (!sub.getDataType().canCastTo(outputType))
-      throw new ExpressionValidationError();
-    this.sub = subExpression;
-    this.outputType = outputType;
-  }
-
-  @Override
-  public DataType getDataType() {
-    return outputType;
-  }
-
-  @Override
-  public void addToString(StringBuilder sb) {
-  }
-
-  
-  
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/DataType.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/DataType.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/DataType.java
deleted file mode 100644
index 4cbbd27..0000000
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/DataType.java
+++ /dev/null
@@ -1,53 +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.common.expression;
-
-import java.util.Arrays;
-
-public enum DataType { // roughly taken from sql
-  INVALID, BOOLEAN, BYTES, NVARCHAR, INTEGER, SMALLINT, VARBIT, FLOAT, DOUBLE, DATE, TIME, DATETIME, UNKNOWN;
-
-  private DataType[] castable;
-
-  private DataType(DataType... castToDataTypes) {
-    castable = castToDataTypes;
-    Arrays.sort(castable);
-  }
-
-  public boolean canCastTo(DataType dt) {
-    if (dt == this)
-      return true;
-    for (int i = 0; i < castable.length; i++) {
-      if (dt.equals(castable[i]))
-        return true;
-    }
-    return false;
-  }
-
-  public static DataType getCombinedCast(DataType a, DataType b) {
-    if (a == b)
-      return a;
-
-    if (a.canCastTo(b))
-      return b;
-    if (b.canCastTo(a))
-      return a;
-    return null;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/238ca97d/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ErrorCollector.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ErrorCollector.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ErrorCollector.java
new file mode 100644
index 0000000..a618ac6
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/expression/ErrorCollector.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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;
+
+import org.apache.drill.common.expression.types.DataType;
+
+import com.google.common.collect.Range;
+
+public class ErrorCollector {
+
+  public void addGeneralError(String s){};
+  public void addUnexpectedArgumentType(String name, DataType actual, DataType[] expected, int argumentIndex){}
+  public void addUnexpectedArgumentCount(int actual, Range<Integer> expected){}
+  public void addUnexpectedArgumentCount(int actual, int expected){}
+  public void addNonNumericType(DataType actual){};
+  public void addUnexpectedType(int index, DataType actual){};
+  public void addExpectedConstantValue(int actual, String s){};
+}