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 2014/04/20 03:18:12 UTC

[04/51] [abbrv] git commit: - Fixes for more recent optiq snapshot - Fix hash rule to insert xor rather than ^ - Update dates so they write correctly - Add DrillSqlOperatorTable that supports resolving calls from Drill Function registry - Add Hack SqlPar

- Fixes for more recent optiq snapshot
- Fix hash rule to insert xor rather than ^
- Update dates so they write correctly
- Add DrillSqlOperatorTable that supports resolving calls from Drill Function registry
- Add Hack SqlParserImplFactory to override default AbstractSqlParserImpl use of Std operator table
- Remove spaces from function names to make ExprParser work correctly
- Add VarBinary to Hive object inspectors
- Update ExpressionTreeMaterializer's visit function call to return NULLExpression instead of null so that FunctionCall constructor's ImmutableList.of() doesn't throw exception on missing cast expression.


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

Branch: refs/heads/master
Commit: 62a786676c12e9ae258ef4eb0bc8322cb1cc7463
Parents: 6b517da
Author: Jacques Nadeau <ja...@apache.org>
Authored: Sun Mar 30 14:52:50 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sat Apr 19 18:07:08 2014 -0700

----------------------------------------------------------------------
 common/pom.xml                                  |   5 +
 .../expression/ExpressionStringBuilder.java     |  46 ++++++--
 .../common/expression/FunctionCallFactory.java  |  12 +-
 .../common/expression/ValueExpressions.java     |   7 +-
 .../src/main/codegen/data/HiveTypes.tdd         |   8 ++
 .../codegen/templates/ComparisonFunctions.java  |  10 +-
 .../templates/DateIntervalFunctions.java        |  20 ++--
 .../codegen/templates/ObjectInspectors.java     |  21 ++++
 .../exec/expr/ExpressionTreeMaterializer.java   |   3 +-
 .../drill/exec/expr/fn/DrillFuncHolder.java     |   2 +-
 .../exec/planner/logical/DrillRuleSets.java     |  13 +-
 .../drill/exec/planner/physical/PrelUtil.java   |   2 +-
 .../apache/drill/exec/planner/sql/Checker.java  |  47 ++++++++
 .../exec/planner/sql/DrillOperatorTable.java    |  50 +++++---
 .../exec/planner/sql/DrillParserFactory.java    |  82 +++++++++++++
 .../exec/planner/sql/DrillSqlAggOperator.java   |  78 ++++++++++++
 .../exec/planner/sql/DrillSqlOperator.java      | 118 +------------------
 .../drill/exec/planner/sql/DrillSqlWorker.java  |   9 +-
 .../exec/planner/sql/DynamicReturnType.java     |  29 +++++
 .../drill/exec/planner/sql/DynamicType.java     |  35 ++++++
 .../drill/exec/planner/sql/FixedRange.java      |  46 ++++++++
 .../drill/exec/resolver/TypeCastRules.java      |   4 +-
 .../apache/drill/exec/store/AbstractSchema.java |   8 +-
 .../drill/exec/store/StoragePluginRegistry.java |  16 +--
 .../exec/store/dfs/FileSystemSchemaFactory.java |  10 +-
 .../java/org/apache/drill/BaseTestQuery.java    |   2 +-
 .../java/org/apache/drill/TestTpchQueries.java  |   2 +-
 .../src/test/resources/queries/tpch/01.sql      |   4 +-
 28 files changed, 493 insertions(+), 196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/common/pom.xml
----------------------------------------------------------------------
diff --git a/common/pom.xml b/common/pom.xml
index afcf7a3..55d4dd4 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -98,6 +98,11 @@
       <version>3.4</version>
     </dependency>
 
+    <dependency>
+        <groupId>joda-time</groupId>
+        <artifactId>joda-time</artifactId>
+        <version>2.3</version>
+    </dependency>
 
   </dependencies>
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java b/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
index 9b3e91a..35835c7 100644
--- a/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
+++ b/common/src/main/java/org/apache/drill/common/expression/ExpressionStringBuilder.java
@@ -17,20 +17,27 @@
  */
 package org.apache.drill.common.expression;
 
+import java.io.IOException;
+
 import org.apache.drill.common.expression.IfExpression.IfCondition;
 import org.apache.drill.common.expression.ValueExpressions.BooleanExpression;
+import org.apache.drill.common.expression.ValueExpressions.DateExpression;
 import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
 import org.apache.drill.common.expression.ValueExpressions.FloatExpression;
 import org.apache.drill.common.expression.ValueExpressions.IntExpression;
-import org.apache.drill.common.expression.ValueExpressions.LongExpression;
-import org.apache.drill.common.expression.ValueExpressions.DateExpression;
-import org.apache.drill.common.expression.ValueExpressions.IntervalYearExpression;
 import org.apache.drill.common.expression.ValueExpressions.IntervalDayExpression;
-import org.apache.drill.common.expression.ValueExpressions.TimeStampExpression;
-import org.apache.drill.common.expression.ValueExpressions.TimeExpression;
+import org.apache.drill.common.expression.ValueExpressions.IntervalYearExpression;
+import org.apache.drill.common.expression.ValueExpressions.LongExpression;
 import org.apache.drill.common.expression.ValueExpressions.QuotedString;
+import org.apache.drill.common.expression.ValueExpressions.TimeExpression;
+import org.apache.drill.common.expression.ValueExpressions.TimeStampExpression;
 import org.apache.drill.common.expression.visitors.AbstractExprVisitor;
 import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.joda.time.Period;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.DateTimeFormatterBuilder;
