added test cases for issue 412
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.1.ddl.aql
deleted file mode 100644
index e69de29..0000000
--- a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.1.ddl.aql
+++ /dev/null
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.2.update.aql
deleted file mode 100644
index e69de29..0000000
--- a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.2.update.aql
+++ /dev/null
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.3.query.aql
deleted file mode 100644
index 0ff1d3c..0000000
--- a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue186/issue186.3.query.aql
+++ /dev/null
@@ -1,3 +0,0 @@
-for $x in [1, 2]
-let $y := (for $i in [[1,2,3],[10,20,30],[-2,-5,0]] return min($i))
-return min($y)
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_0/issue412_0.1.ddl.aql
similarity index 100%
rename from asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.1.ddl.aql
rename to asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_0/issue412_0.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_0/issue412_0.2.update.aql
similarity index 100%
rename from asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.2.update.aql
rename to asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_0/issue412_0.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_0/issue412_0.3.query.aql
similarity index 100%
rename from asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.3.query.aql
rename to asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_0/issue412_0.3.query.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_1/issue412_1.1.ddl.aql
similarity index 100%
copy from asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.1.ddl.aql
copy to asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_1/issue412_1.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_1/issue412_1.2.update.aql
similarity index 100%
copy from asterix-app/src/test/resources/runtimets/queries/aggregate/issue412/issue412.2.update.aql
copy to asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_1/issue412_1.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_1/issue412_1.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_1/issue412_1.3.query.aql
new file mode 100644
index 0000000..f9bc64e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate/issue412_1/issue412_1.3.query.aql
@@ -0,0 +1,2 @@
+let $l := [1, 60, null]
+return { "count": count($l), "average": avg($l), "sum": sum($l), "min": min($l), "max": max($l) } 
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate/issue186/issue186.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate/issue186/issue186.1.adm
deleted file mode 100644
index 978069e..0000000
--- a/asterix-app/src/test/resources/runtimets/results/aggregate/issue186/issue186.1.adm
+++ /dev/null
@@ -1,2 +0,0 @@
--5
--5
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate/issue412/issue412.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate/issue412_0/issue412_0.1.adm
similarity index 100%
rename from asterix-app/src/test/resources/runtimets/results/aggregate/issue412/issue412.1.adm
rename to asterix-app/src/test/resources/runtimets/results/aggregate/issue412_0/issue412_0.1.adm
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate/issue412_1/issue412_1.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate/issue412_1/issue412_1.1.adm
new file mode 100644
index 0000000..7c1107a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate/issue412_1/issue412_1.1.adm
@@ -0,0 +1 @@
+{ "count": 3, "average": null, "sum": null, "min": null, "max": null }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate/scalar_count_null/scalar_count_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate/scalar_count_null/scalar_count_null.1.adm
index 1abbc3f..4ff1111 100644
--- a/asterix-app/src/test/resources/runtimets/results/aggregate/scalar_count_null/scalar_count_null.1.adm
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate/scalar_count_null/scalar_count_null.1.adm
@@ -1,7 +1,7 @@
-null
-null
-null
-null
-null
-null
-null
\ No newline at end of file
+4
+4
+4
+4
+4
+4
+4
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 5849110..c79efac 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -1,18 +1,18 @@
 <test-suite xmlns="urn:xml.testframework.asterix.ics.uci.edu" ResultOffsetPath="results" QueryOffsetPath="queries" QueryFileExtension=".aql">
   <test-group name="aggregate">
     <test-case FilePath="aggregate">
-      <compilation-unit name="issue186">
-        <output-dir compare="Text">issue186</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="aggregate">
       <compilation-unit name="issue395">
         <output-dir compare="Text">issue395</output-dir>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
-      <compilation-unit name="issue412">
-        <output-dir compare="Text">issue412</output-dir>
+      <compilation-unit name="issue412_0">
+        <output-dir compare="Text">issue412_0</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate">
+      <compilation-unit name="issue412_1">
+        <output-dir compare="Text">issue412_1</output-dir>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java
index c8ba938..9126065 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java
@@ -1,6 +1,5 @@
 package edu.uci.ics.asterix.om.typecomputer.impl;
 
-
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.AUnionType;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateFunction.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateFunction.java
index e4d015b..82c1e8a 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateFunction.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateFunction.java
@@ -6,7 +6,6 @@
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.AInt32;
 import edu.uci.ics.asterix.om.base.AMutableInt32;
-import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
@@ -20,19 +19,15 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 /**
- * count(NULL) returns NULL.
+ * COUNT returns the number of items in the given list. Note that COUNT(NULL) is not allowed.
  */
 public class CountAggregateFunction implements ICopyAggregateFunction {
     private AMutableInt32 result = new AMutableInt32(-1);
     @SuppressWarnings("unchecked")
     private ISerializerDeserializer<AInt32> int32Serde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.AINT32);
-    @SuppressWarnings("unchecked")
-    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-            .getSerializerDeserializer(BuiltinType.ANULL);
     private ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
     private ICopyEvaluator eval;
-    private boolean metNull;
     private int cnt;
     private DataOutput out;
 
@@ -44,7 +39,6 @@
     @Override
     public void init() {
         cnt = 0;
-        metNull = false;
     }
 
     @Override
@@ -53,9 +47,7 @@
         eval.evaluate(tuple);
         ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal.getByteArray()[0]);
         // Ignore SYSTEM_NULL.
-        if (typeTag == ATypeTag.NULL) {
-            metNull = true;
-        } else {
+        if (typeTag != ATypeTag.SYSTEM_NULL) {
             cnt++;
         }
     }
@@ -63,12 +55,8 @@
     @Override
     public void finish() throws AlgebricksException {
         try {
-            if (metNull) {
-                nullSerde.serialize(ANull.NULL, out);
-            } else {
-                result.setValue(cnt);
-                int32Serde.serialize(result, out);
-            }
+            result.setValue(cnt);
+            int32Serde.serialize(result, out);
         } catch (IOException e) {
             throw new AlgebricksException(e);
         }