drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudhe...@apache.org
Subject [2/2] drill git commit: DRILL-4618: Correct the usage of random flag in Hive function registry
Date Mon, 10 Oct 2016 21:46:51 GMT
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 <cshi@maprtech.com>
Authored: Wed May 25 23:22:01 2016 -0700
Committer: Sudheesh Katkam <skatkam@maprtech.com>
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<? extends UDF> clazz : udfClasses) {
       register(clazz, methodsUDF);
     }
+
+    if (logger.isTraceEnabled()) {
+      StringBuilder allHiveFunctions = new StringBuilder();
+      for (Map.Entry<String, Class<? extends GenericUDF>> method : methodsGenericUDF.entries())
{
+        allHiveFunctions.append(method.toString()).append("\n");
+      }
+      logger.trace("Registered Hive GenericUDFs: [\n{}]", allHiveFunctions);
+
+      StringBuilder allUDFs = new StringBuilder();
+      for (Map.Entry<String, Class<? extends UDF>> 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<Boolean,LogicalExpression,Runt
     if (!holder.getName().equals(((FunctionHolderExpression) value).getName())) {
       return false;
     }
+    if (holder.isRandom()) {
+      return false;
+    }
     return checkChildren(holder, value);
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/50dea898/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
index 055ab84..53bd8b8 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
@@ -811,7 +811,7 @@ public class EvaluationVisitor {
     @Override
     public HoldingContainer visitFunctionHolderExpression(FunctionHolderExpression holder,
ClassGenerator<?> 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();
+  }
 }


Mime
View raw message