+import org.joda.time.format.DateTimeParser;
 
 import com.google.common.collect.ImmutableList;
 
@@ -88,31 +95,56 @@ public class ExpressionStringBuilder extends AbstractExprVisitor<Void, StringBui
 
   @Override
   public Void visitDateConstant(DateExpression lExpr, StringBuilder sb) throws RuntimeException {
+    sb.append("cast( ");
     sb.append(lExpr.getDate());
+    sb.append(" as DATE)");
     return null;
   }
 
   @Override
   public Void visitTimeConstant(TimeExpression lExpr, StringBuilder sb) throws RuntimeException {
+    sb.append("cast( ");
     sb.append(lExpr.getTime());
+    sb.append(" as TIME)");
     return null;
   }
 
+  static final DateTimeFormatter TIMESTAMP_FORMAT;
+  static {
+    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
+    DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser();
+    DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
+
+    TIMESTAMP_FORMAT = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime).appendOptional(optionalSec).toFormatter();
+
+  }
+  
   @Override
   public Void visitTimeStampConstant(TimeStampExpression lExpr, StringBuilder sb) throws RuntimeException {
+    sb.append("cast( \"");
+    try {
+      TIMESTAMP_FORMAT.printTo(sb, lExpr.getTimeStamp());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
     sb.append(lExpr.getTimeStamp());
+    sb.append(" \" as TIMESTAMP)");
     return null;
   }
 
   @Override
   public Void visitIntervalYearConstant(IntervalYearExpression lExpr, StringBuilder sb) throws RuntimeException {
-    sb.append(lExpr.getIntervalYear());
+    sb.append("cast( \"");
+    sb.append(Period.years(lExpr.getIntervalYear()).toString());
+    sb.append(" \" as INTERVAL)");
     return null;
   }
 
   @Override
   public Void visitIntervalDayConstant(IntervalDayExpression lExpr, StringBuilder sb) throws RuntimeException {
-    sb.append(lExpr.getIntervalDay() + " " + lExpr.getIntervalMillis());
+    sb.append("cast( \"");
+    sb.append(Period.days(lExpr.getIntervalDay()).plusMillis(lExpr.getIntervalMillis()).toString());
+    sb.append(" \" as INTERVAL)");
     return null;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java b/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
index c6c7074..71fd8bd 100644
--- a/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
+++ b/common/src/main/java/org/apache/drill/common/expression/FunctionCallFactory.java
@@ -48,14 +48,14 @@ public class FunctionCallFactory {
 
     opToFuncTable.put("||", "or");
     opToFuncTable.put("&&", "and");
-    opToFuncTable.put(">", "greater than");
-    opToFuncTable.put("<", "less than");
+    opToFuncTable.put(">", "greater_than");
+    opToFuncTable.put("<", "less_than");
     opToFuncTable.put("==", "equal");
     opToFuncTable.put("=", "equal");
-    opToFuncTable.put("!=", "not equal");
-    opToFuncTable.put("<>", "not equal");
-    opToFuncTable.put(">=", "greater than or equal to");
-    opToFuncTable.put("<=", "less than or equal to");
+    opToFuncTable.put("!=", "not_equal");
+    opToFuncTable.put("<>", "not_equal");
+    opToFuncTable.put(">=", "greater_than_or_equal_to");
+    opToFuncTable.put("<=", "less_than_or_equal_to");
 
     opToFuncTable.put("!", "not");
     opToFuncTable.put("u-", "negative");

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
index 8ec4109..10cf152 100644
--- a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
+++ b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
@@ -420,12 +420,13 @@ public class ValueExpressions {
   public static class IntervalDayExpression extends LogicalExpressionBase {
 
     private static final MajorType INTERVALDAY_CONSTANT = Types.required(MinorType.INTERVALDAY);
-
+    private static final long MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
+    
     private int days;
     private int millis;
-
+    
     public IntervalDayExpression(long intervalInMillis) {
-      this((int) intervalInMillis / (1000 * 60 * 60 * 24), (int) (intervalInMillis % (1000 * 60 * 60 * 24)), ExpressionPosition.UNKNOWN);
+      this((int) (intervalInMillis / MILLIS_IN_DAY), (int) (intervalInMillis % MILLIS_IN_DAY), ExpressionPosition.UNKNOWN);
     }
 
       public IntervalDayExpression(int days, int millis, ExpressionPosition pos) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/codegen/data/HiveTypes.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/HiveTypes.tdd b/exec/java-exec/src/main/codegen/data/HiveTypes.tdd
index ddc8041..c23f981 100644
--- a/exec/java-exec/src/main/codegen/data/HiveTypes.tdd
+++ b/exec/java-exec/src/main/codegen/data/HiveTypes.tdd
@@ -87,6 +87,14 @@
       javaType: "",
       minorType: "VAR16CHAR",
       holder: "Var16Char"
+    },
+    {
+      hiveType: "BINARY",
+      hiveOI: "BinaryObjectInspector",
+      serdeConstant: "BINARY_TYPE_NAME",
+      javaType: "",
+      minorType: "VARBINARY",
+      holder: "VarBinary"
     }
   ]
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java b/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
index f5ccc6f..9b0028c 100644
--- a/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
@@ -118,7 +118,7 @@ public class GCompare${left}${right}{
       }
   }
   
-  @FunctionTemplate(names = {"less than", "<"}, scope = FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"less_than", "<"}, scope = FunctionTemplate.FunctionScope.SIMPLE)
   public static class LessThan${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -149,7 +149,7 @@ public class GCompare${left}${right}{
       }
   }
   
-  @FunctionTemplate(names = {"less than or equal to", "<="}, scope = FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"less_than_or_equal_to", "<="}, scope = FunctionTemplate.FunctionScope.SIMPLE)
   public static class LessThanE${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -180,7 +180,7 @@ public class GCompare${left}${right}{
     }
   }
   
