drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [12/12] drill git commit: DRILL-2870: Part2 - Fix return type of aggregate functions to be nullable
Date Sun, 10 May 2015 16:30:57 GMT
DRILL-2870: Part2 - Fix return type of aggregate functions to be nullable


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

Branch: refs/heads/merge_2015_05_09
Commit: 6a7de92e3692a75ade346e87af10d8ed1705f916
Parents: ed5fa92
Author: Mehant Baid <mehantr@gmail.com>
Authored: Sat May 9 13:36:05 2015 -0700
Committer: Jacques Nadeau <jacques@apache.org>
Committed: Sun May 10 09:30:22 2015 -0700

----------------------------------------------------------------------
 .../codegen/data/AggrBitwiseLogicalTypes.tdd    |  64 ++++++------
 .../src/main/codegen/data/AggrTypes1.tdd        | 102 +++++++++----------
 .../src/main/codegen/data/AggrTypes2.tdd        |  20 ++--
 .../src/main/codegen/data/AggrTypes3.tdd        |  80 +++++++--------
 .../AggrBitwiseLogicalTypeFunctions.java        |  23 +++--
 .../codegen/templates/AggrTypeFunctions1.java   |  40 +++-----
 .../codegen/templates/AggrTypeFunctions2.java   |  36 +++----
 .../codegen/templates/AggrTypeFunctions3.java   |  42 ++------
 .../templates/DateIntervalAggrFunctions1.java   |  80 ++++++++-------
 .../templates/IntervalAggrFunctions2.java       |  39 ++++---
 .../templates/VarCharAggrFunctions1.java        |  53 ++++------
 .../exec/physical/impl/join/JoinUtils.java      |   2 +-
 .../exec/fn/impl/TestAggregateFunctions.java    |  71 ++++++++++++-
 .../drill/exec/physical/impl/agg/TestAgg.java   |   3 +-
 .../resources/parquet/alltypes_required.parquet | Bin 0 -> 1197 bytes
 15 files changed, 340 insertions(+), 315 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/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
