drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject drill git commit: DRILL-2014: Add mechanism to detect and prevent registering Drill functions with matching signature. Eliminate existing duplicate functions.
Date Mon, 19 Jan 2015 22:07:45 GMT
Repository: drill
Updated Branches:
  refs/heads/master a418af12b -> 952114fcd


DRILL-2014: Add mechanism to detect and prevent registering Drill functions with matching
signature.
Eliminate existing duplicate functions.


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

Branch: refs/heads/master
Commit: 952114fcdb9b819b546bd0283d30e56027c3f831
Parents: a418af1
Author: Mehant Baid <mehantr@gmail.com>
Authored: Fri Jan 16 14:38:45 2015 -0800
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Mon Jan 19 10:50:37 2015 -0800

----------------------------------------------------------------------
 .../main/codegen/templates/NullOperator.java    |  4 ++--
 .../exec/expr/fn/DrillFunctionRegistry.java     | 25 +++++++++++++++++++-
 .../exec/expr/fn/impl/CastBigIntTimeStamp.java  |  2 +-
 .../apache/drill/exec/expr/fn/impl/IsFalse.java |  4 ++--
 .../drill/exec/expr/fn/impl/IsNotFalse.java     |  4 ++--
 .../drill/exec/expr/fn/impl/IsNotTrue.java      |  4 ++--
 .../apache/drill/exec/expr/fn/impl/IsTrue.java  |  4 ++--
 7 files changed, 35 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/952114fc/exec/java-exec/src/main/codegen/templates/NullOperator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/NullOperator.java b/exec/java-exec/src/main/codegen/templates/NullOperator.java