-  @FunctionTemplate(names = {"greater than", ">"}, scope = FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"greater_than", ">"}, scope = FunctionTemplate.FunctionScope.SIMPLE)
   public static class GreaterThan${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -211,7 +211,7 @@ public class GCompare${left}${right}{
     }
   }
   
-  @FunctionTemplate(names = {"greater than or equal to", ">="}, scope = FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"greater_than_or_equal_to", ">="}, scope = FunctionTemplate.FunctionScope.SIMPLE)
   public static class GreaterThanE${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -273,7 +273,7 @@ public class GCompare${left}${right}{
       }
   }
   
-  @FunctionTemplate(names = {"not equal","<>","!="}, scope = FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"not_equal","<>","!="}, scope = FunctionTemplate.FunctionScope.SIMPLE)
   public static class NotEquals${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java
index eb0e1fb..7afbcfc 100644
--- a/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/DateIntervalFunctions.java
@@ -53,7 +53,7 @@ public class GCompare${type.name}Functions {
       }
   }
 
-  @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "less_than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class LessThan${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -69,7 +69,7 @@ public class GCompare${type.name}Functions {
       }
   }
 
-  @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "less_than_or_equal_to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class LessThanE${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -85,7 +85,7 @@ public class GCompare${type.name}Functions {
     }
   }
 
-  @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "greater_than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class GreaterThan${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -101,7 +101,7 @@ public class GCompare${type.name}Functions {
     }
   }
 
-  @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "greater_than_or_equal_to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class GreaterThanE${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -132,7 +132,7 @@ public class GCompare${type.name}Functions {
       }
   }
 
-  @FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "not_equal", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class NotEquals${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -211,7 +211,7 @@ public class GCompare${type.name}Functions {
       }
   }
 
-  @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "less_than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class LessThan${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -234,7 +234,7 @@ public class GCompare${type.name}Functions {
       }
   }
 
-  @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "less_than_or_equal_to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class LessThanE${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -257,7 +257,7 @@ public class GCompare${type.name}Functions {
     }
   }
 
-  @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "greater_than", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class GreaterThan${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -280,7 +280,7 @@ public class GCompare${type.name}Functions {
     }
   }
 
-  @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "greater_than_or_equal_to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class GreaterThanE${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;
@@ -326,7 +326,7 @@ public class GCompare${type.name}Functions {
       }
   }
 
