Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 09E60200B9C for ; Mon, 10 Oct 2016 23:46:56 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 08708160AD1; Mon, 10 Oct 2016 21:46:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 98D5D160AE1 for ; Mon, 10 Oct 2016 23:46:54 +0200 (CEST) Received: (qmail 41348 invoked by uid 500); 10 Oct 2016 21:46:51 -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 41254 invoked by uid 99); 10 Oct 2016 21:46:51 -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, 10 Oct 2016 21:46:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5CB0CE04AF; Mon, 10 Oct 2016 21:46:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sudheesh@apache.org To: commits@drill.apache.org Date: Mon, 10 Oct 2016 21:46:51 -0000 Message-Id: In-Reply-To: <8ca8df875a54416f92f29fdf76ea650c@git.apache.org> References: <8ca8df875a54416f92f29fdf76ea650c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] drill git commit: DRILL-4618: Correct the usage of random flag in Hive function registry archived-at: Mon, 10 Oct 2016 21:46:56 -0000 DRILL-4618: Correct the usage of random flag in Hive function registry + Function visitor should not use previous function holder if this function is non-deterministic closes #509 Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/50dea898 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/50dea898 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/50dea898 Branch: refs/heads/master Commit: 50dea8984bf145337dd34bf08c99ea3dff70e791 Parents: 4edabe7 Author: chunhui-shi Authored: Wed May 25 23:22:01 2016 -0700 Committer: Sudheesh Katkam Committed: Mon Oct 10 11:57:37 2016 -0700 ---------------------------------------------------------------------- .../exec/expr/fn/HiveFunctionRegistry.java | 22 +++++++++++++++++++- .../drill/exec/fn/hive/TestInbuiltHiveUDFs.java | 10 +++++++++ .../apache/drill/exec/expr/EqualityVisitor.java | 3 +++ .../drill/exec/expr/EvaluationVisitor.java | 2 +- .../org/apache/drill/TestFunctionsQuery.java | 11 ++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/50dea898/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/expr/fn/HiveFunctionRegistry.java ---------------------------------------------------------------------- diff --git a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/expr/fn/HiveFunctionRegistry.java b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/expr/fn/HiveFunctionRegistry.java index c716e9e..8d8707e 100644 --- a/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/expr/fn/HiveFunctionRegistry.java +++ b/contrib/storage-hive/core/src/main/java/org/apache/drill/exec/expr/fn/HiveFunctionRegistry.java @@ -18,6 +18,7 @@ package org.apache.drill.exec.expr.fn; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.apache.calcite.rel.type.RelDataType; @@ -73,6 +74,25 @@ public class HiveFunctionRegistry implements PluggableFunctionRegistry{ for (Class clazz : udfClasses) { register(clazz, methodsUDF); } + + if (logger.isTraceEnabled()) { + StringBuilder allHiveFunctions = new StringBuilder(); + for (Map.Entry> method : methodsGenericUDF.entries()) { + allHiveFunctions.append(method.toString()).append("\n"); + } + logger.trace("Registered Hive GenericUDFs: [\n{}]", allHiveFunctions); + + StringBuilder allUDFs = new StringBuilder(); + for (Map.Entry> method : methodsUDF.entries()) { + allUDFs.append(method.toString()).append("\n"); + } + logger.trace("Registered Hive UDFs: [\n{}]", allUDFs); + StringBuilder allNonDeterministic = new StringBuilder(); + for (Class clz : nonDeterministicUDFs) { + allNonDeterministic.append(clz.toString()).append("\n"); + } + logger.trace("Registered Hive nonDeterministicUDFs: [\n{}]", allNonDeterministic); + } } @Override @@ -96,7 +116,7 @@ public class HiveFunctionRegistry implements PluggableFunctionRegistry{ } UDFType type = clazz.getAnnotation(UDFType.class); - if (type != null && type.deterministic()) { + if (type != null && !type.deterministic()) { nonDeterministicUDFs.add(clazz); } http://git-wip-us.apache.org/repos/asf/drill/blob/50dea898/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/fn/hive/TestInbuiltHiveUDFs.java ---------------------------------------------------------------------- diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/fn/hive/TestInbuiltHiveUDFs.java b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/fn/hive/TestInbuiltHiveUDFs.java index 9e13844..0eb4116 100644 --- a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/fn/hive/TestInbuiltHiveUDFs.java +++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/fn/hive/TestInbuiltHiveUDFs.java @@ -94,4 +94,14 @@ public class TestInbuiltHiveUDFs extends HiveTestBase { .go(); } + @Test // DRILL-4618 + public void testRand() throws Exception { + String query = "select 2*rand()=2*rand() col1 from (values (1))"; + testBuilder() + .sqlQuery(query) + .unOrdered() + .baselineColumns("col1") + .baselineValues(false) + .go(); + } } http://git-wip-us.apache.org/repos/asf/drill/blob/50dea898/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java index 7945bb4..433e95f 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EqualityVisitor.java @@ -75,6 +75,9 @@ class EqualityVisitor extends AbstractExprVisitor generator) throws RuntimeException { HoldingContainer hc = getPrevious(holder, generator.getMappingSet()); - if (hc == null) { + if (hc == null || holder.isRandom()) { hc = super.visitFunctionHolderExpression(holder, generator); put(holder, hc, generator.getMappingSet()); } http://git-wip-us.apache.org/repos/asf/drill/blob/50dea898/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java b/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java index 475d08a..8be8781 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java +++ b/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java @@ -912,4 +912,15 @@ public class TestFunctionsQuery extends BaseTestQuery { .baselineValues("foo") .go(); } + + @Test + public void testRandom() throws Exception { + String query = "select 2*random()=2*random() as col1 from (values (1))"; + testBuilder() + .sqlQuery(query) + .unOrdered() + .baselineColumns("col1") + .baselineValues(false) + .go(); + } }