drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject [2/2] drill git commit: DRILL-2870: Part1 - Separate count aggregate functions from others Count is the only aggregate function with required type as output, this will reduce some of the conditional logic in the templates
Date Sun, 10 May 2015 19:53:21 GMT
DRILL-2870: Part1 - Separate count aggregate functions from others
Count is the only aggregate function with required type as output, this will reduce some of
the conditional logic in the templates


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

Branch: refs/heads/master
Commit: e0070e2db2c718318e2f0b0b47ecbabba6a2af53
Parents: 87051d4
Author: Mehant Baid <mehantr@gmail.com>
Authored: Sat May 9 12:31:36 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Sun May 10 11:30:33 2015 -0700

----------------------------------------------------------------------
 exec/java-exec/src/main/codegen/config.fmpp     |  3 +-
 .../src/main/codegen/data/AggrTypes1.tdd        | 29 -------
 .../src/main/codegen/data/CountAggrTypes.tdd    | 39 ++++++++++
 .../src/main/codegen/data/DecimalAggrTypes1.tdd | 13 +---
 .../templates/CountAggregateFunctions.java      | 80 ++++++++++++++++++++
 5 files changed, 122 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/e0070e2d/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 8db120d..c70f6da 100644
--- a/exec/java-exec/src/main/codegen/config.fmpp
+++ b/exec/java-exec/src/main/codegen/config.fmpp
@@ -43,7 +43,8 @@ data: {
     extract:                  tdd(../data/ExtractTypes.tdd),
     sumzero:                  tdd(../data/SumZero.tdd),
     numericTypes:             tdd(../data/NumericTypes.tdd),
-    casthigh:                 tdd(../data/CastHigh.tdd)
+    casthigh:                 tdd(../data/CastHigh.tdd),
+    countAggrTypes:           tdd(../data/CountAggrTypes.tdd)
 }
 freemarkerLinks: {
     includes: includes/

http://git-wip-us.apache.org/repos/asf/drill/blob/e0070e2d/exec/java-exec/src/main/codegen/data/AggrTypes1.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/AggrTypes1.tdd b/exec/java-exec/src/main/codegen/data/AggrTypes1.tdd
index 8952417..1a98a07 100644
--- a/exec/java-exec/src/main/codegen/data/AggrTypes1.tdd
+++ b/exec/java-exec/src/main/codegen/data/AggrTypes1.tdd
@@ -88,35 +88,6 @@
       {inputType: "Interval", outputType: "Interval", runningType: "Interval", major: "Date",
initialValue: "0"},
       {inputType: "NullableInterval", outputType: "Interval", runningType: "Interval", major:
"Date", initialValue: "0"}
      ]
-   },
-   {className: "Count", funcName: "count", types: [
-      {inputType: "Bit", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "Int", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "BigInt", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "NullableBit", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "NullableInt", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "NullableBigInt", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "Float4", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "Float8", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "NullableFloat4", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "NullableFloat8", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "Date", outputType: "BigInt", runningType: "BigInt", major: "Date", initialValue:
"0"},
-      {inputType: "NullableDate", outputType: "BigInt", runningType: "BigInt", major: "Date",
initialValue: "0"},
-      {inputType: "TimeStamp", outputType: "BigInt", runningType: "BigInt", major: "Date",
initialValue: "0"},
-      {inputType: "NullableTimeStamp", outputType: "BigInt", runningType: "BigInt", major:
"Date", initialValue: "0"},
-      {inputType: "Time", outputType: "BigInt", runningType: "BigInt", major: "Date", initialValue:
"0"},
-      {inputType: "NullableTime", outputType: "BigInt", runningType: "BigInt", major: "Date",
initialValue: "0"},
-      {inputType: "IntervalDay", outputType: "BigInt", runningType: "BigInt", major: "Date",
initialValue: "0"},
-      {inputType: "NullableIntervalDay", outputType: "BigInt", runningType: "BigInt", major:
"Date", initialValue: "0"},
-      {inputType: "IntervalYear", outputType: "BigInt", runningType: "BigInt", major: "Date",
initialValue: "0"},
-      {inputType: "NullableIntervalYear", outputType: "BigInt", runningType: "BigInt", major:
"Date", initialValue: "0"},
-      {inputType: "Interval", outputType: "BigInt", runningType: "BigInt", major: "Date",
initialValue: "0"},
-      {inputType: "NullableInterval", outputType: "BigInt", runningType: "BigInt", major:
"Date", initialValue: "0"},
-      {inputType: "VarChar", outputType: "BigInt", runningType: "BigInt", major: "VarBytes"},
-      {inputType: "NullableVarChar", outputType: "BigInt", runningType: "BigInt", major:
"VarBytes"},
-      {inputType: "VarBinary", outputType: "BigInt", runningType: "BigInt", major: "VarBytes"},
-      {inputType: "NullableVarBinary", outputType: "BigInt", runningType: "BigInt", major:
"VarBytes"}
-     ]
    }
   ]
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/e0070e2d/exec/java-exec/src/main/codegen/data/CountAggrTypes.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/CountAggrTypes.tdd b/exec/java-exec/src/main/codegen/data/CountAggrTypes.tdd
new file mode 100644
index 0000000..53e25f7
--- /dev/null
+++ b/exec/java-exec/src/main/codegen/data/CountAggrTypes.tdd
@@ -0,0 +1,39 @@
+{
+  countFunctionsInput: [
+    "Bit",
+    "NullableBit",
+    "Int",
+    "NullableInt",
+    "BigInt",
+    "NullableBigInt",
+    "Float4",
+    "NullableFloat4",
+    "Float8",
+    "NullableFloat8",
+    "Date",
+    "NullableDate",
+    "TimeStamp",
+    "NullableTimeStamp",
+    "Time",
+    "NullableTime",
+    "IntervalDay",
+    "NullableIntervalDay",
+    "IntervalYear",
+    "NullableIntervalYear",
+    "Interval",
+    "NullableInterval",
+    "VarChar",
+    "NullableVarChar",
+    "VarBinary"
+    "NullableVarBinary",
+    "Decimal9",
+    "NullableDecimal9",
+    "Decimal18",
+    "NullableDecimal18",
+    "Decimal28Sparse",
+    "NullableDecimal28Sparse",
+    "Decimal38Sparse",
+    "NullableDecimal38Sparse"
+  ]
+}
+

