Return-Path: X-Original-To: apmail-drill-commits-archive@www.apache.org Delivered-To: apmail-drill-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0935117CC5 for ; Mon, 27 Apr 2015 20:48:00 +0000 (UTC) Received: (qmail 87296 invoked by uid 500); 27 Apr 2015 20:48:00 -0000 Delivered-To: apmail-drill-commits-archive@drill.apache.org Received: (qmail 87249 invoked by uid 500); 27 Apr 2015 20:47:59 -0000 Mailing-List: contact commits-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: commits@drill.apache.org Delivered-To: mailing list commits@drill.apache.org Received: (qmail 87235 invoked by uid 99); 27 Apr 2015 20:47:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2015 20:47:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C0A75E17E1; Mon, 27 Apr 2015 20:47:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mehant@apache.org To: commits@drill.apache.org Date: Mon, 27 Apr 2015 20:47:59 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/4] drill git commit: DRILL-2824: Add checks to ensure function resolution is deterministic Fix NOT function 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 Authored: Sun Apr 19 22:57:21 2015 -0700 Committer: Mehant Baid 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 methods,FunctionCall call) { int bestcost = Integer.MAX_VALUE; int currcost = Integer.MAX_VALUE; DrillFuncHolder bestmatch = null; + final List 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; } }