index 054294b..73eda1a 100644
--- a/exec/java-exec/src/main/codegen/templates/NullOperator.java
+++ b/exec/java-exec/src/main/codegen/templates/NullOperator.java
@@ -35,7 +35,7 @@ import org.apache.drill.exec.record.RecordBatch;
 
 public class ${className} {
 
-  @FunctionTemplate(names = {"isNull", "isnull", "is null"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isnull", "is null"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class IsNull implements DrillSimpleFunc {
 
     @Param ${mode.prefix}${minor.class}Holder input;
@@ -52,7 +52,7 @@ public class ${className} {
     }
   }
 
-  @FunctionTemplate(names = {"isNotNull", "isnotnull", "is not null"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isnotnull", "is not null"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class IsNotNull implements DrillSimpleFunc {
 
     @Param ${mode.prefix}${minor.class}Holder input;

http://git-wip-us.apache.org/repos/asf/drill/blob/952114fc/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
index 27cd6dc..00aaec6 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
@@ -18,6 +18,7 @@
 package org.apache.drill.exec.expr.fn;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -40,6 +41,12 @@ public class DrillFunctionRegistry {
 
   private ArrayListMultimap<String, DrillFuncHolder> methods = ArrayListMultimap.create();
 
+  /* Hash map to prevent registering functions with exactly matching signatures
+   * key: Function Name + Input's Major Type
+   * Value: Class name where function is implemented
+   */
+  private HashMap<String, String> functionSignatureMap = new HashMap<>();
+
   public DrillFunctionRegistry(DrillConfig config) {
     FunctionConverter converter = new FunctionConverter();
     Set<Class<? extends DrillFunc>> providerClasses = PathScanner.scanForImplementations(DrillFunc.class,
config.getStringList(ExecConstants.FUNCTION_PACKAGES));
@@ -48,8 +55,24 @@ public class DrillFunctionRegistry {
       if (holder != null) {
         // register handle for each name the function can be referred to
         String[] names = holder.getRegisteredNames();
+
+        // Create the string for input types
+        String functionInput = "";
+        for (DrillFuncHolder.ValueReference ref : holder.parameters) {
+          functionInput += ref.getType().toString();
+        }
         for (String name : names) {
-          methods.put(name.toLowerCase(), holder);
+          String functionName = name.toLowerCase();
+          methods.put(functionName, holder);
+          String functionSignature = functionName + functionInput;
+
+          String existingImplementation;
+          if ((existingImplementation = functionSignatureMap.get(functionSignature)) != null)
{
+            throw new AssertionError(String.format("Conflicting functions with similar signature
found. Func Name: %s, Class name: %s " +
+                " Class name: %s", functionName, clazz.getName(), existingImplementation));
+          } else {
+            functionSignatureMap.put(functionSignature, clazz.getName());
+          }
         }
       } else {
         logger.warn("Unable to initialize function for class {}", clazz.getName());

http://git-wip-us.apache.org/repos/asf/drill/blob/952114fc/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastBigIntTimeStamp.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastBigIntTimeStamp.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastBigIntTimeStamp.java
index c53d747..ea92f3c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastBigIntTimeStamp.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CastBigIntTimeStamp.java
@@ -27,7 +27,7 @@ import org.apache.drill.exec.expr.holders.TimeStampHolder;
 import org.apache.drill.exec.record.RecordBatch;
 
 @SuppressWarnings("unused")
-@FunctionTemplate(names = {"castTIMESTAMP", "to_timestamp"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls= NullHandling.NULL_IF_NULL)
+@FunctionTemplate(name = "castTIMESTAMP", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls= NullHandling.NULL_IF_NULL)
 public class CastBigIntTimeStamp implements DrillSimpleFunc {
 
   @Param

http://git-wip-us.apache.org/repos/asf/drill/blob/952114fc/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
index 72378e2..12a2205 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
@@ -28,7 +28,7 @@ import org.apache.drill.exec.record.RecordBatch;
 
 public class IsFalse {
 
-  @FunctionTemplate(names = {"isFalse", "isfalse", "is false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isfalse", "is false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Optional implements DrillSimpleFunc {
 
     @Param NullableBitHolder in;
@@ -45,7 +45,7 @@ public class IsFalse {
     }
   }
 
-  @FunctionTemplate(names = {"isFalse", "isfalse", "is false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isfalse", "is false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Required implements DrillSimpleFunc {
 
     @Param BitHolder in;

http://git-wip-us.apache.org/repos/asf/drill/blob/952114fc/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
index 07f420c..5b8a9bd 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
@@ -28,7 +28,7 @@ import org.apache.drill.exec.record.RecordBatch;
 
 public class IsNotFalse {
 
-  @FunctionTemplate(names = {"isNotFalse", "isnotfalse", "is not false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isnotfalse", "is not false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Optional implements DrillSimpleFunc {
 
     @Param NullableBitHolder in;
@@ -45,7 +45,7 @@ public class IsNotFalse {
     }
   }
 
-  @FunctionTemplate(names = {"isNotFalse", "isnotfalse", "is not false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isnotfalse", "is not false"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Required implements DrillSimpleFunc {
 
     @Param BitHolder in;

http://git-wip-us.apache.org/repos/asf/drill/blob/952114fc/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
index a7a87a3..1485e8c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
@@ -28,7 +28,7 @@ import org.apache.drill.exec.record.RecordBatch;
 
 public class IsNotTrue {
 
-  @FunctionTemplate(names = {"isNotTrue", "isnottrue", "is not true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isnottrue", "is not true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Optional implements DrillSimpleFunc {
 
     @Param NullableBitHolder in;
@@ -45,7 +45,7 @@ public class IsNotTrue {
     }
   }
 
-  @FunctionTemplate(names = {"isNotTrue", "isnottrue", "is not true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"isnottrue", "is not true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Required implements DrillSimpleFunc {
 
     @Param BitHolder in;

http://git-wip-us.apache.org/repos/asf/drill/blob/952114fc/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
index d534b7d..2fd65e3 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
@@ -28,7 +28,7 @@ import org.apache.drill.exec.record.RecordBatch;
 
 public class IsTrue {
 
-  @FunctionTemplate(names = {"isTrue", "istrue", "is true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"istrue", "is true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Optional implements DrillSimpleFunc {
 
     @Param NullableBitHolder in;
@@ -45,7 +45,7 @@ public class IsTrue {
     }
   }
 
-  @FunctionTemplate(names = {"isTrue", "istrue", "is true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
+  @FunctionTemplate(names = {"istrue", "is true"}, scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
   public static class Required implements DrillSimpleFunc {
 
     @Param BitHolder in;


Mime
View raw message