aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec
diff options
context:
space:
mode:
authorMehant Baid <mehantr@gmail.com>2014-12-03 17:22:48 -0800
committerMehant Baid <mehantr@gmail.com>2014-12-17 18:52:00 -0800
commitf516a2011fda6b38c2c75db16c08ab65e8569970 (patch)
tree1fa619cfc5e5f4483a45818994ea43dd49a1022e /exec/java-exec
parente07c332139cb211ef49f4ae7977b304a35774a96 (diff)
DRILL-584: Prevent second level of implicit casts to be added in ExpressionTreeMaterializer
Diffstat (limited to 'exec/java-exec')
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java2
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ExactFunctionResolver.java51
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java5
3 files changed, 57 insertions, 1 deletions
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 a2d5e103c..0f4095870 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
@@ -293,7 +293,7 @@ public class ExpressionTreeMaterializer {
}
FunctionCall castCall = new FunctionCall(castFuncName, castArgs, ExpressionPosition.UNKNOWN);
- FunctionResolver resolver = FunctionResolverFactory.getResolver(castCall);
+ FunctionResolver resolver = FunctionResolverFactory.getExactResolver(castCall);
DrillFuncHolder matchedCastFuncHolder = registry.findDrillFunction(resolver, castCall);
if (matchedCastFuncHolder == null) {
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ExactFunctionResolver.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ExactFunctionResolver.java
new file mode 100644
index 000000000..ab6be3314
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ExactFunctionResolver.java
@@ -0,0 +1,51 @@
+/**
+ * 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.resolver;
+
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.exec.expr.fn.DrillFuncHolder;
+
+import java.util.List;
+
+public class ExactFunctionResolver implements FunctionResolver {
+
+
+ /*
+ * This function resolves the input call to a func holder only if all
+ * the input argument types match exactly with the func holder arguments. This is used when we
+ * are trying to inject an implicit cast and do not want to inject another implicit
+ * cast
+ */
+ @Override
+ public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods, FunctionCall call) {
+
+ int currcost;
+
+ for (DrillFuncHolder h : methods) {
+
+ currcost = TypeCastRules.getCost(call, h);
+
+ // Return if we found a function that has an exact match with the input arguments
+ if (currcost == 0){
+ return h;
+ }
+ }
+ // No match found
+ return null;
+ }
+}
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java
index 0205aef9e..b9070afb4 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java
@@ -26,4 +26,9 @@ public class FunctionResolverFactory {
return new DefaultFunctionResolver();
}
+ public static FunctionResolver getExactResolver(FunctionCall call) {
+ return new ExactFunctionResolver();
+ }
+
+
}