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-1898: Add compare_to function for boolean type
Date Fri, 26 Dec 2014 05:32:06 GMT
Repository: drill
Updated Branches:
  refs/heads/master e95e43bd0 -> b6b139dea


DRILL-1898: Add compare_to function for boolean type


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

Branch: refs/heads/master
Commit: b6b139deaade3153a2fb1b9a1b6850fe6d9ee800
Parents: e95e43b
Author: Mehant Baid <mehantr@gmail.com>
Authored: Thu Dec 25 04:37:32 2014 -0800
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Thu Dec 25 04:37:32 2014 -0800

----------------------------------------------------------------------
 .../drill/exec/expr/fn/impl/BitFunctions.java   | 13 ++++++++
 .../drill/exec/expr/fn/impl/HashFunctions.java  | 34 ++++++++++++++++++++
 .../exec/fn/impl/TestAggregateFunctions.java    | 10 ++++++
 3 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/b6b139de/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java
index 35e35b0..3fe489f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java
@@ -87,4 +87,17 @@ public class BitFunctions {
     }
   }
 
+  @FunctionTemplate(name = "compare_to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= NullHandling.NULL_IF_NULL)
+  public static class CompareBitBit implements DrillSimpleFunc {
+
+    @Param BitHolder left;
+    @Param BitHolder right;
+    @Output IntHolder out;
+
+    public void setup(RecordBatch b) {}
+
+    public void eval() {
+      out.value = left.value < right.value ? -1 : ((left.value == right.value)? 0 : 1);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/b6b139de/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
index dd8ac88..9658fdb 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
@@ -23,6 +23,7 @@ import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
 import org.apache.drill.exec.expr.annotations.Output;
 import org.apache.drill.exec.expr.annotations.Param;
 import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.BitHolder;
 import org.apache.drill.exec.expr.holders.DateHolder;
 import org.apache.drill.exec.expr.holders.Decimal18Holder;
 import org.apache.drill.exec.expr.holders.Decimal28SparseHolder;
@@ -32,6 +33,7 @@ import org.apache.drill.exec.expr.holders.Float4Holder;
 import org.apache.drill.exec.expr.holders.Float8Holder;
 import org.apache.drill.exec.expr.holders.IntHolder;
 import org.apache.drill.exec.expr.holders.NullableBigIntHolder;
+import org.apache.drill.exec.expr.holders.NullableBitHolder;
 import org.apache.drill.exec.expr.holders.NullableDateHolder;
 import org.apache.drill.exec.expr.holders.NullableDecimal18Holder;
 import org.apache.drill.exec.expr.holders.NullableDecimal28SparseHolder;
@@ -538,4 +540,36 @@ public class HashFunctions {
     }
   }
 
+  @FunctionTemplate(name = "hash", scope = FunctionScope.SIMPLE, nulls = FunctionTemplate.NullHandling.INTERNAL
)
+  public static class NullableBitHash implements DrillSimpleFunc {
+
+    @Param NullableBitHolder in;
+    @Output IntHolder out;
+
+    public void setup(RecordBatch incoming) {
+    }
+
+    public void eval() {
+      if (in.isSet == 0) {
+        out.value = 0;
+      } else {
+        out.value = org.apache.drill.exec.expr.fn.impl.XXHash.hash32(in.value, 0);
+      }
+    }
+  }
+
+  @FunctionTemplate(name = "hash", scope = FunctionScope.SIMPLE, nulls = FunctionTemplate.NullHandling.INTERNAL
)
+  public static class BitHash implements DrillSimpleFunc {
+
+    @Param BitHolder in;
+    @Output IntHolder out;
+
+    public void setup(RecordBatch incoming) {
+    }
+
+    public void eval() {
+      out.value = org.apache.drill.exec.expr.fn.impl.XXHash.hash32(in.value, 0);
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/b6b139de/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
index 14f5a4c..c5cc4f7 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
@@ -36,4 +36,14 @@ public class TestAggregateFunctions extends BaseTestQuery {
         .baselineValues(3l, 4l)
         .build().run();
   }
+
+  @Test
+  public void testCountDistinctOnBoolColumn() throws Exception {
+    testBuilder()
+        .sqlQuery("select count(distinct `bool_val`) as cnt from `sys`.`options`")
+        .ordered()
+        .baselineColumns("cnt")
+        .baselineValues(2l)
+        .build().run();
+  }
 }


Mime
View raw message