Revert "Create CastExpression and traverse visitor pattern while performing 
implicit cast in ExpressionTreeMaterializer."

This reverts commit b7c76c218a7359e99140bc8ee8eeef65f950d7ee.


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

Branch: refs/heads/master
Commit: eeb853573fbb908f765c6718b193b96d6e829531
Parents: 342f3fd
Author: Jinfeng Ni <[email protected]>
Authored: Tue Apr 1 15:08:16 2014 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Sat Apr 19 18:07:10 2014 -0700

----------------------------------------------------------------------
 .../exec/expr/ExpressionTreeMaterializer.java   | 23 +++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/eeb85357/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 97b965d..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
@@ -127,27 +127,34 @@ public class ExpressionTreeMaterializer {
       if (matchedFuncHolder!=null) {
         //Compare parm type against arg type. Insert cast on top of arg, 
whenever necessary.
         for (int i = 0; i < call.args.size(); ++i) {
-          LogicalExpression currentArg = call.args.get(i);
-
           TypeProtos.MajorType parmType = 
matchedFuncHolder.getParmMajorType(i);
 
           //Case 1: If  1) the argument is NullExpression
           //            2) the parameter of matchedFuncHolder allows null 
input, or func's null_handling is NULL_IF_NULL (means null and non-null are 
exchangable).
           //        then replace NullExpression with a TypedNullConstant
-          if (currentArg.equals(NullExpression.INSTANCE) &&
+          if (call.args.get(i).equals(NullExpression.INSTANCE) &&
             ( parmType.getMode().equals(TypeProtos.DataMode.OPTIONAL) ||
               matchedFuncHolder.getNullHandling() == 
FunctionTemplate.NullHandling.NULL_IF_NULL)) {
             argsWithCast.add(new TypedNullConstant(parmType));
-          } else if (Types.softEquals(parmType, currentArg.getMajorType(), 
matchedFuncHolder.getNullHandling() ==
+          } else if (Types.softEquals(parmType, 
call.args.get(i).getMajorType(), matchedFuncHolder.getNullHandling() ==
             FunctionTemplate.NullHandling.NULL_IF_NULL)) {
             //Case 2: argument and parameter matches. Do nothing.
             argsWithCast.add(call.args.get(i));
           } else {
             //Case 3: insert cast if param type is different from arg type.
-
-            // Create the desired output type and CasExpression and traverse 
the visitor pattern
-            CastExpression castExpression = new CastExpression(currentArg, 
parmType, ExpressionPosition.UNKNOWN);
-            argsWithCast.add(castExpression.accept(this, registry));
+            String castFuncName = 
CastFunctions.getCastFunc(parmType.getMinorType());
+            List<LogicalExpression> castArgs = Lists.newArrayList();
+            castArgs.add(call.args.get(i));  //input_expr
+            FunctionCall castCall = new FunctionCall(castFuncName, castArgs, 
ExpressionPosition.UNKNOWN);
+            DrillFuncHolder matchedCastFuncHolder = resolver.getBestMatch(
+              registry.getDrillRegistry().getMethods().get(castFuncName), 
castCall);
+
+            if (matchedCastFuncHolder == null) {
+              logFunctionResolutionError(errorCollector, castCall);
+              return NullExpression.INSTANCE;
+            }
+
+            argsWithCast.add(new DrillFuncHolderExpr(call.getName(), 
matchedCastFuncHolder, castArgs, ExpressionPosition.UNKNOWN));
           }
         }
         return new DrillFuncHolderExpr(call.getName(), matchedFuncHolder, 
argsWithCast, call.getPosition());

Reply via email to