drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [04/12] git commit: DRILL-923: Bit-wise and logical Aggregate functions
Date Thu, 03 Jul 2014 17:45:17 GMT
DRILL-923: Bit-wise and logical Aggregate functions


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

Branch: refs/heads/master
Commit: 1e420874a358a0696519f994728b47ab2c4f3ac5
Parents: 67c303c
Author: Yash Sharma <yash.sharma@snapdeal.com>
Authored: Tue Jun 17 21:36:32 2014 +0530
Committer: Aditya Kishore <aditya@maprtech.com>
Committed: Wed Jul 2 23:06:49 2014 -0700

----------------------------------------------------------------------
 .../common/expression/fn/CastFunctions.java     |   1 +
 exec/java-exec/src/main/codegen/config.fmpp     |   1 +
 .../codegen/data/AggrBitwiseLogicalTypes.tdd    |  58 ++++++
 exec/java-exec/src/main/codegen/data/Casts.tdd  |   2 +
 .../AggrBitwiseLogicalTypeFunctions.java        | 132 ++++++++++++
 .../exec/expr/fn/impl/BooleanAggrFunctions.java | 202 +++++++++++++++++++
 .../exec/fn/impl/TestNewAggregateFunctions.java |  90 +++++++++
 .../resources/functions/test_logical_aggr.json  |  80 ++++++++
 .../src/test/resources/logical_aggr_input.json  |   4 +
 9 files changed, 570 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
