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:31 UTC
[23/51] [abbrv] git commit: Create CastExpression and traverse
visitor pattern while performing implicit cast in ExpressionTreeMaterializer.
Create CastExpression and traverse visitor pattern while performing implicit cast in ExpressionTreeMaterializer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/443e4e9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/443e4e9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/443e4e9f
Branch: refs/heads/master
Commit: 443e4e9fe012147efc0671f9539052ca2b191aeb
Parents: db0ff63
Author: Mehant Baid <me...@gmail.com>
Authored: Mon Mar 31 21:10:51 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Sat Apr 19 18:07:10 2014 -0700
----------------------------------------------------------------------
.../exec/expr/ExpressionTreeMaterializer.java | 23 +++++++-------------
1 file changed, 8 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/443e4e9f/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 d65ff78..97b965d 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,34 +127,27 @@ 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 (call.args.get(i).equals(NullExpression.INSTANCE) &&
+ if (currentArg.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, call.args.get(i).getMajorType(), matchedFuncHolder.getNullHandling() ==
+ } else if (Types.softEquals(parmType, currentArg.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.
- 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));
+
+ // 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));
}
}
return new DrillFuncHolderExpr(call.getName(), matchedFuncHolder, argsWithCast, call.getPosition());