index 2b72abd..1070faa 100644
--- a/exec/java-exec/src/main/codegen/data/AggrBitwiseLogicalTypes.tdd
+++ b/exec/java-exec/src/main/codegen/data/AggrBitwiseLogicalTypes.tdd
@@ -17,41 +17,41 @@
 {
   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"}
+     {inputType: "BigInt", outputType: "NullableBigInt", maxval: "Integer"},
+      {inputType: "NullableBigInt", outputType: "NullableBigInt", maxval: "Integer"},
+      {inputType: "Int", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "NullableInt", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "SmallInt", outputType: "NullableSmallInt", maxval: "Byte", extraCast: "short"},
+      {inputType: "NullableSmallInt", outputType: "NullableSmallInt", maxval: "Byte", extraCast: "short"},
+      {inputType: "TinyInt", outputType: "NullableTinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "NullableTinyInt", outputType: "NullableTinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "UInt1", outputType: "NullableInt", maxval: "Byte"},
+      {inputType: "NullableUInt1", outputType: "NullableInt", maxval: "Byte"},
+      {inputType: "UInt2", outputType: "NullableInt", maxval: "Character"},
+      {inputType: "NullableUInt2", outputType: "NullableInt", maxval: "Character"},
+      {inputType: "UInt4", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "NullableUInt4", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "UInt8", outputType: "NullableUInt8", maxval: "Long"},
+      {inputType: "NullableUInt8", outputType: "NullableUInt8", 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"}
+     {inputType: "BigInt", outputType: "NullableBigInt", maxval: "Integer"},
+      {inputType: "NullableBigInt", outputType: "NullableBigInt", maxval: "Integer"},
+      {inputType: "Int", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "NullableInt", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "SmallInt", outputType: "NullableSmallInt", maxval: "Byte", extraCast: "short"},
+      {inputType: "NullableSmallInt", outputType: "NullableSmallInt", maxval: "Byte", extraCast: "short"},
+      {inputType: "TinyInt", outputType: "NullableTinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "NullableTinyInt", outputType: "NullableTinyInt", maxval: "Byte", extraCast: "byte"},
+      {inputType: "UInt1", outputType: "NullableInt", maxval: "Byte"},
+      {inputType: "NullableUInt1", outputType: "NullableInt", maxval: "Byte"},
+      {inputType: "UInt2", outputType: "NullableInt", maxval: "Character"},
+      {inputType: "NullableUInt2", outputType: "NullableInt", maxval: "Character"},
+      {inputType: "UInt4", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "NullableUInt4", outputType: "NullableInt", maxval: "Integer"},
+      {inputType: "UInt8", outputType: "NullableUInt8", maxval: "Long"},
+      {inputType: "NullableUInt8", outputType: "NullableUInt8", maxval: "Long"}
      ]
    }
   ]

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/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 1a98a07..202f539 100644
--- a/exec/java-exec/src/main/codegen/data/AggrTypes1.tdd
+++ b/exec/java-exec/src/main/codegen/data/AggrTypes1.tdd
@@ -17,76 +17,76 @@
 {
   aggrtypes: [
     {className: "Min", funcName: "min", types: [
-      {inputType: "Bit", outputType: "Bit", runningType: "Bit", major: "Numeric"},
-      {inputType: "Int", outputType: "Int", runningType: "Int", major: "Numeric"},
-      {inputType: "BigInt", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
+      {inputType: "Bit", outputType: "NullableBit", runningType: "Bit", major: "Numeric"},
+      {inputType: "Int", outputType: "NullableInt", runningType: "Int", major: "Numeric"},
+      {inputType: "BigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
       {inputType: "NullableBit", outputType: "NullableBit", runningType: "Bit", major: "Numeric"},
       {inputType: "NullableInt", outputType: "NullableInt", runningType: "Int", major: "Numeric"},
       {inputType: "NullableBigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "Float4", outputType: "Float4", runningType: "Float4", major: "Numeric"},
-      {inputType: "Float8", outputType: "Float8", runningType: "Float8", major: "Numeric"},
+      {inputType: "Float4", outputType: "NullableFloat4", runningType: "Float4", major: "Numeric"},
+      {inputType: "Float8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
       {inputType: "NullableFloat4", outputType: "NullableFloat4", runningType: "Float4", major: "Numeric"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
-      {inputType: "Date", outputType: "Date", runningType: "Date", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "NullableDate", outputType: "Date", runningType: "Date", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "TimeStamp", outputType: "TimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "NullableTimeStamp", outputType: "TimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "Time", outputType: "Time", runningType: "Time", major: "Date", initialValue: "Integer.MAX_VALUE"},
-      {inputType: "NullableTime", outputType: "Time", runningType: "Time", major: "Date", initialValue: "Integer.MAX_VALUE"},
-      {inputType: "IntervalDay", outputType: "IntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "NullableIntervalDay", outputType: "IntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "IntervalYear", outputType: "IntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MAX_VALUE"},
-      {inputType: "NullableIntervalYear", outputType: "IntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MAX_VALUE"},
-      {inputType: "Interval", outputType: "Interval", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "NullableInterval", outputType: "Interval", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
-      {inputType: "VarChar", outputType: "VarChar", runningType: "VarChar", major: "VarBytes"},
-      {inputType: "NullableVarChar", outputType: "VarChar", runningType: "VarChar", major: "VarBytes"},
-      {inputType: "VarBinary", outputType: "VarBinary", runningType: "VarBinary", major: "VarBytes"},
-      {inputType: "NullableVarBinary", outputType: "VarBinary", runningType: "VarBinary", major: "VarBytes"}
+      {inputType: "Date", outputType: "NullableDate", runningType: "Date", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "NullableDate", outputType: "NullableDate", runningType: "Date", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "TimeStamp", outputType: "NullableTimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "NullableTimeStamp", outputType: "NullableTimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "Time", outputType: "NullableTime", runningType: "Time", major: "Date", initialValue: "Integer.MAX_VALUE"},
+      {inputType: "NullableTime", outputType: "NullableTime", runningType: "Time", major: "Date", initialValue: "Integer.MAX_VALUE"},
+      {inputType: "IntervalDay", outputType: "NullableIntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "NullableIntervalDay", outputType: "NullableIntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "IntervalYear", outputType: "NullableIntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MAX_VALUE"},
+      {inputType: "NullableIntervalYear", outputType: "NullableIntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MAX_VALUE"},
+      {inputType: "Interval", outputType: "NullableInterval", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "NullableInterval", outputType: "NullableInterval", runningType: "BigInt", major: "Date", initialValue: "Long.MAX_VALUE"},
+      {inputType: "VarChar", outputType: "NullableVarChar", runningType: "VarChar", major: "VarBytes"},
+      {inputType: "NullableVarChar", outputType: "NullableVarChar", runningType: "VarChar", major: "VarBytes"},
+      {inputType: "VarBinary", outputType: "NullableVarBinary", runningType: "VarBinary", major: "VarBytes"},
+      {inputType: "NullableVarBinary", outputType: "NullableVarBinary", runningType: "VarBinary", major: "VarBytes"}
      ]
    },
    {className: "Max", funcName: "max", types: [
-      {inputType: "Int", outputType: "Int", runningType: "Int", major: "Numeric"},
-      {inputType: "BigInt", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
+      {inputType: "Int", outputType: "NullableInt", runningType: "Int", major: "Numeric"},
+      {inputType: "BigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
       {inputType: "NullableInt", outputType: "NullableInt", runningType: "Int", major: "Numeric"},
       {inputType: "NullableBigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "Float4", outputType: "Float4", runningType: "Float4", major: "Numeric"},
-      {inputType: "Float8", outputType: "Float8", runningType: "Float8", major: "Numeric"},
+      {inputType: "Float4", outputType: "NullableFloat4", runningType: "Float4", major: "Numeric"},
+      {inputType: "Float8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
       {inputType: "NullableFloat4", outputType: "NullableFloat4", runningType: "Float4", major: "Numeric"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
-      {inputType: "Date", outputType: "Date", runningType: "Date", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "NullableDate", outputType: "Date", runningType: "Date", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "TimeStamp", outputType: "TimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "NullableTimeStamp", outputType: "TimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "Time", outputType: "Time", runningType: "Time", major: "Date", initialValue: "Integer.MIN_VALUE"},
-      {inputType: "NullableTime", outputType: "Time", runningType: "Time", major: "Date", initialValue: "Integer.MIN_VALUE"},
-      {inputType: "IntervalDay", outputType: "IntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "NullableIntervalDay", outputType: "IntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "IntervalYear", outputType: "IntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MIN_VALUE"},
-      {inputType: "NullableIntervalYear", outputType: "IntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MIN_VALUE"},
-      {inputType: "Interval", outputType: "Interval", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "NullableInterval", outputType: "Interval", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
-      {inputType: "VarChar", outputType: "VarChar", runningType: "VarChar", major: "VarBytes"},
-      {inputType: "NullableVarChar", outputType: "VarChar", runningType: "VarChar", major: "VarBytes"},
-      {inputType: "VarBinary", outputType: "VarBinary", runningType: "VarBinary", major: "VarBytes"},
-      {inputType: "NullableVarBinary", outputType: "VarBinary", runningType: "VarBinary", major: "VarBytes"}
+      {inputType: "Date", outputType: "NullableDate", runningType: "Date", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "NullableDate", outputType: "NullableDate", runningType: "Date", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "TimeStamp", outputType: "NullableTimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "NullableTimeStamp", outputType: "NullableTimeStamp", runningType: "TimeStamp", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "Time", outputType: "NullableTime", runningType: "Time", major: "Date", initialValue: "Integer.MIN_VALUE"},
+      {inputType: "NullableTime", outputType: "NullableTime", runningType: "Time", major: "Date", initialValue: "Integer.MIN_VALUE"},
+      {inputType: "IntervalDay", outputType: "NullableIntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "NullableIntervalDay", outputType: "NullableIntervalDay", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "IntervalYear", outputType: "NullableIntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MIN_VALUE"},
+      {inputType: "NullableIntervalYear", outputType: "NullableIntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "Integer.MIN_VALUE"},
+      {inputType: "Interval", outputType: "NullableInterval", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "NullableInterval", outputType: "NullableInterval", runningType: "BigInt", major: "Date", initialValue: "Long.MIN_VALUE"},
+      {inputType: "VarChar", outputType: "NullableVarChar", runningType: "VarChar", major: "VarBytes"},
+      {inputType: "NullableVarChar", outputType: "NullableVarChar", runningType: "VarChar", major: "VarBytes"},
+      {inputType: "VarBinary", outputType: "NullableVarBinary", runningType: "VarBinary", major: "VarBytes"},
+      {inputType: "NullableVarBinary", outputType: "NullableVarBinary", runningType: "VarBinary", major: "VarBytes"}
      ]
    },
    {className: "Sum", funcName: "sum", types: [
-      {inputType: "Int", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "BigInt", outputType: "BigInt", runningType: "BigInt", major: "Numeric"},
+      {inputType: "Int", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
+      {inputType: "BigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
       {inputType: "NullableInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
       {inputType: "NullableBigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"},
-      {inputType: "Float4", outputType: "Float8", runningType: "Float8", major: "Numeric"},
-      {inputType: "Float8", outputType: "Float8", runningType: "Float8", major: "Numeric"},
+      {inputType: "Float4", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
+      {inputType: "Float8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
       {inputType: "NullableFloat4", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"},
-      {inputType: "IntervalDay", outputType: "IntervalDay", runningType: "IntervalDay", major: "Date", initialValue: "0"},
-      {inputType: "NullableIntervalDay", outputType: "IntervalDay", runningType: "IntervalDay", major: "Date", initialValue: "0"},
-      {inputType: "IntervalYear", outputType: "IntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "0"},
-      {inputType: "NullableIntervalYear", outputType: "IntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "0"},
-      {inputType: "Interval", outputType: "Interval", runningType: "Interval", major: "Date", initialValue: "0"},
-      {inputType: "NullableInterval", outputType: "Interval", runningType: "Interval", major: "Date", initialValue: "0"}
+      {inputType: "IntervalDay", outputType: "NullableIntervalDay", runningType: "IntervalDay", major: "Date", initialValue: "0"},
+      {inputType: "NullableIntervalDay", outputType: "NullableIntervalDay", runningType: "IntervalDay", major: "Date", initialValue: "0"},
+      {inputType: "IntervalYear", outputType: "NullableIntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "0"},
+      {inputType: "NullableIntervalYear", outputType: "NullableIntervalYear", runningType: "IntervalYear", major: "Date", initialValue: "0"},
+      {inputType: "Interval", outputType: "NullableInterval", runningType: "Interval", major: "Date", initialValue: "0"},
+      {inputType: "NullableInterval", outputType: "NullableInterval", runningType: "Interval", major: "Date", initialValue: "0"}
      ]
    }
   ]

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/data/AggrTypes2.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/AggrTypes2.tdd b/exec/java-exec/src/main/codegen/data/AggrTypes2.tdd
index ee64daf..183d028 100644
--- a/exec/java-exec/src/main/codegen/data/AggrTypes2.tdd
+++ b/exec/java-exec/src/main/codegen/data/AggrTypes2.tdd
@@ -17,20 +17,20 @@
 {
   aggrtypes: [
     {className: "Avg", funcName: "avg", types: [
-      {inputType: "Int", outputType: "Float8", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Numeric"},
-      {inputType: "BigInt", outputType: "Float8", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Numeric"},
+      {inputType: "Int", outputType: "NullableFloat8", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Numeric"},
+      {inputType: "BigInt", outputType: "NullableFloat8", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Numeric"},
       {inputType: "NullableInt", outputType: "NullableFloat8", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Numeric"},
       {inputType: "NullableBigInt", outputType: "NullableFloat8", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Numeric"},
-      {inputType: "Float4", outputType: "Float8", sumRunningType: "Float8", countRunningType: "BigInt", major: "Numeric"},
-      {inputType: "Float8", outputType: "Float8", sumRunningType: "Float8", countRunningType: "BigInt", major: "Numeric"},
+      {inputType: "Float4", outputType: "NullableFloat8", sumRunningType: "Float8", countRunningType: "BigInt", major: "Numeric"},
+      {inputType: "Float8", outputType: "NullableFloat8", sumRunningType: "Float8", countRunningType: "BigInt", major: "Numeric"},
       {inputType: "NullableFloat4", outputType: "NullableFloat8", sumRunningType: "Float8", countRunningType: "BigInt", major: "Numeric"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", sumRunningType: "Float8", countRunningType: "BigInt", major: "Numeric"},
-      {inputType: "IntervalDay", outputType: "Interval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
-      {inputType: "NullableIntervalDay", outputType: "Interval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
-      {inputType: "IntervalYear", outputType: "Interval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
-      {inputType: "NullableIntervalYear", outputType: "Interval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
-      {inputType: "Interval", outputType: "Interval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
-      {inputType: "NullableInterval", outputType: "Interval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"}
+      {inputType: "IntervalDay", outputType: "NullableInterval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
+      {inputType: "NullableIntervalDay", outputType: "NullableInterval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
+      {inputType: "IntervalYear", outputType: "NullableInterval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
+      {inputType: "NullableIntervalYear", outputType: "NullableInterval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
+      {inputType: "Interval", outputType: "NullableInterval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"},
+      {inputType: "NullableInterval", outputType: "NullableInterval", sumRunningType: "BigInt", countRunningType: "BigInt", major: "Date"}
      ]
    }
   ]

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/data/AggrTypes3.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/AggrTypes3.tdd b/exec/java-exec/src/main/codegen/data/AggrTypes3.tdd
index 0c3a358..7fb67cf 100644
--- a/exec/java-exec/src/main/codegen/data/AggrTypes3.tdd
+++ b/exec/java-exec/src/main/codegen/data/AggrTypes3.tdd
@@ -17,97 +17,97 @@
 {
   aggrtypes: [
     {className: "StdDevPop", funcName: "stddev_pop", aliasName: "", types: [
-      {inputType: "BigInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "BigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableBigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Int", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Int", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "SmallInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "SmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableSmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "TinyInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "TinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableTinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt1", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt2", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"}
      ]
    },
 
     {className: "VariancePop", funcName: "var_pop", aliasName: "", types: [
-      {inputType: "BigInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "BigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableBigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Int", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Int", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "SmallInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "SmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableSmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "TinyInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "TinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableTinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt1", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt2", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"}
      ]
    },
 
     {className: "StdDevSample", funcName: "stddev_samp", aliasName: "stddev", types: [
-      {inputType: "BigInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "BigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableBigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Int", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Int", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "SmallInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "SmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableSmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "TinyInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "TinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableTinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt1", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt2", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"}
      ]
    },
 
     {className: "VarianceSample", funcName: "var_samp", aliasName: "variance", types: [
-      {inputType: "BigInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "BigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableBigInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Int", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Int", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "SmallInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "SmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableSmallInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "TinyInt", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "TinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableTinyInt", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt1", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt1", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt2", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt2", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "UInt8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "UInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableUInt8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float4", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat4", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
-      {inputType: "Float8", outputType: "Float8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
+      {inputType: "Float8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"},
       {inputType: "NullableFloat8", outputType: "NullableFloat8", movingAverageType: "Float8", movingDeviationType: "Float8", countRunningType: "BigInt"}
      ]
    }

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/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
index b159421..3453058 100644
--- a/exec/java-exec/src/main/codegen/templates/AggrBitwiseLogicalTypeFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/AggrBitwiseLogicalTypeFunctions.java
@@ -72,10 +72,13 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Param ${type.inputType}Holder in;
   @Workspace ${type.outputType}Holder inter;
+  @Workspace BigIntHolder nonNullCount;
   @Output ${type.outputType}Holder out;
 
   public void setup() {
-  inter = new ${type.outputType}Holder();
+    inter = new ${type.outputType}Holder();
+    nonNullCount = new BigIntHolder();
+    nonNullCount.value = 0;
 
     // Initialize the workspace variables
   <#if aggrtype.funcName == "bit_and">
@@ -94,7 +97,7 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
      break sout;
     }
   </#if>
-
+    nonNullCount.value = 1;
   <#if aggrtype.funcName == "bit_and">
     inter.value = <#if type.extraCast ??>(${type.extraCast})</#if>(inter.value & in.value);
     <#elseif aggrtype.funcName == "bit_or">
@@ -108,15 +111,21 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Override
   public void output() {
-    <#if aggrtype.funcName == "bit_and">
-      out.value = inter.value;
-      <#elseif aggrtype.funcName == "bit_or">
-      out.value = inter.value;
-    </#if>
+    if (nonNullCount.value > 0) {
+      out.isSet = 1;
+      <#if aggrtype.funcName == "bit_and">
+        out.value = inter.value;
+        <#elseif aggrtype.funcName == "bit_or">
+        out.value = inter.value;
+      </#if>
+    } else {
+      out.isSet = 0;
+    }
   }
 
   @Override
   public void reset() {
+    nonNullCount.value = 0;
     <#if aggrtype.funcName == "bit_and">
       inter.value = ${type.maxval}.MAX_VALUE;
       <#elseif aggrtype.funcName == "bit_or">

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions1.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions1.java b/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions1.java
index 19a6d46..1360f66 100644
--- a/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions1.java
+++ b/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions1.java
@@ -24,12 +24,10 @@
 
 <#include "/@includes/license.ftl" />
 
-<#-- A utility class that is used to generate java code for aggr functions that maintain a single -->
-<#-- running counter to hold the result.  This includes: MIN, MAX, SUM, COUNT. -->
+// Source code generated using FreeMarker template ${.template_name}
 
-/* 
- * This class is automatically generated from AggrTypeFunctions1.tdd using FreeMarker.
- */
+<#-- A utility class that is used to generate java code for aggr functions that maintain a single -->
+<#-- running counter to hold the result.  This includes: MIN, MAX, SUM. -->
 
 package org.apache.drill.exec.expr.fn.impl.gaggr;
 
@@ -54,18 +52,14 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Param ${type.inputType}Holder in;
   @Workspace ${type.runningType}Holder value;
-  <#if type.inputType?starts_with("Nullable") && type.outputType?starts_with("Nullable")>
-    @Workspace BigIntHolder nonNullCount;
-  </#if>
+  @Workspace BigIntHolder nonNullCount;
   @Output ${type.outputType}Holder out;
 
   public void setup() {
-	value = new ${type.runningType}Holder();
-  <#if type.inputType?starts_with("Nullable") && type.outputType?starts_with("Nullable")>
+	  value = new ${type.runningType}Holder();
 	  nonNullCount = new BigIntHolder();
 	  nonNullCount.value = 0;
-	</#if>
-	<#if aggrtype.funcName == "sum" || aggrtype.funcName == "count">
+	<#if aggrtype.funcName == "sum">
 	  value.value = 0;
 	<#elseif aggrtype.funcName == "min">
     <#if type.runningType?starts_with("Bit")>
@@ -103,12 +97,8 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 		    // processing nullable input and the value is null, so don't do anything...
 		    break sout;
 	    }
-      <#if type.outputType?starts_with("Nullable")>
-        else {
-  	        nonNullCount.value++;
-	      }
-      </#if>
 	  </#if>
+    nonNullCount.value = 1;
 	  <#if aggrtype.funcName == "min">
 	    value.value = Math.min(value.value, in.value);
 	  <#elseif aggrtype.funcName == "max">
@@ -127,23 +117,17 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Override
   public void output() {   
-    <#if type.inputType?starts_with("Nullable") && type.outputType?starts_with("Nullable")>
-      if (nonNullCount.value > 0) {
-        out.value = value.value;
-        out.isSet = 1;
-      } else {
-        out.isSet = 0;
-      }
-    <#else> 
+    if (nonNullCount.value > 0) {
       out.value = value.value;
-    </#if>
+      out.isSet = 1;
+    } else {
+      out.isSet = 0;
+    }
   }
 
   @Override
   public void reset() {
-  <#if type.inputType?starts_with("Nullable") && type.outputType?starts_with("Nullable")>
     nonNullCount.value = 0;
-  </#if>
 	<#if aggrtype.funcName == "sum" || aggrtype.funcName == "count">
 	  value.value = 0;
 	<#elseif aggrtype.funcName == "min">

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions2.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions2.java b/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions2.java
index 6701f09..fe76cbe 100644
--- a/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions2.java
+++ b/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions2.java
@@ -24,13 +24,11 @@
 
 <#include "/@includes/license.ftl" />
 
+// Source code generated using FreeMarker template ${.template_name}
+
 <#-- A utility class that is used to generate java code for aggr functions that maintain a sum -->
 <#-- and a running count.  For now, this includes: AVG. -->
 
-/* 
- * This class is automatically generated from AggrTypeFunctions2.tdd using FreeMarker.
- */
-
 
 package org.apache.drill.exec.expr.fn.impl.gaggr;
 
@@ -63,10 +61,8 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
   public void setup() {
   	sum = new ${type.sumRunningType}Holder();  
     count = new ${type.countRunningType}Holder();  
-    <#if type.inputType?starts_with("Nullable") >
-  	  nonNullCount = new BigIntHolder();
-  	  nonNullCount.value = 0;
-  	</#if>
+  	nonNullCount = new BigIntHolder();
+  	nonNullCount.value = 0;
     sum.value = 0;
     count.value = 0;
   }
@@ -79,10 +75,8 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 		    // processing nullable input and the value is null, so don't do anything...
 		    break sout;
 	    } 
-      else {
-        nonNullCount.value++;
-      } 
 	  </#if>
+    nonNullCount.value = 1;
 	  <#if aggrtype.funcName == "avg">
  	    sum.value += in.value;
  	    count.value++;
@@ -96,27 +90,21 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Override
   public void output() {
-    <#if type.inputType?starts_with("Nullable") >
-      if (nonNullCount.value > 0) {
-        out.value = sum.value / ((double) count.value);
-        out.isSet = 1;
-      } else {
-        out.isSet = 0;
-      }
-    <#else> 
+    if (nonNullCount.value > 0) {
       out.value = sum.value / ((double) count.value);
-    </#if>
+      out.isSet = 1;
+    } else {
+      out.isSet = 0;
+    }
   }
 
   @Override
   public void reset() {
-    <#if type.inputType?starts_with("Nullable") >
-      nonNullCount.value = 0;
-    </#if>
+    nonNullCount.value = 0;
     sum.value = 0;
     count.value = 0;
   }
- 
+
  }
 
 </#if>

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions3.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions3.java b/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions3.java
index c005446..ee158bd 100644
--- a/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions3.java
+++ b/exec/java-exec/src/main/codegen/templates/AggrTypeFunctions3.java
@@ -24,11 +24,9 @@
 
 <#include "/@includes/license.ftl" />
 
-<#-- A utility class that is used to generate java code for aggr functions such as stddev, variance -->
+// Source code generated using FreeMarker template ${.template_name}
 
-/*
- * This class is automatically generated from AggrTypeFunctions2.tdd using FreeMarker.
- */
+<#-- A utility class that is used to generate java code for aggr functions such as stddev, variance -->
 
 package org.apache.drill.exec.expr.fn.impl.gaggr;
 
@@ -67,10 +65,8 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
   	avg = new ${type.movingAverageType}Holder();
     dev = new ${type.movingDeviationType}Holder();
     count = new ${type.countRunningType}Holder();
-    <#if type.inputType?starts_with("Nullable") >
-  	  nonNullCount = new BigIntHolder();
-  	  nonNullCount.value = 0;
-  	</#if>
+  	nonNullCount = new BigIntHolder();
+  	nonNullCount.value = 0;
     // Initialize the workspace variables
     avg.value = 0;
     dev.value = 0;
@@ -85,11 +81,9 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 	   // processing nullable input and the value is null, so don't do anything...
 	   break sout;
 	  }
-    else {
-      nonNullCount.value++;
-    }
 	</#if>
 
+    nonNullCount.value = 1;
     // Welford's approach to compute standard deviation
     double temp = avg.value;
     avg.value += ((in.value - temp) / count.value);
@@ -103,9 +97,8 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Override
   public void output() {
-   <#if type.inputType?starts_with("Nullable") >
-     if (nonNullCount.value > 0) {
-       out.isSet = 1;
+    if (nonNullCount.value > 0) {
+      out.isSet = 1;
       <#if aggrtype.funcName == "stddev_pop">
       if (count.value > 1)
         out.value = Math.sqrt((dev.value / (count.value - 1)));
@@ -121,29 +114,12 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
       </#if>
      } else {
        out.isSet = 0;
-     }
-   <#else> 
-    <#if aggrtype.funcName == "stddev_pop">
-    if (count.value > 1)
-      out.value = Math.sqrt((dev.value / (count.value - 1)));
-    <#elseif aggrtype.funcName == "var_pop">
-    if (count.value  > 1)
-      out.value = (dev.value / (count.value - 1));
-    <#elseif aggrtype.funcName == "stddev_samp">
-    if (count.value  > 2)
-      out.value = Math.sqrt((dev.value / (count.value - 2)));
-    <#elseif aggrtype.funcName == "var_samp">
-    if (count.value > 2)
-      out.value = (dev.value / (count.value - 2));
-    </#if>
-   </#if>
+    }
   }
 
   @Override
   public void reset() {
-    <#if type.inputType?starts_with("Nullable") >
-      nonNullCount.value = 0;
-    </#if>
+    nonNullCount.value = 0;
     avg.value = 0;
     dev.value = 0;
     count.value = 1;

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java b/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java
index e934167..7480842 100644
--- a/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java
+++ b/exec/java-exec/src/main/codegen/templates/DateIntervalAggrFunctions1.java
@@ -24,13 +24,11 @@
 
 <#include "/@includes/license.ftl" />
 
+// Source code generated using FreeMarker template ${.template_name}
+
 <#-- A utility class that is used to generate java code for aggr functions for Date, Time, Interval types -->
 <#--  that maintain a single running counter to hold the result.  This includes: MIN, MAX, SUM, COUNT. -->
 
-/*
- * This class is automatically generated from AggrTypeFunctions1.tdd using FreeMarker.
- */
-
 package org.apache.drill.exec.expr.fn.impl.gaggr;
 
 import org.apache.drill.exec.expr.DrillAggFunc;
@@ -52,10 +50,13 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Param ${type.inputType}Holder in;
   @Workspace ${type.runningType}Holder value;
+  @Workspace BigIntHolder nonNullCount;
   @Output ${type.outputType}Holder out;
 
   public void setup() {
-	value = new ${type.runningType}Holder();
+	  value = new ${type.runningType}Holder();
+    nonNullCount = new BigIntHolder();
+    nonNullCount.value = 0;
     <#if type.runningType == "Interval">
     value.months = ${type.initialValue};
     value.days= ${type.initialValue};
@@ -77,10 +78,10 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 		    break sout;
 	    }
 	  </#if>
-
+    nonNullCount.value = 1;
 	  <#if aggrtype.funcName == "min">
 
-    <#if type.outputType == "Interval">
+    <#if type.outputType?ends_with("Interval")>
 
     long inMS = (long) in.months * org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis+
                        in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) +
@@ -88,7 +89,7 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
     value.value = Math.min(value.value, inMS);
 
-    <#elseif type.outputType == "IntervalDay">
+    <#elseif type.outputType?ends_with("IntervalDay")>
     long inMS = (long) in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) +
                        in.milliseconds;
 
@@ -99,13 +100,13 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
     value.value = Math.min(value.value, in.value);
     </#if>
 	  <#elseif aggrtype.funcName == "max">
-    <#if type.outputType == "Interval">
+    <#if type.outputType?ends_with("Interval")>
     long inMS = (long) in.months * org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis+
                        in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) +
                        in.milliseconds;
 
     value.value = Math.max(value.value, inMS);
-    <#elseif type.outputType == "IntervalDay">
+    <#elseif type.outputType?ends_with("IntervalDay")>
     long inMS = (long) in.days * (org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis) +
                        in.milliseconds;
 
@@ -115,11 +116,11 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
     </#if>
 
 	  <#elseif aggrtype.funcName == "sum">
-    <#if type.outputType == "Interval">
+    <#if type.outputType?ends_with("Interval")>
     value.days += in.days;
     value.months += in.months;
     value.milliseconds += in.milliseconds;
-    <#elseif type.outputType == "IntervalDay">
+    <#elseif type.outputType?ends_with("IntervalDay")>
     value.days += in.days;
     value.milliseconds += in.milliseconds;
     <#else>
@@ -137,35 +138,40 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Override
   public void output() {
-
-    <#if aggrtype.funcName == "max" || aggrtype.funcName == "min">
-    <#if type.outputType == "Interval">
-    out.months = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis);
-    value.value = value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis;
-    out.days = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    out.milliseconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    <#elseif type.outputType == "IntervalDay">
-    out.days = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    out.milliseconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    <#else>
-    out.value = value.value;
-    </#if>
-    <#else>
-    <#if type.outputType == "Interval">
-    out.months = value.months;
-    out.days = value.days;
-    out.milliseconds = value.milliseconds;
-    <#elseif type.outputType == "IntervalDay">
-    out.days = value.days;
-    out.milliseconds = value.milliseconds;
-    <#else>
-    out.value = value.value;
-    </#if>
-    </#if>
+    if (nonNullCount.value > 0) {
+      out.isSet = 1;
+      <#if aggrtype.funcName == "max" || aggrtype.funcName == "min">
+      <#if type.outputType?ends_with("Interval")>
+      out.months = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis);
+      value.value = value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis;
+      out.days = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      out.milliseconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      <#elseif type.outputType?ends_with("IntervalDay")>
+      out.days = (int) (value.value / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      out.milliseconds = (int) (value.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      <#else>
+      out.value = value.value;
+      </#if>
+      <#else>
+      <#if type.outputType?ends_with("Interval")>
+      out.months = value.months;
+      out.days = value.days;
+      out.milliseconds = value.milliseconds;
+      <#elseif type.outputType?ends_with("IntervalDay")>
+      out.days = value.days;
+      out.milliseconds = value.milliseconds;
+      <#else>
+      out.value = value.value;
+      </#if>
+      </#if>
+    } else {
+      out.isSet = 0;
+    }
   }
 
   @Override
   public void reset() {
+    nonNullCount.value = 0;
     <#if type.runningType == "Interval">
     value.months = ${type.initialValue};
     value.days= ${type.initialValue};

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java b/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java
index b29fa08..6745097 100644
--- a/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java
+++ b/exec/java-exec/src/main/codegen/templates/IntervalAggrFunctions2.java
@@ -24,14 +24,11 @@
 
 <#include "/@includes/license.ftl" />
 
+// Source code generated using FreeMarker template ${.template_name}
+
 <#-- A utility class that is used to generate java code for aggr functions for the interval data types. It maintains a running sum  -->
 <#-- and a running count.  For now, this includes: AVG. -->
 
-/*
- * This class is automatically generated from AggrTypeFunctions2.tdd using FreeMarker.
- */
-
-
 package org.apache.drill.exec.expr.fn.impl.gaggr;
 
 import org.apache.drill.exec.expr.DrillAggFunc;
@@ -57,11 +54,14 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
   @Param ${type.inputType}Holder in;
   @Workspace ${type.sumRunningType}Holder sum;
   @Workspace ${type.countRunningType}Holder count;
+  @Workspace BigIntHolder nonNullCount;
   @Output ${type.outputType}Holder out;
 
   public void setup() {
   	sum = new ${type.sumRunningType}Holder();
     count = new ${type.countRunningType}Holder();
+    nonNullCount = new BigIntHolder();
+    nonNullCount.value = 0;
     sum.value = 0;
     count.value = 0;
   }
@@ -75,6 +75,7 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 		    break sout;
 	    }
 	  </#if>
+    nonNullCount.value = 1;
 	  <#if aggrtype.funcName == "avg">
     <#if type.inputType.endsWith("Interval")>
     sum.value += (long) in.months * org.apache.drill.exec.expr.fn.impl.DateUtility.monthToStandardDays +
@@ -98,21 +99,27 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Override
   public void output() {
-    double millis = sum.value / ((double) count.value);
-    <#if type.inputType.endsWith("Interval") || type.inputType.endsWith("IntervalYear")>
-    out.months = (int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis);
-    millis = millis % org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis;
-    out.days =(int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    out.milliseconds = (int) (millis % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    <#elseif type.inputType.endsWith("IntervalDay")>
-    out.months = 0;
-    out.days = (int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    out.milliseconds = (int) (millis % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
-    </#if>
+    if (nonNullCount.value > 0) {
+      out.isSet = 1;
+      double millis = sum.value / ((double) count.value);
+      <#if type.inputType.endsWith("Interval") || type.inputType.endsWith("IntervalYear")>
+      out.months = (int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis);
+      millis = millis % org.apache.drill.exec.expr.fn.impl.DateUtility.monthsToMillis;
+      out.days =(int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      out.milliseconds = (int) (millis % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      <#elseif type.inputType.endsWith("IntervalDay")>
+      out.months = 0;
+      out.days = (int) (millis / org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      out.milliseconds = (int) (millis % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+      </#if>
+    } else {
+      out.isSet = 0;
+    }
   }
 
   @Override
   public void reset() {
+    nonNullCount.value = 0;
     sum.value = 0;
     count.value = 0;
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java b/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java
index 53474ea..14cea5b 100644
--- a/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java
+++ b/exec/java-exec/src/main/codegen/templates/VarCharAggrFunctions1.java
@@ -24,13 +24,11 @@
 
 <#include "/@includes/license.ftl" />
 
+// Source code generated using FreeMarker template ${.template_name}
+
 <#-- A utility class that is used to generate java code for aggr functions that maintain a single -->
 <#-- running counter to hold the result.  This includes: MIN, MAX, COUNT. -->
 
-/*
- * This class is automatically generated from VarCharAggrFunctions1.java using FreeMarker.
- */
-
 package org.apache.drill.exec.expr.fn.impl.gaggr;
 
 <#include "/@includes/vv_imports.ftl" />
@@ -60,27 +58,20 @@ public class ${aggrtype.className}VarBytesFunctions {
 public static class ${type.inputType}${aggrtype.className} implements DrillAggFunc{
 
   @Param ${type.inputType}Holder in;
-  <#if aggrtype.funcName == "max" || aggrtype.funcName == "min">
   @Workspace ObjectHolder value;
-  @Workspace UInt1Holder init; 
+  @Workspace UInt1Holder init;
+  @Workspace BigIntHolder nonNullCount;
   @Inject DrillBuf buf;
-  <#else>
-  @Workspace  ${type.runningType}Holder value;
-  </#if>
   @Output ${type.outputType}Holder out;
 
   public void setup() {
-    <#if aggrtype.funcName == "max" || aggrtype.funcName == "min">
     init = new UInt1Holder();
+    nonNullCount = new BigIntHolder();
+    nonNullCount.value = 0;
     init.value = 0;
     value = new ObjectHolder();
     org.apache.drill.exec.expr.fn.impl.DrillByteArray tmp = new org.apache.drill.exec.expr.fn.impl.DrillByteArray();
     value.obj = tmp;
-
-    <#else>
-    value = new ${type.runningType}Holder();
-    value.value = 0;
-    </#if>
   }
 
   @Override
@@ -92,7 +83,7 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
         break sout;
       }
     </#if>
-    <#if aggrtype.funcName == "max" || aggrtype.funcName == "min">
+    nonNullCount.value = 1;
     org.apache.drill.exec.expr.fn.impl.DrillByteArray tmp = (org.apache.drill.exec.expr.fn.impl.DrillByteArray) value.obj;
     int cmp = 0;
     boolean swap = false;
@@ -123,9 +114,6 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
         tmp.setBytes(tempArray);
       }
     }
-    <#else>
-    value.value++;
-    </#if>
     <#if type.inputType?starts_with("Nullable")>
     } // end of sout block
 	  </#if>
@@ -133,27 +121,24 @@ public static class ${type.inputType}${aggrtype.className} implements DrillAggFu
 
   @Override
   public void output() {
-    <#if aggrtype.funcName == "max" || aggrtype.funcName == "min">
-    org.apache.drill.exec.expr.fn.impl.DrillByteArray tmp = (org.apache.drill.exec.expr.fn.impl.DrillByteArray) value.obj;
-    buf = buf.reallocIfNeeded(tmp.getLength());
-    buf.setBytes(0, tmp.getBytes(), 0, tmp.getLength());
-    out.start  = 0;
-    out.end    = tmp.getLength();
-    out.buffer = buf;
-    <#else>
-    out.value = value.value;
-    </#if>
+    if (nonNullCount.value > 0) {
+      out.isSet = 1;
+      org.apache.drill.exec.expr.fn.impl.DrillByteArray tmp = (org.apache.drill.exec.expr.fn.impl.DrillByteArray) value.obj;
+      buf = buf.reallocIfNeeded(tmp.getLength());
+      buf.setBytes(0, tmp.getBytes(), 0, tmp.getLength());
+      out.start  = 0;
+      out.end    = tmp.getLength();
+      out.buffer = buf;
+    } else {
+      out.isSet = 0;
+    }
   }
 
   @Override
   public void reset() {
-    <#if aggrtype.funcName == "max" || aggrtype.funcName == "min">
     value = new ObjectHolder();
     init.value = 0;
-    <#else>
-    value = new ${type.runningType}Holder();
-    value.value = 0;
-    </#if>
+    nonNullCount.value = 0;
   }
 }
 </#if>

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java
index 3925370..d39df8f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java
@@ -178,7 +178,7 @@ public class JoinUtils {
         // currently we only support implicit casts if the input types are numeric or varchar/varbinary
         if (!allowImplicitCast(rightType, leftType)) {
           throw new DrillRuntimeException(String.format("Join only supports implicit casts between " +
-              "1. Numeric data\n 2. Varchar, Varbinary data " +
+              "1. Numeric data\n 2. Varchar, Varbinary data 3. Date, Timestamp data " +
               "Left type: %s, Right type: %s. Add explicit casts to avoid this error", leftType, rightType));
         }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/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 01db7c2..69a7cbf 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
@@ -207,7 +207,7 @@ public class TestAggregateFunctions extends BaseTestQuery {
         .go();
   }
 
-  @Test
+  @Test // test aggregates when input is empty and data type is optional
   public void testAggregateWithEmptyInput() throws Exception {
     String query = "select " +
         "count(employee_id) col1, avg(employee_id) col2, sum(employee_id) col3 " +
@@ -220,4 +220,73 @@ public class TestAggregateFunctions extends BaseTestQuery {
         .baselineValues(0l, null, null)
         .go();
   }
+
+  @Test // test aggregates when input is empty and data type is required
+  public void testAggregateWithEmptyRequiredInput() throws Exception {
+    // test min function on required type
+    String query = "select " +
+        "min(bool_col) col1, min(int_col) col2, min(bigint_col) col3, min(float4_col) col4, min(float8_col) col5, " +
+        "min(date_col) col6, min(time_col) col7, min(timestamp_col) col8, min(interval_year_col) col9, " +
+        "min(varhcar_col) col10 " +
+        "from cp.`parquet/alltypes_required.parquet` where 1 = 0";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8", "col9", "col10")
+        .baselineValues(null, null, null, null, null, null, null, null, null, null)
+        .go();
+
+    // test max function
+    query = "select " +
+        "max(int_col) col1, max(bigint_col) col2, max(float4_col) col3, max(float8_col) col4, " +
+        "max(date_col) col5, max(time_col) col6, max(timestamp_col) col7, max(interval_year_col) col8, " +
+        "max(varhcar_col) col9 " +
+        "from cp.`parquet/alltypes_required.parquet` where 1 = 0";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8", "col9")
+        .baselineValues(null, null, null, null, null, null, null, null, null)
+        .go();
+
+    // test sum function
+    query = "select " +
+        "sum(int_col) col1, sum(bigint_col) col2, sum(float4_col) col3, sum(float8_col) col4, sum(interval_year_col) col5 " +
+        "from cp.`employee.json` where 1 = 0";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2", "col3", "col4", "col5")
+        .baselineValues(null, null, null, null, null)
+        .go();
+
+    // test avg function
+    query = "select " +
+        "avg(int_col) col1, avg(bigint_col) col2, avg(float4_col) col3, avg(float8_col) col4, avg(interval_year_col) col5 " +
+        "from cp.`employee.json` where 1 = 0";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2", "col3", "col4", "col5")
+        .baselineValues(null, null, null, null, null)
+        .go();
+
+    // test stddev function
+    query = "select " +
+        "stddev_pop(int_col) col1, stddev_pop(bigint_col) col2, stddev_pop(float4_col) col3, " +
+        "stddev_pop(float8_col) col4, stddev_pop(interval_year_col) col5 " +
+        "from cp.`employee.json` where 1 = 0";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2", "col3", "col4", "col5")
+        .baselineValues(null, null, null, null, null)
+        .go();
+
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
index b39566a..d2616a8 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java
@@ -42,6 +42,7 @@ import org.apache.drill.exec.rpc.user.UserServer.UserClientConnection;
 import org.apache.drill.exec.server.DrillbitContext;
 import org.apache.drill.exec.vector.BigIntVector;
 import org.apache.drill.exec.vector.IntVector;
+import org.apache.drill.exec.vector.NullableBigIntVector;
 import org.junit.Test;
 
 import com.codahale.metrics.MetricRegistry;
@@ -100,7 +101,7 @@ public class TestAgg extends ExecTest {
       IntVector key1 = exec.getValueVectorById(SchemaPath.getSimplePath("key1"), IntVector.class);
       BigIntVector key2 = exec.getValueVectorById(SchemaPath.getSimplePath("key2"), BigIntVector.class);
       BigIntVector cnt = exec.getValueVectorById(SchemaPath.getSimplePath("cnt"), BigIntVector.class);
-      BigIntVector total = exec.getValueVectorById(SchemaPath.getSimplePath("total"), BigIntVector.class);
+      NullableBigIntVector total = exec.getValueVectorById(SchemaPath.getSimplePath("total"), NullableBigIntVector.class);
       Integer[] keyArr1 = {Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE};
       long[] keyArr2 = {0,1,2,0,1,2};
       long[] cntArr = {34,34,34,34,34,34};

http://git-wip-us.apache.org/repos/asf/drill/blob/6a7de92e/exec/java-exec/src/test/resources/parquet/alltypes_required.parquet
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/parquet/alltypes_required.parquet b/exec/java-exec/src/test/resources/parquet/alltypes_required.parquet
new file mode 100644
index 0000000..549e316
Binary files /dev/null and b/exec/java-exec/src/test/resources/parquet/alltypes_required.parquet differ


Mime
View raw message