DRILL-772 :  Change comparison operator to use NULL_IF_NULL policy, when inputs 
are nullable type.


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

Branch: refs/heads/master
Commit: 42057800b1f2a4f1bdf771760c9c33a822fc435b
Parents: 27d3e71
Author: Jinfeng Ni <[email protected]>
Authored: Tue Jun 17 16:31:32 2014 -0700
Committer: Jinfeng Ni <[email protected]>
Committed: Wed Jun 18 07:13:56 2014 -0700

----------------------------------------------------------------------
 .../codegen/templates/ComparisonFunctions.java  | 109 +++----------------
 1 file changed, 15 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/42057800/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java 
b/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
index b57a37f..df60650 100644
--- a/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/ComparisonFunctions.java
@@ -96,6 +96,7 @@ 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.*;
@@ -117,8 +118,10 @@ public class GCompare${left}${right}{
         <@compareBlock mode=type.mode left=left right=right output="out.value" 
nullCompare=true />
       }
   }
-  
-  @FunctionTemplate(names = {"less_than", "<"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE)
+
+  <#if ! left?starts_with("Nullable")  &&  ! right?starts_with("Nullable") >
+
+  @FunctionTemplate(names = {"less_than", "<"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class LessThan${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -128,20 +131,7 @@ public class GCompare${left}${right}{
       public void setup(RecordBatch b) {}
 
       public void eval() {
-        sout: {
-        <#if left?starts_with("Nullable")>
-        if(left.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
-        <#if right?starts_with("Nullable")>
-        if(right.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
-
+        
         <#if type.mode == "var" >
         int cmp;
         <@compareBlock mode=type.mode left=left right=right output="cmp" 
nullCompare=false/>
@@ -150,11 +140,10 @@ public class GCompare${left}${right}{
         out.value = left.value < right.value ? 1 : 0;
         </#if>
 
-        }
       }
   }
   
-  @FunctionTemplate(names = {"less_than_or_equal_to", "<="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"less_than_or_equal_to", "<="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class LessThanE${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -164,19 +153,6 @@ public class GCompare${left}${right}{
       public void setup(RecordBatch b) {}
 
       public void eval() {
-        sout: {
-        <#if left?starts_with("Nullable")>
-        if(left.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
-        <#if right?starts_with("Nullable")>
-        if(right.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
         
         <#if type.mode == "var" >
         int cmp;
@@ -186,11 +162,10 @@ public class GCompare${left}${right}{
         out.value = left.value <= right.value ? 1 : 0;
         </#if>
 
-        }
     }
   }
   
-  @FunctionTemplate(names = {"greater_than", ">"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"greater_than", ">"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class GreaterThan${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -200,19 +175,6 @@ public class GCompare${left}${right}{
       public void setup(RecordBatch b) {}
 
       public void eval() {
-        sout: {
-        <#if left?starts_with("Nullable")>
-        if(left.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
-        <#if right?starts_with("Nullable")>
-        if(right.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
         
         <#if type.mode == "var" >
         int cmp;
@@ -222,11 +184,10 @@ public class GCompare${left}${right}{
         out.value = left.value > right.value ? 1 : 0;
         </#if>
 
-        }
     }
   }
   
-  @FunctionTemplate(names = {"greater_than_or_equal_to", ">="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"greater_than_or_equal_to", ">="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class GreaterThanE${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -236,19 +197,6 @@ public class GCompare${left}${right}{
       public void setup(RecordBatch b) {}
 
       public void eval() {
-        sout: {
-        <#if left?starts_with("Nullable")>
-        if(left.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
-        <#if right?starts_with("Nullable")>
-        if(right.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
         
         <#if type.mode == "var" >            
         int cmp;
@@ -258,11 +206,10 @@ public class GCompare${left}${right}{
         out.value = left.value >= right.value ? 1 : 0;
         </#if>
 
-        }
       }
   }
   
-  @FunctionTemplate(names = {"equal","==","="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"equal","==","="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class Equals${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -272,19 +219,6 @@ public class GCompare${left}${right}{
       public void setup(RecordBatch b) {}
 
       public void eval() {
-        sout: {
-          <#if left?starts_with("Nullable")>
-          if(left.isSet ==0){
-            out.value = 0;
-            break sout;
-          }
-          </#if>
-          <#if right?starts_with("Nullable")>
-          if(right.isSet ==0){
-            out.value = 0;
-            break sout;
-          }
-          </#if>
         
           <#if type.mode == "var" >
 outside: 
@@ -310,11 +244,10 @@ outside:
           out.value = left.value == right.value ? 1 : 0;
           </#if>
 
-        }
       }
   }
   
-  @FunctionTemplate(names = {"not_equal","<>","!="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE)
+  @FunctionTemplate(names = {"not_equal","<>","!="}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
   public static class NotEquals${left}${right} implements DrillSimpleFunc {
 
       @Param ${left}Holder left;
@@ -324,19 +257,6 @@ outside:
       public void setup(RecordBatch b) {}
 
       public void eval() {
-        sout: {
-        <#if left?starts_with("Nullable")>
-        if(left.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
-        <#if right?starts_with("Nullable")>
-        if(right.isSet ==0){
-          out.value = 0;
-          break sout;
-        }
-        </#if>
         
         <#if type.mode == "var" >            
         int cmp;
@@ -345,11 +265,12 @@ outside:
         <#else>
         out.value = left.value != right.value ? 1 : 0;
         </#if>
-        
-        }
-        
+                
       }
   }
+
+  </#if>
+
 }
 </#list>
 </#list>

Reply via email to