b/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
index b76708d..e6a814f 100644
--- a/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
+++ b/common/src/main/java/org/apache/drill/common/expression/fn/CastFunctions.java
@@ -29,6 +29,7 @@ public class CastFunctions {
   static {
     TYPE2FUNC.put(MinorType.BIGINT, "castBIGINT");
     TYPE2FUNC.put(MinorType.INT, "castINT");
+    TYPE2FUNC.put(MinorType.TINYINT, "castTINYINT");
     TYPE2FUNC.put(MinorType.FLOAT4, "castFLOAT4");
     TYPE2FUNC.put(MinorType.FLOAT8, "castFLOAT8");
     TYPE2FUNC.put(MinorType.VARCHAR, "castVARCHAR");

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/main/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/config.fmpp b/exec/java-exec/src/main/codegen/config.fmpp
index e9293a8..83a0b70 100644
--- a/exec/java-exec/src/main/codegen/config.fmpp
+++ b/exec/java-exec/src/main/codegen/config.fmpp
@@ -26,6 +26,7 @@ data: {
     aggrtypes3: tdd(../data/AggrTypes3.tdd),
     covarTypes: tdd(../data/CovarTypes.tdd),
     corrTypes: tdd(../data/CorrelationTypes.tdd),
+    logicalTypes: tdd(../data/AggrBitwiseLogicalTypes.tdd),
     date: tdd(../data/DateTypes.tdd),
     extract: tdd(../data/ExtractTypes.tdd),
     parser: tdd(../data/Parser.tdd),

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/main/codegen/data/AggrBitwiseLogicalTypes.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/AggrBitwiseLogicalTypes.tdd b/exec/java-exec/src/main/codegen/data/AggrBitwiseLogicalTypes.tdd
new file mode 100644
index 0000000..2b72abd
--- /dev/null
+++ b/exec/java-exec/src/main/codegen/data/AggrBitwiseLogicalTypes.tdd
@@ -0,0 +1,58 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http:# www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+{
+  logicalAggrTypes: [
+    {className: "BitwiseAnd", funcName: "bit_and", aliasName: "every", types: [
+     {inputType: "BigInt", outputType: "BigInt", maxval: "Integer"},
+      {inputType: "NullableBigInt", outputType: "BigInt", maxval: "Integer"},
+      {inputType: "Int", outputType: "Int", maxval: "Integer"},
+      {inputType: "NullableInt", outputType: "Int", maxval: "Integer"},
+      {inputType: "SmallInt", outputType: "SmallInt", maxval: "Byte", extraCast: "short"},
+      {inputType: "NullableSmallInt", outputType: "SmallInt", maxval: "Byte", extraCast:
"short"},
+      {inputType: "TinyInt", outputType: "TinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "NullableTinyInt", outputType: "TinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "UInt1", outputType: "Int", maxval: "Byte"},
+      {inputType: "NullableUInt1", outputType: "Int", maxval: "Byte"},
+      {inputType: "UInt2", outputType: "Int", maxval: "Character"},
+      {inputType: "NullableUInt2", outputType: "Int", maxval: "Character"},
+      {inputType: "UInt4", outputType: "Int", maxval: "Integer"},
+      {inputType: "NullableUInt4", outputType: "Int", maxval: "Integer"},
+      {inputType: "UInt8", outputType: "UInt8", maxval: "Long"},
+      {inputType: "NullableUInt8", outputType: "UInt8", maxval: "Long"}
+     ]
+   },
+   {className: "BitwiseOr", funcName: "bit_or", aliasName: "", types: [
+     {inputType: "BigInt", outputType: "BigInt", maxval: "Integer"},
+      {inputType: "NullableBigInt", outputType: "BigInt", maxval: "Integer"},
+      {inputType: "Int", outputType: "Int", maxval: "Integer"},
+      {inputType: "NullableInt", outputType: "Int", maxval: "Integer"},
+      {inputType: "SmallInt", outputType: "SmallInt", maxval: "Byte", extraCast: "short"},
+      {inputType: "NullableSmallInt", outputType: "SmallInt", maxval: "Byte", extraCast:
"short"},
+      {inputType: "TinyInt", outputType: "TinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "NullableTinyInt", outputType: "TinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "UInt1", outputType: "Int", maxval: "Byte"},
+      {inputType: "NullableUInt1", outputType: "Int", maxval: "Byte"},
+      {inputType: "UInt2", outputType: "Int", maxval: "Character"},
+      {inputType: "NullableUInt2", outputType: "Int", maxval: "Character"},
+      {inputType: "UInt4", outputType: "Int", maxval: "Integer"},
+      {inputType: "NullableUInt4", outputType: "Int", maxval: "Integer"},
+      {inputType: "UInt8", outputType: "UInt8", maxval: "Long"},
+      {inputType: "NullableUInt8", outputType: "UInt8", maxval: "Long"}
+     ]
+   }
+  ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/main/codegen/data/Casts.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/Casts.tdd b/exec/java-exec/src/main/codegen/data/Casts.tdd
index e49df93..ba8b6d6 100644
--- a/exec/java-exec/src/main/codegen/data/Casts.tdd
+++ b/exec/java-exec/src/main/codegen/data/Casts.tdd
@@ -28,6 +28,8 @@
     {to: "BigInt", from: "Float4" , explicit: "long", major: "Fixed"},
     {to: "Int", from: "Float8" , explicit: "int", major: "Fixed"},
     {to: "BigInt", from: "Float8" , explicit: "long", major: "Fixed"},
+    {from: "TinyInt", to: "Bit", major: "Fixed"},
+    {from: "Bit", to: "TinyInt", explicit: "byte", major: "Fixed"},
     
     {from: "VarChar", to: "BigInt", major: "SrcVarlen", javaType: "Long", primeType: "long"},
     {from: "VarChar", to: "Int", major: "SrcVarlen", javaType:"Integer", primeType:"int"},

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/main/codegen/templates/AggrBitwiseLogicalTypeFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/AggrBitwiseLogicalTypeFunctions.java
b/exec/java-exec/src/main/codegen/templates/AggrBitwiseLogicalTypeFunctions.java
new file mode 100644
index 0000000..e659d32
--- /dev/null
+++ b/exec/java-exec/src/main/codegen/templates/AggrBitwiseLogicalTypeFunctions.java
@@ -0,0 +1,132 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+<@pp.dropOutputFile />
+
+
+
+<#list logicalTypes.logicalAggrTypes as aggrtype>
+<@pp.changeOutputFile name="/org/apache/drill/exec/expr/fn/impl/gaggr/${aggrtype.className}Functions.java"
/>
+
+<#include "/@includes/license.ftl" />
+
+<#-- A utility class that is used to generate java code for aggr functions bit_and / bit_or
-->
+
+/*
+ * This class is automatically generated from AggrBitwiseLogicalTypes.tdd using FreeMarker.
+ */
+
+package org.apache.drill.exec.expr.fn.impl.gaggr;
+
+import org.apache.drill.exec.expr.DrillAggFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+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.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.NullableBigIntHolder;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.NullableIntHolder;
+import org.apache.drill.exec.expr.holders.SmallIntHolder;
+import org.apache.drill.exec.expr.holders.NullableSmallIntHolder;
+import org.apache.drill.exec.expr.holders.TinyIntHolder;
+import org.apache.drill.exec.expr.holders.NullableTinyIntHolder;
+import org.apache.drill.exec.expr.holders.UInt1Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt1Holder;
+import org.apache.drill.exec.expr.holders.UInt2Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt2Holder;
+import org.apache.drill.exec.expr.holders.UInt4Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt4Holder;
+import org.apache.drill.exec.expr.holders.UInt8Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt8Holder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@SuppressWarnings("unused")
+
+public class ${aggrtype.className}Functions {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(${aggrtype.className}Functions.class);
+
+<#list aggrtype.types as type>
+
+<#if aggrtype.aliasName == "">
+@FunctionTemplate(name = "${aggrtype.funcName}", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
+<#else>
+@FunctionTemplate(names = {"${aggrtype.funcName}", "${aggrtype.aliasName}"}, scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
+</#if>
+public static class ${type.inputType}${aggrtype.className} implements DrillAggFunc{
+
+  @Param ${type.inputType}Holder in;
+  @Workspace ${type.outputType}Holder inter;
+  @Output ${type.outputType}Holder out;
+
+  public void setup(RecordBatch b) {
+  inter = new ${type.outputType}Holder();
+
+    // Initialize the workspace variables
+  <#if aggrtype.funcName == "bit_and">
+    inter.value = ${type.maxval}.MAX_VALUE;
+    <#elseif aggrtype.funcName == "bit_or">
+    inter.value = 0;
+  </#if>
+  }
+
+  @Override
+  public void add() {
+  <#if type.inputType?starts_with("Nullable")>
+    sout: {
+    if (in.isSet == 0) {
+     // processing nullable input and the value is null, so don't do anything...
+     break sout;
+    }
+  </#if>
+
+  <#if aggrtype.funcName == "bit_and">
+    inter.value = <#if type.extraCast ??>(${type.extraCast})</#if>(inter.value
& in.value);
+    <#elseif aggrtype.funcName == "bit_or">
+    inter.value = <#if type.extraCast ??>(${type.extraCast})</#if>(inter.value
| in.value);
+  </#if>
+
+    <#if type.inputType?starts_with("Nullable")>
+    } // end of sout block
+    </#if>
+  }
+
+  @Override
+  public void output() {
+    <#if aggrtype.funcName == "bit_and">
+      out.value = inter.value;
+      <#elseif aggrtype.funcName == "bit_or">
+      out.value = inter.value;
+    </#if>
+  }
+
+  @Override
+  public void reset() {
+    <#if aggrtype.funcName == "bit_and">
+      inter.value = ${type.maxval}.MAX_VALUE;
+      <#elseif aggrtype.funcName == "bit_or">
+      inter.value = 0;
+    </#if>
+  }
+}
+
+
+</#list>
+}
+</#list>

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BooleanAggrFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BooleanAggrFunctions.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BooleanAggrFunctions.java
new file mode 100644
index 0000000..b13a58b
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BooleanAggrFunctions.java
@@ -0,0 +1,202 @@
+
+/*******************************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+/*
+ * This class is automatically generated from AggrTypeFunctions2.tdd using FreeMarker.
+ */
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import org.apache.drill.exec.expr.DrillAggFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+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.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.BitHolder;
+import org.apache.drill.exec.expr.holders.NullableBitHolder;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.NullableBigIntHolder;
+import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.NullableIntHolder;
+import org.apache.drill.exec.expr.holders.SmallIntHolder;
+import org.apache.drill.exec.expr.holders.NullableSmallIntHolder;
+import org.apache.drill.exec.expr.holders.TinyIntHolder;
+import org.apache.drill.exec.expr.holders.NullableTinyIntHolder;
+import org.apache.drill.exec.expr.holders.UInt1Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt1Holder;
+import org.apache.drill.exec.expr.holders.UInt2Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt2Holder;
+import org.apache.drill.exec.expr.holders.UInt4Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt4Holder;
+import org.apache.drill.exec.expr.holders.UInt8Holder;
+import org.apache.drill.exec.expr.holders.NullableUInt8Holder;
+import org.apache.drill.exec.record.RecordBatch;
+
+@SuppressWarnings("unused")
+public class BooleanAggrFunctions {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BooleanAggrFunctions.class);
+
+
+@FunctionTemplate(name = "bool_or", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
+public static class BitBooleanOr implements DrillAggFunc{
+
+  @Param BitHolder in;
+  @Workspace BitHolder inter;
+  @Output BitHolder out;
+
+  public void setup(RecordBatch b) {
+  inter = new BitHolder();
+
+    // Initialize the workspace variables
+    inter.value = 0;
+  }
+
+  @Override
+  public void add() {
+    inter.value = inter.value | in.value;
+  }
+
+  @Override
+  public void output() {
+    out.value = inter.value;
+  }
+
+  @Override
+  public void reset() {
+    inter.value = 0;
+  }
+}
+
+
+
+@FunctionTemplate(name = "bool_or", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
+public static class NullableBitBooleanOr implements DrillAggFunc{
+
+  @Param NullableBitHolder in;
+  @Workspace BitHolder inter;
+  @Output BitHolder out;
+
+  public void setup(RecordBatch b) {
+  inter = new BitHolder();
+
+    // Initialize the workspace variables
+    inter.value = 0;
+  }
+
+  @Override
+  public void add() {
+    sout: {
+    if (in.isSet == 0) {
+     // processing nullable input and the value is null, so don't do anything...
+     break sout;
+    }
+
+    inter.value = inter.value | in.value;
+    } // end of sout block
+  }
+
+
+  @Override
+  public void output() {
+    out.value = inter.value;
+  }
+
+  @Override
+  public void reset() {
+    inter.value = 0;
+  }
+}
+
+
+@FunctionTemplate(name = "bool_and", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
+public static class BitBooleanAnd implements DrillAggFunc{
+
+  @Param BitHolder in;
+  @Workspace BitHolder inter;
+  @Output BitHolder out;
+
+  public void setup(RecordBatch b) {
+  inter = new BitHolder();
+
+    // Initialize the workspace variables
+    inter.value = Integer.MAX_VALUE;
+  }
+
+  @Override
+  public void add() {
+
+    inter.value = inter.value & in.value;
+
+  }
+
+  @Override
+  public void output() {
+    out.value = inter.value;
+  }
+
+  @Override
+  public void reset() {
+    inter.value = Integer.MAX_VALUE;
+  }
+}
+
+
+@FunctionTemplate(name = "bool_and", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
+public static class NullableBitBooleanAnd implements DrillAggFunc{
+
+  @Param NullableBitHolder in;
+  @Workspace BitHolder inter;
+  @Output BitHolder out;
+
+  public void setup(RecordBatch b) {
+  inter = new BitHolder();
+
+    // Initialize the workspace variables
+    inter.value = Integer.MAX_VALUE;
+  }
+
+  @Override
+  public void add() {
+    sout: {
+    if (in.isSet == 0) {
+     // processing nullable input and the value is null, so don't do anything...
+     break sout;
+    }
+
+    inter.value = inter.value & in.value;
+
+    } // end of sout block
+  }
+
+
+  @Override
+  public void output() {
+    out.value = inter.value;
+  }
+
+  @Override
+  public void reset() {
+    inter.value = Integer.MAX_VALUE;
+  }
+}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewAggregateFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewAggregateFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewAggregateFunctions.java
new file mode 100644
index 0000000..189af39
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewAggregateFunctions.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.fn.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.pop.PopUnitTestBase;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.rpc.user.QueryResultBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.vector.ValueVector;
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
+public class TestNewAggregateFunctions extends PopUnitTestBase {
+
+  public void runTest(String physicalPlan, String inputDataFile,
+      Object[] expected) throws Exception {
+    try (RemoteServiceSet serviceSet = RemoteServiceSet
+        .getLocalServiceSet();
+        Drillbit bit = new Drillbit(CONFIG, serviceSet);
+        DrillClient client = new DrillClient(CONFIG,
+            serviceSet.getCoordinator())) {
+
+      // run query.
+      bit.run();
+      client.connect();
+      List<QueryResultBatch> results = client.runQuery(
+          QueryType.PHYSICAL,
+          Files.toString(FileUtils.getResourceAsFile(physicalPlan),
+              Charsets.UTF_8).replace("#{TEST_FILE}",
+              inputDataFile));
+
+      RecordBatchLoader batchLoader = new RecordBatchLoader(bit
+          .getContext().getAllocator());
+
+      QueryResultBatch batch = results.get(0);
+      assertTrue(batchLoader.load(batch.getHeader().getDef(),
+          batch.getData()));
+
+      int i = 0;
+      for (VectorWrapper<?> v : batchLoader) {
+        ValueVector.Accessor accessor = v.getValueVector().getAccessor();
+        System.out.println((accessor.getObject(0)));
+        assertEquals(expected[i++], (accessor.getObject(0)));
+      }
+
+      batchLoader.clear();
+      for (QueryResultBatch b : results) {
+        b.release();
+      }
+    }
+  }
+
+  @Test
+  public void testBitwiseAggrFuncs() throws Exception {
+    String physicalPlan = "/functions/test_logical_aggr.json";
+    String inputDataFile = "/logical_aggr_input.json";
+    Object[] expected = {0L, 4L, 4L, 7L, -2L, 1L, true, false};
+
+    runTest(physicalPlan, inputDataFile, expected);
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/test/resources/functions/test_logical_aggr.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/test_logical_aggr.json b/exec/java-exec/src/test/resources/functions/test_logical_aggr.json
new file mode 100644
index 0000000..b6680be
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/test_logical_aggr.json
@@ -0,0 +1,80 @@
+{
+  "head" : {
+    "version" : 1,
+    "generator" : {
+      "type" : "org.apache.drill.exec.planner.logical.DrillImplementor",
+      "info" : ""
+    },
+    "type" : "APACHE_DRILL_PHYSICAL",
+    "resultMode" : "EXEC"
+  },
+  graph:[
+  {
+      @id:1,
+      pop:"fs-scan",
+      format: {type: "json"},
+      storage:{type: "file", connection: "classpath:///"},
+      files:["#{TEST_FILE}"]
+ },
+ {
+    "pop" : "project",
+    "@id" : 2,
+    "exprs" : [ {
+      "ref" : "`A`",
+      "expr" : "`A`"
+    },
+    {
+      "ref" : "`B`",
+      "expr" : "`B`"
+    },
+    {
+      "ref" : "`C`",
+      "expr" : "`C`"
+    },
+    {
+      "ref" : "`D`",
+      "expr" : "`D`"
+    } ],
+    "child" : 1
+  }, {
+    "pop" : "streaming-aggregate",
+    "@id" : 3,
+    "child" : 2,
+    "keys" : [ ],
+    "exprs" : [ {
+      "ref" : "`EXPR$0`",
+      "expr" : "every(`B`) "
+    }, {
+      "ref" : "`EXPR$1`",
+      "expr" : "bit_and(`A`) "
+    },
+    {
+      "ref" : "`EXPR$2`",
+      "expr" : "every(`A`) "
+    },
+    {
+      "ref" : "`EXPR$3`",
+      "expr" : "bit_or(`A`) "
+    },
+    {
+      "ref" : "`EXPR$4`",
+      "expr" : "bit_or(`B`) "
+    },
+    {
+      "ref" : "`EXPR$5`",
+      "expr" : "bit_or(`D`) "
+    },
+    {
+      "ref" : "`EXPR$5`",
+      "expr" : "bool_or(`C`) "
+    },
+    {
+      "ref" : "`EXPR$6`",
+      "expr" : "bool_and(`C`) "
+    }]
+  }, {
+    "pop" : "screen",
+    "@id" : 4,
+    "child" : 3
+  } ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1e420874/exec/java-exec/src/test/resources/logical_aggr_input.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/logical_aggr_input.json b/exec/java-exec/src/test/resources/logical_aggr_input.json
new file mode 100644
index 0000000..d1d25be
--- /dev/null
+++ b/exec/java-exec/src/test/resources/logical_aggr_input.json
@@ -0,0 +1,4 @@
+{"A" : 7, "B" : 2,  "C" : true, "D" : 1}
+{"A" : 4, "B" : -2, "C" : false, "D" : 0}
+{"A" : 4, "B" : 4,  "C" : false, "D" : 0}
+{"A" : 4, "B" : -4, "C" : true, "D" : 1}
\ No newline at end of file


Mime
View raw message