http://git-wip-us.apache.org/repos/asf/drill/blob/e0070e2d/exec/java-exec/src/main/codegen/data/DecimalAggrTypes1.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/DecimalAggrTypes1.tdd b/exec/java-exec/src/main/codegen/data/DecimalAggrTypes1.tdd
index 5ac299c..92e93bb 100644
--- a/exec/java-exec/src/main/codegen/data/DecimalAggrTypes1.tdd
+++ b/exec/java-exec/src/main/codegen/data/DecimalAggrTypes1.tdd
@@ -37,18 +37,7 @@
       {inputType: "Decimal38Sparse", outputType: "Decimal38Sparse", runningType: "Decimal38Sparse"},
       {inputType: "NullableDecimal38Sparse", outputType: "Decimal38Sparse", runningType:
"Decimal38Sparse"}
      ]
-   },
-      {className: "Count", funcName: "count", types: [
-         {inputType: "Decimal9", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-         {inputType: "NullableDecimal9", outputType: "BigInt", runningType: "BigInt", major:
"Numeric"},
-         {inputType: "Decimal18", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-         {inputType: "NullableDecimal18", outputType: "BigInt", runningType: "BigInt", major:
"Numeric"},
-         {inputType: "Decimal28Sparse", outputType: "BigInt", runningType: "BigInt", major:
"Numeric"},
-         {inputType: "NullableDecimal28Sparse", outputType: "BigInt", runningType: "BigInt",
major: "Numeric"},
-         {inputType: "Decimal38Sparse", outputType: "BigInt", runningType: "BigInt", major:
"Numeric"},
-         {inputType: "NullableDecimal38Sparse", outputType: "BigInt", runningType: "BigInt",
major: "Numeric"}
-        ]
-      },
+   }
       {className: "Sum", funcName: "sum", types: [
         {inputType: "Decimal9", outputType: "Decimal38Sparse", major: "Numeric"},
         {inputType: "NullableDecimal9", outputType: "Decimal38Sparse", major: "Numeric"},

http://git-wip-us.apache.org/repos/asf/drill/blob/e0070e2d/exec/java-exec/src/main/codegen/templates/CountAggregateFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/CountAggregateFunctions.java b/exec/java-exec/src/main/codegen/templates/CountAggregateFunctions.java
new file mode 100644
index 0000000..71ac6a7
--- /dev/null
+++ b/exec/java-exec/src/main/codegen/templates/CountAggregateFunctions.java
@@ -0,0 +1,80 @@
+/**
+ * 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.
+ */
+
+import java.lang.Override;
+
+<@pp.dropOutputFile />
+
+<#-- A utility class that is used to generate java code for count aggregate functions
-->
+
+<@pp.changeOutputFile name="/org/apache/drill/exec/expr/fn/impl/gaggr/CountFunctions.java"
/>
+
+<#include "/@includes/license.ftl" />
+
+// Source code generated using FreeMarker template ${.template_name}
+
+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.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.*;
+
+@SuppressWarnings("unused")
+
+public class CountFunctions {
+  <#list countAggrTypes.countFunctionsInput as inputType>
+  @FunctionTemplate(name = "count", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE)
+  public static class ${inputType}CountFunction implements DrillAggFunc {
+
+    @Param ${inputType}Holder in;
+    @Workspace BigIntHolder value;
+    @Output BigIntHolder out;
+
+    @Override
+    public void setup() {
+	    value = new BigIntHolder();
+      value.value = 0;
+    }
+
+    @Override
+    public void add() {
+      <#if inputType?starts_with("Nullable")>
+        if (in.isSet == 1) {
+          value.value++;
+        }
+      <#else>
+        value.value++;
+      </#if>
+    }
+
+    @Override
+    public void output() {
+      out.value = value.value;
+    }
+
+    @Override
+    public void reset() {
+      value.value = 0;
+    }
+  }
+  </#list>
+}
\ No newline at end of file


Mime
View raw message