drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject [1/4] drill git commit: DRILL-2824: Add checks to ensure function resolution is deterministic Fix NOT function
Date Mon, 27 Apr 2015 20:47:59 GMT
Repository: drill
Updated Branches:
  refs/heads/master 7289cabb5 -> 3689522d4


DRILL-2824: Add checks to ensure function resolution is deterministic
Fix NOT function


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

Branch: refs/heads/master
Commit: 5189635f2101ea4dc1d099001966bdfc4192bdad
Parents: 70b1a1f
Author: Mehant Baid <mehantr@gmail.com>
Authored: Sun Apr 19 22:57:21 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Mon Apr 27 13:08:17 2015 -0700

----------------------------------------------------------------------
 .../org/apache/drill/exec/expr/fn/impl/Not.java | 18 +--------------
 .../exec/resolver/DefaultFunctionResolver.java  | 24 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/5189635f/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Not.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Not.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Not.java
index a45f9dd..78390cc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Not.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Not.java
@@ -20,28 +20,12 @@ package org.apache.drill.exec.expr.fn.impl;
 
 import org.apache.drill.exec.expr.DrillSimpleFunc;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
 import org.apache.drill.exec.expr.annotations.Output;
 import org.apache.drill.exec.expr.annotations.Param;
 import org.apache.drill.exec.expr.holders.BitHolder;
-import org.apache.drill.exec.expr.holders.NullableBitHolder;
 
 public class Not {
-
-  @FunctionTemplate(names = {"not"}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= NullHandling.NULL_IF_NULL)
-  public static class Optional implements DrillSimpleFunc {
-
-    @Param NullableBitHolder in;
-    @Output BitHolder out;
-
-    public void setup() { }
-
-    public void eval() {
-      out.value = (in.value == 0 ? 1 : 0);
-    }
-  }
-
-  @FunctionTemplate(names = {"not"}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"not"}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
   public static class Required implements DrillSimpleFunc {
 
     @Param BitHolder in;

http://git-wip-us.apache.org/repos/asf/drill/blob/5189635f/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java
index 4f128b3..6904272 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java
@@ -18,19 +18,24 @@
 
 package org.apache.drill.exec.resolver;
 
+import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.drill.common.expression.FunctionCall;
 import org.apache.drill.exec.expr.fn.DrillFuncHolder;
+import org.apache.drill.exec.util.AssertionUtil;
 
 public class DefaultFunctionResolver implements FunctionResolver {
 
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DefaultFunctionResolver.class);
+
   @Override
   public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods,FunctionCall call)
{
 
     int bestcost = Integer.MAX_VALUE;
     int currcost = Integer.MAX_VALUE;
     DrillFuncHolder bestmatch = null;
+    final List<DrillFuncHolder> bestMatchAlternatives = new LinkedList<>();
 
     for (DrillFuncHolder h : methods) {
 
@@ -44,6 +49,10 @@ public class DefaultFunctionResolver implements FunctionResolver {
       if (currcost < bestcost) {
         bestcost = currcost;
         bestmatch = h;
+        bestMatchAlternatives.clear();
+      } else if (currcost == bestcost) {
+        // keep log of different function implementations that have the same best cost
+        bestMatchAlternatives.add(h);
       }
     }
 
@@ -52,6 +61,21 @@ public class DefaultFunctionResolver implements FunctionResolver {
       //TODO: raise exception here?
       return null;
     } else {
+      if (AssertionUtil.isAssertionsEnabled() && bestMatchAlternatives.size() >
0) {
+        /*
+         * There are other alternatives to the best match function which could have been
selected
+         * Log the possible functions and the chose implementation and raise an exception
+         */
+        logger.error("Chosen function impl: " + bestmatch.toString());
+
+        // printing the possible matches
+        logger.error("Printing all the possible functions that could have matched: ");
+        for (DrillFuncHolder holder: bestMatchAlternatives) {
+          logger.error(holder.toString());
+        }
+
+        throw new AssertionError("Multiple functions with best cost found");
+      }
       return bestmatch;
     }
   }


Mime
View raw message