-  @FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
+  @FunctionTemplate(name = "not_equal", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class NotEquals${type.name} implements DrillSimpleFunc {
 
       @Param ${type.name}Holder left;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/codegen/templates/ObjectInspectors.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/ObjectInspectors.java b/exec/java-exec/src/main/codegen/templates/ObjectInspectors.java
index 57a7bda..cf96cbc 100644
--- a/exec/java-exec/src/main/codegen/templates/ObjectInspectors.java
+++ b/exec/java-exec/src/main/codegen/templates/ObjectInspectors.java
@@ -65,6 +65,27 @@ public class Drill${entry.holder}ObjectInspector extends AbstractPrimitiveObject
     else
     return ((NullableVar16CharHolder)o).toString();
   }
+<#elseif entry.minorType == "VARBINARY">  
+@Override
+public org.apache.hadoop.io.BytesWritable getPrimitiveWritableObject(Object o) {
+  throw new UnsupportedOperationException();
+}
+
+@Override
+public byte[] getPrimitiveJavaObject(Object o) {
+  if (o instanceof VarBinaryHolder){
+    VarBinaryHolder h = (VarBinaryHolder)o;
+    byte[] buf = new byte[h.end-h.start];
+    h.buffer.getBytes(h.start, buf, 0, h.end-h.start);
+    return buf;
+  }else{
+    NullableVarBinaryHolder h = (NullableVarBinaryHolder)o;
+    byte[] buf = new byte[h.end-h.start];
+    h.buffer.getBytes(h.start, buf, 0, h.end-h.start);
+    return buf;
+    
+  }
+}
 <#elseif entry.minorType == "BIT">
   @Override
   public boolean get(Object o) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
index 608c2ff..d65ff78 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
@@ -107,6 +107,7 @@ public class ExpressionTreeMaterializer {
       List<LogicalExpression> args = Lists.newArrayList();
       for (int i = 0; i < call.args.size(); ++i) {
         LogicalExpression newExpr = call.args.get(i).accept(this, registry);
+        assert newExpr != null : String.format("Materialization of %s return a null expression.", call.args.get(i));
         args.add(newExpr);
       }
 
@@ -150,7 +151,7 @@ public class ExpressionTreeMaterializer {
 
             if (matchedCastFuncHolder == null) {
               logFunctionResolutionError(errorCollector, castCall);
-              return null;
+              return NullExpression.INSTANCE;
             }
 
             argsWithCast.add(new DrillFuncHolderExpr(call.getName(), matchedCastFuncHolder, castArgs, ExpressionPosition.UNKNOWN));

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
index 47b8408..e93a768 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
@@ -180,7 +180,7 @@ public abstract class DrillFuncHolder {
     return this.parameters[i].type;
   }
 
-  public int getParmSize() {
+  public int getParamCount() {
     return this.parameters.length;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
index 9ab5308..562a3d4 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
@@ -30,8 +30,10 @@ import org.apache.drill.exec.planner.physical.ScreenPrule;
 import org.apache.drill.exec.planner.physical.SortConvertPrule;
 import org.apache.drill.exec.planner.physical.SortPrule;
 import org.apache.drill.exec.planner.physical.StreamAggPrule;
+import org.eigenbase.rel.rules.PushFilterPastJoinRule;
+import org.eigenbase.rel.rules.PushFilterPastProjectRule;
+import org.eigenbase.rel.rules.PushJoinThroughJoinRule;
 import org.eigenbase.relopt.RelOptRule;
-import org.eigenbase.relopt.volcano.AbstractConverter;
 import org.eigenbase.relopt.volcano.AbstractConverter.ExpandConversionRule;
 
 import com.google.common.collect.ImmutableSet;
@@ -40,6 +42,12 @@ public class DrillRuleSets {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillRuleSets.class);
 
   public static final RuleSet DRILL_BASIC_RULES = new DrillRuleSet(ImmutableSet.of( //
+      // Add support for WHERE style joins.
+      PushFilterPastProjectRule.INSTANCE,
+      PushFilterPastJoinRule.FILTER_ON_JOIN,
+      PushJoinThroughJoinRule.RIGHT, 
+      PushJoinThroughJoinRule.LEFT, 
+      // End supprot for WHERE style joins.
       
       DrillScanRule.INSTANCE,
       DrillFilterRule.INSTANCE,
@@ -50,6 +58,9 @@ public class DrillRuleSets {
       DrillSortRule.INSTANCE,
       DrillJoinRule.INSTANCE,
       DrillUnionRule.INSTANCE
+      
+      
+
       ));
   
   public static final RuleSet DRILL_PHYSICAL_MEM = new DrillRuleSet(ImmutableSet.of( //

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelUtil.java
index 22e8090..45e7523 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelUtil.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelUtil.java
@@ -63,7 +63,7 @@ public class PrelUtil {
       fr = new FieldReference(childFields.get(fields.get(i).getFieldId()), ExpressionPosition.UNKNOWN);      
       FunctionCall func2 = new FunctionCall("hash",  ImmutableList.of((LogicalExpression)fr), ExpressionPosition.UNKNOWN);
       
-      func = new FunctionCall("^", ImmutableList.of((LogicalExpression)func, (LogicalExpression)func2), ExpressionPosition.UNKNOWN);
+      func = new FunctionCall("xor", ImmutableList.of((LogicalExpression)func, (LogicalExpression)func2), ExpressionPosition.UNKNOWN);
     }
     
     return func;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/Checker.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/Checker.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/Checker.java
new file mode 100644
index 0000000..a22da17
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/Checker.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql;
+
+import org.eigenbase.sql.SqlCallBinding;
+import org.eigenbase.sql.SqlOperandCountRange;
+import org.eigenbase.sql.SqlOperator;
+import org.eigenbase.sql.type.SqlOperandTypeChecker;
+
+class Checker implements SqlOperandTypeChecker {
+  private SqlOperandCountRange range;
+
+  public Checker(int size) {
+    range = new FixedRange(size);
+  }
+
+  @Override
+  public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
+    return true;
+  }
+
+  @Override
+  public SqlOperandCountRange getOperandCountRange() {
+    return range;
+  }
+
+  @Override
+  public String getAllowedSignatures(SqlOperator op, String opName) {
+    return opName + "(Drill - Opaque)";
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillOperatorTable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillOperatorTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillOperatorTable.java
index f20ca99..0dbbc56 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillOperatorTable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillOperatorTable.java
@@ -17,8 +17,10 @@
  */
 package org.apache.drill.exec.planner.sql;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.drill.exec.expr.fn.DrillFuncHolder;
 import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
@@ -31,44 +33,58 @@ import org.eigenbase.sql.fun.SqlStdOperatorTable;
 
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Lists;
+import com.google.hive12.common.collect.Sets;
 
-public class DrillOperatorTable extends SqlStdOperatorTable{
+public class DrillOperatorTable extends SqlStdOperatorTable {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillOperatorTable.class);
 
   private static final SqlOperatorTable inner = SqlStdOperatorTable.instance();
   private List<SqlOperator> operators;
   private ArrayListMultimap<String, SqlOperator> opMap = ArrayListMultimap.create();
-  
-  public DrillOperatorTable(FunctionImplementationRegistry registry){
+
+  public DrillOperatorTable(FunctionImplementationRegistry registry) {
     operators = Lists.newArrayList();
     operators.addAll(inner.getOperatorList());
-    
-    for(Map.Entry<String, DrillFuncHolder> function : registry.getDrillRegistry().getMethods().entries()){
-      SqlOperator op = new DrillSqlOperator(function.getKey(), function.getValue().getParmSize());
-      operators.add(op);
-      opMap.put(function.getKey(), op);
+
+    for (Map.Entry<String, Collection<DrillFuncHolder>> function : registry.getDrillRegistry().getMethods().asMap().entrySet()) {
+      Set<Integer> argCounts = Sets.newHashSet();
+      String name = function.getKey().toUpperCase();
+      for (DrillFuncHolder f : function.getValue()) {
+        if (argCounts.add(f.getParamCount())) {
+          SqlOperator op = null;
+          if (f.isAggregating()) {
+            op = new DrillSqlAggOperator(name, f.getParamCount());
+          } else {
+            op = new DrillSqlOperator(name, f.getParamCount());
+          }
+          operators.add(op);
+          opMap.put(function.getKey(), op);
+        }
+      }
     }
-    
+
     // TODO: add hive functions.
   }
-  
+
   @Override
   public List<SqlOperator> lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax) {
-    if(syntax == SqlSyntax.FUNCTION){
+    if (syntax == SqlSyntax.FUNCTION) {
       List<SqlOperator> drillOps = opMap.get(opName.getSimple());
-      if(drillOps == null || drillOps.isEmpty()) return inner.lookupOperatorOverloads(opName, category, syntax);
-      
+      if (drillOps == null || drillOps.isEmpty())
+        return inner.lookupOperatorOverloads(opName, category, syntax);
+
       List<SqlOperator> optiqOps = inner.lookupOperatorOverloads(opName, category, syntax);
-      if(optiqOps.isEmpty()) return drillOps;
-      
+      if (optiqOps.isEmpty())
+        return drillOps;
+
       // combine the two.
       List<SqlOperator> both = Lists.newArrayList();
       both.addAll(optiqOps);
       both.addAll(drillOps);
-      
+
       return both;
 
-    }else{
+    } else {
       return inner.lookupOperatorOverloads(opName, category, syntax);
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserFactory.java
new file mode 100644
index 0000000..d0a6a19
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserFactory.java
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql;
+
+import java.io.Reader;
+import java.util.List;
+
+import org.eigenbase.sql.SqlCall;
+import org.eigenbase.sql.SqlFunction;
+import org.eigenbase.sql.SqlFunctionCategory;
+import org.eigenbase.sql.SqlIdentifier;
+import org.eigenbase.sql.SqlLiteral;
+import org.eigenbase.sql.SqlNode;
+import org.eigenbase.sql.SqlOperator;
+import org.eigenbase.sql.SqlOperatorTable;
+import org.eigenbase.sql.SqlSyntax;
+import org.eigenbase.sql.parser.SqlParserImplFactory;
+import org.eigenbase.sql.parser.SqlParserPos;
+import org.eigenbase.sql.parser.impl.SqlParserImpl;
+
+public class DrillParserFactory implements SqlParserImplFactory {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillParserFactory.class);
+
+  private final SqlOperatorTable table;
+
+  public DrillParserFactory(SqlOperatorTable table) {
+    super();
+    this.table = table;
+  }
+
+  public DrillParser getParser(Reader stream) {
+    return new DrillParser(stream);
+  }
+
+  public class DrillParser extends SqlParserImpl {
+
+    public DrillParser(Reader stream) {
+      super(stream);
+    }
+
+    protected SqlCall createCall(SqlIdentifier funName, SqlParserPos pos, SqlFunctionCategory funcType,
+        SqlLiteral functionQualifier, SqlNode[] operands) {
+      SqlOperator fun = null;
+
+      // First, try a half-hearted resolution as a builtin function.
+      // If we find one, use it; this will guarantee that we
+      // preserve the correct syntax (i.e. don't quote builtin function
+      // / name when regenerating SQL).
+      if (funName.isSimple()) {
+        List<SqlOperator> list = table.lookupOperatorOverloads(funName, null, SqlSyntax.FUNCTION);
+        if (list.size() == 1) {
+          fun = list.get(0);
+        }
+      }
+
+      // Otherwise, just create a placeholder function. Later, during
+      // validation, it will be resolved into a real function reference.
+      if (fun == null) {
+        fun = new SqlFunction(funName, null, null, null, null, funcType);
+      }
+
+      return fun.createCall(functionQualifier, pos, operands);
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlAggOperator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlAggOperator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlAggOperator.java
new file mode 100644
index 0000000..f18559f
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlAggOperator.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql;
+
+import java.util.List;
+
+import org.apache.drill.exec.planner.types.RelDataTypeDrillImpl;
+import org.apache.drill.exec.planner.types.RelDataTypeHolder;
+import org.eigenbase.reltype.RelDataType;
+import org.eigenbase.reltype.RelDataTypeFactory;
+import org.eigenbase.sql.SqlAggFunction;
+import org.eigenbase.sql.SqlCall;
+import org.eigenbase.sql.SqlCallBinding;
+import org.eigenbase.sql.SqlFunctionCategory;
+import org.eigenbase.sql.SqlIdentifier;
+import org.eigenbase.sql.SqlKind;
+import org.eigenbase.sql.SqlLiteral;
+import org.eigenbase.sql.SqlNode;
+import org.eigenbase.sql.SqlOperandCountRange;
+import org.eigenbase.sql.SqlOperatorBinding;
+import org.eigenbase.sql.SqlSyntax;
+import org.eigenbase.sql.SqlWriter;
+import org.eigenbase.sql.parser.SqlParserPos;
+import org.eigenbase.sql.type.SqlOperandTypeChecker;
+import org.eigenbase.sql.type.SqlOperandTypeInference;
+import org.eigenbase.sql.type.SqlReturnTypeInference;
+import org.eigenbase.sql.type.SqlTypeName;
+import org.eigenbase.sql.util.SqlBasicVisitor.ArgHandler;
+import org.eigenbase.sql.util.SqlVisitor;
+import org.eigenbase.sql.validate.SqlMonotonicity;
+import org.eigenbase.sql.validate.SqlValidator;
+import org.eigenbase.sql.validate.SqlValidatorScope;
+
+import com.google.hive12.common.collect.ImmutableList;
+
+public class DrillSqlAggOperator extends SqlAggFunction {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillSqlAggOperator.class);
+
+  
+  DrillSqlAggOperator(String name, int argCount) {
+    super(name, SqlKind.OTHER_FUNCTION, DynamicReturnType.INSTANCE, null, new Checker(argCount), SqlFunctionCategory.USER_DEFINED_FUNCTION);
+  }
+
+  @Override
+  public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
+    return getAny(validator.getTypeFactory());
+  }
+
+  private RelDataType getAny(RelDataTypeFactory factory){
+    return factory.createSqlType(SqlTypeName.ANY);
+//    return new RelDataTypeDrillImpl(new RelDataTypeHolder(), factory);
+  }
+  
+  @Override
+  public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
+    return ImmutableList.of(typeFactory.createSqlType(SqlTypeName.ANY));
+  }
+
+  @Override
+  public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
+    return getAny(typeFactory);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
index f09e1a1..4531914 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlOperator.java
@@ -18,138 +18,26 @@
 
 package org.apache.drill.exec.planner.sql;
 
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.drill.exec.expr.fn.DrillFuncHolder;
-import org.apache.drill.exec.planner.types.RelDataTypeDrillImpl;
-import org.apache.drill.exec.planner.types.RelDataTypeHolder;
 import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeFactory;
-import org.eigenbase.reltype.RelProtoDataType;
 import org.eigenbase.sql.SqlCall;
-import org.eigenbase.sql.SqlCallBinding;
 import org.eigenbase.sql.SqlFunction;
 import org.eigenbase.sql.SqlFunctionCategory;
-import org.eigenbase.sql.SqlIdentifier;
 import org.eigenbase.sql.SqlKind;
-import org.eigenbase.sql.SqlOperandCountRange;
-import org.eigenbase.sql.SqlOperator;
-import org.eigenbase.sql.SqlSyntax;
-import org.eigenbase.sql.type.ExplicitReturnTypeInference;
-import org.eigenbase.sql.type.SqlOperandCountRanges;
-import org.eigenbase.sql.type.SqlOperandTypeChecker;
 import org.eigenbase.sql.type.SqlTypeName;
 import org.eigenbase.sql.validate.SqlValidator;
 import org.eigenbase.sql.validate.SqlValidatorScope;
 
-import com.google.hive12.common.collect.Lists;
-
 public class DrillSqlOperator extends SqlFunction {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillSqlOperator.class);
 
   DrillSqlOperator(String name, int argCount) {
-    super(name, SqlKind.OTHER_FUNCTION, DYNAMIC_RETURN, null, new Checker(argCount), SqlFunctionCategory.USER_DEFINED_FUNCTION);
-  }
-
-  private static final DynamicReturnType DYNAMIC_RETURN = new DynamicReturnType();
-
-
-  @Override
-  public SqlIdentifier getSqlIdentifier() {
-    return super.getSqlIdentifier();
-  }
-
-  @Override
-  public SqlIdentifier getNameAsId() {
-    return super.getNameAsId();
-  }
-
-  @Override
-  public List<RelDataType> getParamTypes() {
-    return super.getParamTypes();
-  }
-
-  @Override
-  public SqlFunctionCategory getFunctionType() {
-    return super.getFunctionType();
-  }
-
-  @Override
-  public boolean isQuantifierAllowed() {
-    return super.isQuantifierAllowed();
+    super(name, SqlKind.OTHER_FUNCTION, DynamicReturnType.INSTANCE, null, new Checker(argCount), SqlFunctionCategory.USER_DEFINED_FUNCTION);
   }
 
   @Override
   public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
-    return new RelDataTypeDrillImpl(new RelDataTypeHolder(), validator.getTypeFactory());
-//    return validator.getTypeFactory().createSqlType(SqlTypeName.ANY);
-    //return super.deriveType(validator, scope, call);
-  }
-
-  
-  private static class DynamicReturnType extends ExplicitReturnTypeInference {
-    public DynamicReturnType() {
-      super(new DynamicType());
-    }
+    return validator.getTypeFactory().createSqlType(SqlTypeName.ANY);
+//    return new RelDataTypeDrillImpl(new RelDataTypeHolder(), validator.getTypeFactory());
   }
-  private static class DynamicType implements RelProtoDataType {
-
-    @Override
-    public RelDataType apply(RelDataTypeFactory factory) {
-      return factory.createSqlType(SqlTypeName.ANY);
-      //return new RelDataTypeDrillImpl(new RelDataTypeHolder(), factory);
-    }
-
-  }
-
-  private static class FixedRange implements SqlOperandCountRange{
-
-    private final int size;
-    
-    public FixedRange(int size) {
-      super();
-      this.size = size;
-    }
-
-    @Override
-    public boolean isValidCount(int count) {
-      return count == size;
-    }
 
-    @Override
-    public int getMin() {
-      return size;
-    }
-
-    @Override
-    public int getMax() {
-      return size;
-    }
-    
-  }
-  
-  private static class Checker implements SqlOperandTypeChecker {
-    private SqlOperandCountRange range;
-
-    public Checker(int size) {
-      range = new FixedRange(size);
-    }
-
-    @Override
-    public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
-      return true;
-    }
-
-    @Override
-    public SqlOperandCountRange getOperandCountRange() {
-      return range;
-    }
-
-    @Override
-    public String getAllowedSignatures(SqlOperator op, String opName) {
-      return opName + "(Drill - Opaque)";
-    }
-
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
index 676a1e3..30eb605 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
@@ -35,17 +35,16 @@ import org.apache.drill.exec.client.QuerySubmitter;
 import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry;
 import org.apache.drill.exec.ops.QueryContext;
 import org.apache.drill.exec.physical.PhysicalPlan;
-import org.apache.drill.exec.planner.logical.DrillStoreRel;
 import org.apache.drill.exec.planner.logical.DrillImplementor;
 import org.apache.drill.exec.planner.logical.DrillParseContext;
 import org.apache.drill.exec.planner.logical.DrillRel;
 import org.apache.drill.exec.planner.logical.DrillRuleSets;
 import org.apache.drill.exec.planner.logical.DrillScreenRel;
+import org.apache.drill.exec.planner.logical.DrillStoreRel;
 import org.apache.drill.exec.planner.physical.DrillDistributionTrait;
 import org.apache.drill.exec.planner.physical.DrillDistributionTraitDef;
 import org.apache.drill.exec.planner.physical.PhysicalPlanCreator;
 import org.apache.drill.exec.planner.physical.Prel;
-import org.apache.drill.exec.planner.physical.DrillDistributionTrait.DistributionField;
 import org.apache.drill.exec.store.StoragePluginRegistry.DrillSchemaFactory;
 import org.eigenbase.rel.RelCollationTraitDef;
 import org.eigenbase.rel.RelNode;
@@ -58,11 +57,9 @@ import org.eigenbase.sql.SqlExplainLevel;
 import org.eigenbase.sql.SqlKind;
 import org.eigenbase.sql.SqlLiteral;
 import org.eigenbase.sql.SqlNode;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
 import org.eigenbase.sql.parser.SqlParseException;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.ImmutableList;
 
 public class DrillSqlWorker {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillSqlWorker.class);
@@ -78,7 +75,9 @@ public class DrillSqlWorker {
     traitDefs.add(DrillDistributionTraitDef.INSTANCE);    
     traitDefs.add(RelCollationTraitDef.INSTANCE);
     
-    this.planner = Frameworks.getPlanner(Lex.MYSQL, schemaFactory, SqlStdOperatorTable.instance(), traitDefs, RULES);
+    DrillOperatorTable table = new DrillOperatorTable(registry);
+    DrillParserFactory factory = new DrillParserFactory(table);
+    this.planner = Frameworks.getPlanner(Lex.MYSQL, factory, schemaFactory, table, traitDefs, RULES);
 //    this.planner = Frameworks.getPlanner(Lex.MYSQL, SqlParserImpl.FACTORY, schemaFactory, SqlStdOperatorTable.instance(), traitDefs, RULES);
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicReturnType.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicReturnType.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicReturnType.java
new file mode 100644
index 0000000..ee13330
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicReturnType.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql;
+
+import org.eigenbase.sql.type.ExplicitReturnTypeInference;
+
+class DynamicReturnType extends ExplicitReturnTypeInference {
+  
+  public static final DynamicReturnType INSTANCE = new DynamicReturnType();
+  
+  public DynamicReturnType() {
+    super(new DynamicType());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicType.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicType.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicType.java
new file mode 100644
index 0000000..5b65565
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DynamicType.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql;
+
+import org.apache.drill.exec.planner.types.RelDataTypeDrillImpl;
+import org.apache.drill.exec.planner.types.RelDataTypeHolder;
+import org.eigenbase.reltype.RelDataType;
+import org.eigenbase.reltype.RelDataTypeFactory;
+import org.eigenbase.reltype.RelProtoDataType;
+import org.eigenbase.sql.type.SqlTypeName;
+
+class DynamicType implements RelProtoDataType {
+
+  @Override
+  public RelDataType apply(RelDataTypeFactory factory) {
+    return factory.createSqlType(SqlTypeName.ANY);
+//    return new RelDataTypeDrillImpl(new RelDataTypeHolder(), factory);
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/FixedRange.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/FixedRange.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/FixedRange.java
new file mode 100644
index 0000000..d68b8f2
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/FixedRange.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql;
+
+import org.eigenbase.sql.SqlOperandCountRange;
+
+class FixedRange implements SqlOperandCountRange{
+
+  private final int size;
+  
+  public FixedRange(int size) {
+    super();
+    this.size = size;
+  }
+
+  @Override
+  public boolean isValidCount(int count) {
+    return count == size;
+  }
+
+  @Override
+  public int getMin() {
+    return size;
+  }
+
+  @Override
+  public int getMax() {
+    return size;
+  }
+  
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
index 98f8127..ed89301 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
@@ -578,11 +578,11 @@ public class TypeCastRules {
   public static int getCost(FunctionCall call, DrillFuncHolder holder) {
     int cost = 0;
 
-    if (call.args.size() != holder.getParmSize()) {
+    if (call.args.size() != holder.getParamCount()) {
       return -1;
     }
       
-    for (int i = 0; i < holder.getParmSize(); i++) {
+    for (int i = 0; i < holder.getParamCount(); i++) {
       MajorType argType = call.args.get(i).getMajorType();
       MajorType parmType = holder.getParmMajorType(i);
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
index 5b8ccff..6aad394 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
@@ -23,9 +23,9 @@ import java.util.Set;
 
 import net.hydromatic.linq4j.expressions.DefaultExpression;
 import net.hydromatic.linq4j.expressions.Expression;
+import net.hydromatic.optiq.Function;
 import net.hydromatic.optiq.Schema;
 import net.hydromatic.optiq.SchemaPlus;
-import net.hydromatic.optiq.TableFunction;
 
 import org.apache.drill.exec.planner.logical.DrillTable;
 
@@ -55,16 +55,14 @@ public abstract class AbstractSchema implements Schema{
   }
 
   @Override
-  public Collection<TableFunction> getTableFunctions(String name) {
+  public Collection<Function> getFunctions(String name) {
     return Collections.emptyList();
   }
 
   @Override
-  public Set<String> getTableFunctionNames() {
+  public Set<String> getFunctionNames() {
     return Collections.emptySet();
   }
-  
-  
 
   @Override
   public Schema getSubSchema(String name) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
index ce15341..b9d8f33 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
@@ -31,10 +31,10 @@ import java.util.Set;
 import net.hydromatic.linq4j.expressions.DefaultExpression;
 import net.hydromatic.linq4j.expressions.Expression;
 import net.hydromatic.linq4j.function.Function1;
+import net.hydromatic.optiq.Function;
 import net.hydromatic.optiq.Schema;
 import net.hydromatic.optiq.SchemaPlus;
 import net.hydromatic.optiq.Table;
-import net.hydromatic.optiq.TableFunction;
 
 import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.exceptions.ExecutionSetupException;
@@ -221,13 +221,13 @@ public class StoragePluginRegistry implements Iterable<Map.Entry<String, Storage
     }
 
     @Override
-    public Collection<TableFunction> getTableFunctions(String name) {
-      return inner.getTableFunctions(name);
+    public Collection<Function> getFunctions(String name) {
+      return inner.getFunctions(name);
     }
 
     @Override
-    public Set<String> getTableFunctionNames() {
-      return inner.getTableFunctionNames();
+    public Set<String> getFunctionNames() {
+      return inner.getFunctionNames();
     }
 
     @Override
@@ -274,12 +274,12 @@ public class StoragePluginRegistry implements Iterable<Map.Entry<String, Storage
     }
 
     @Override
-    public Collection<TableFunction> getTableFunctions(String name) {
+    public Collection<Function> getFunctions(String name) {
       return Collections.emptyList();
     }
 
     @Override
-    public Set<String> getTableFunctionNames() {
+    public Set<String> getFunctionNames() {
       return Collections.emptySet();
     }
 
@@ -311,7 +311,7 @@ public class StoragePluginRegistry implements Iterable<Map.Entry<String, Storage
     }
 
     @Override
-    public void add(String name, TableFunction table) {
+    public void add(String name, Function table) {
       throw new UnsupportedOperationException();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
index fbea81c..b150cc1 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
@@ -22,9 +22,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import net.hydromatic.optiq.Function;
 import net.hydromatic.optiq.Schema;
 import net.hydromatic.optiq.SchemaPlus;
-import net.hydromatic.optiq.TableFunction;
 
 import org.apache.drill.exec.planner.logical.DrillTable;
 import org.apache.drill.exec.store.AbstractSchema;
@@ -87,13 +87,13 @@ public class FileSystemSchemaFactory implements SchemaFactory{
     }
 
     @Override
-    public Collection<TableFunction> getTableFunctions(String name) {
-      return defaultSchema.getTableFunctions(name);
+    public Collection<Function> getFunctions(String name) {
+      return defaultSchema.getFunctions(name);
     }
 
     @Override
-    public Set<String> getTableFunctionNames() {
-      return defaultSchema.getTableFunctionNames();
+    public Set<String> getFunctionNames() {
+      return defaultSchema.getFunctionNames();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
index f724ca4..0e17f8e 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
@@ -32,7 +32,7 @@ import com.google.common.io.Resources;
 public class BaseTestQuery {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BaseTestQuery.class);
   
-  @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(10000);
+  @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(20000);
   
   protected void test(String sql) throws Exception{
     boolean good = false;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/test/java/org/apache/drill/TestTpchQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestTpchQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestTpchQueries.java
index 8643fa3..fada2f0 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestTpchQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestTpchQueries.java
@@ -36,7 +36,7 @@ public class TestTpchQueries extends BaseTestQuery{
   }
 
   @Test
-  @Ignore // DRILL-436
+  @Ignore
   public void tpch03() throws Exception{
     testSqlFromFile("queries/tpch/03.sql");
   }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62a78667/exec/java-exec/src/test/resources/queries/tpch/01.sql
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/queries/tpch/01.sql b/exec/java-exec/src/test/resources/queries/tpch/01.sql
index b107339..f33416f 100644
--- a/exec/java-exec/src/test/resources/queries/tpch/01.sql
+++ b/exec/java-exec/src/test/resources/queries/tpch/01.sql
@@ -13,8 +13,8 @@ select
   count(*) as count_order
 from
   cp.`tpch/lineitem.parquet`
--- where
---  l_shipdate <= date '1998-12-01' - interval '120' day (3)
+where
+  l_shipdate <= date '1998-12-01' - interval '120' day (3)
 group by
   l_returnflag,
   l_linestatus