Added tests for all the sql-aggregate functions.
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.1.ddl.aql
new file mode 100644
index 0000000..aae98cc
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.1.ddl.aql
@@ -0,0 +1,5 @@
+/*
+* Description  : Run aggregates over both ordered list and unordered list with only null items.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.3.query.aql
new file mode 100644
index 0000000..f4fb020
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null/agg_null.3.query.aql
@@ -0,0 +1,9 @@
+/*
+* Description  : Run aggregates over both ordered list and unordered list with only null items.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+let $l1 := [null]
+let $l2 := {{null, null}}
+return { "sql-count1": sql-count($l1), "average1": sql-avg($l1), "sql-sum1": sql-sum($l1), "sql-min1": sql-min($l1), "sql-max1": sql-max($l1), "sql-count2": sql-count($l2), "average2": sql-avg($l2), "sql-sum2": sql-sum($l2), "sql-min2": sql-min($l2), "sql-max2": sql-max($l2) } 
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.1.ddl.aql
new file mode 100644
index 0000000..3546456
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.1.ddl.aql
@@ -0,0 +1,16 @@
+/*
+* Description  : Run aggregates over records, with only null items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type TestType as open {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.2.update.aql
new file mode 100644
index 0000000..75bc00e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.2.update.aql
@@ -0,0 +1,11 @@
+/*
+* Description  : Run aggregates over records, with only null items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+use dataverse test;
+
+insert into dataset Test ({"id": 0, "val": 4.32, "valplus": 21});
+insert into dataset Test ({"id": 1, "val": 5.32});
+insert into dataset Test ({"id": 2, "val": 6.32, "valplus": 31});
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.3.query.aql
new file mode 100644
index 0000000..19463da
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec/agg_null_rec.3.query.aql
@@ -0,0 +1,10 @@
+/*
+* Description  : Run aggregates over records, with only null items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+use dataverse test;
+
+let $l := for $t in dataset Test return $t.valplus
+return { "sql-count": sql-count($l), "average": sql-avg($l), "sql-sum": sql-sum($l), "sql-min": sql-min($l), "sql-max": sql-max($l) }  
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.1.ddl.aql
new file mode 100644
index 0000000..3546456
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.1.ddl.aql
@@ -0,0 +1,16 @@
+/*
+* Description  : Run aggregates over records, with only null items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type TestType as open {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.2.update.aql
new file mode 100644
index 0000000..4e0db2b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.2.update.aql
@@ -0,0 +1,11 @@
+/*
+* Description  : Run aggregates over records, with only null items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+use dataverse test;
+
+insert into dataset Test ({"id": 0, "val": 4.32, "valplus": 473847});
+insert into dataset Test ({"id": 1, "val": 5.32});
+insert into dataset Test ({"id": 2, "val": 6.32, "valplus": 38473827484738239});
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.3.query.aql
new file mode 100644
index 0000000..14ed81d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_null_rec_1/agg_null_rec_1.3.query.aql
@@ -0,0 +1,12 @@
+/*
+* Description  : Run aggregates over records, with only null items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+use dataverse test;
+
+let $l := for $t in dataset Test return $t
+return { "sql-count": sql-count($l), "average": sql-avg(for $i in $l return $i.val), "sql-sum":
+sql-sum(for $i in $l return $i.val), "sql-min": sql-min(for $i in $l return $i.valplus),
+"sql-max": sql-max(for $i in $l return $i.valplus) }
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.1.ddl.aql
new file mode 100644
index 0000000..343be89
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.1.ddl.aql
@@ -0,0 +1,6 @@
+/*
+* Description  : Run aggregates over an ordered list with numbers of different types
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.3.query.aql
new file mode 100644
index 0000000..33e8b03
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number/agg_number.3.query.aql
@@ -0,0 +1,15 @@
+/*
+* Description  : Run aggregates over an ordered list with numbers of different types
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+let $l1 := [float("2.0"), double("3.0"), 93847382783847382, 1]
+let $l2 := {{float("2.0"), double("3.0"), 93847382783847382, 1}}
+let $a1 := sql-count($l2)
+let $a2 := sql-avg($l2)
+let $a3 := sql-sum($l2)
+let $a4 := sql-min($l2)
+let $a5 := sql-max($l2)
+return { "sql-count1": sql-count($l1), "average1": sql-avg($l1), "sql-sum1": sql-sum($l1), "sql-min1": sql-min($l1), "sql-max1": sql-max($l1), "sql-count2": $a1, "average2": $a2, "sql-sum2": $a3, "sql-min2": $a4, "sql-max2": $a5 }
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.1.ddl.aql
new file mode 100644
index 0000000..53a50fb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.1.ddl.aql
@@ -0,0 +1,16 @@
+/*
+* Description  : Run aggregates over records, with different numeric typed items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type TestType as open {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.2.update.aql
new file mode 100644
index 0000000..86aeb85
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.2.update.aql
@@ -0,0 +1,11 @@
+/*
+* Description  : Run aggregates over records, with different numeric typed items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+use dataverse test;
+
+insert into dataset Test ({"id": 0, "val": 4.32, "valplus": 2});
+insert into dataset Test ({"id": 1, "val": 5.32, "valplus": 32.98});
+insert into dataset Test ({"id": 2, "val": 6.32, "valplus": 38473827484738239});
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.3.query.aql
new file mode 100644
index 0000000..9588561
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/agg_number_rec/agg_number_rec.3.query.aql
@@ -0,0 +1,10 @@
+/*
+* Description  : Run aggregates over records, with different numeric typed items for the aggregating fields.
+* Expected Res : Success
+* Date         : Jun 2nd 2013
+*/
+
+use dataverse test;
+
+let $l := for $t in dataset Test return $t.valplus
+return { "sql-count": sql-count($l), "average": sql-avg($l), "sql-sum": sql-sum($l), "sql-min": sql-min($l), "sql-max": sql-max($l) }  
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.1.ddl.aql
new file mode 100644
index 0000000..55ab0f7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.1.ddl.aql
@@ -0,0 +1,6 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.3.query.aql
new file mode 100644
index 0000000..b4cb727
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double/avg_double.3.query.aql
@@ -0,0 +1,5 @@
+sql-avg(
+ for $x in [1.0, 2.0, double("3.0")]
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.2.update.aql
new file mode 100644
index 0000000..1ecf3aa
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.3.query.aql
new file mode 100644
index 0000000..2b9e5ce
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_double_null/avg_double_null.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $a := sql-avg( 
+ for $x in dataset('Numeric') 
+ return $x.doubleField
+)
+return {"average": $a}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.1.ddl.aql
new file mode 100644
index 0000000..0970752
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.1.ddl.aql
@@ -0,0 +1,9 @@
+/*
+ * Description    : Tests that sql-avg aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.2.update.aql
new file mode 100644
index 0000000..e078b9a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.2.update.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests that sql-avg aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+// no inserts, deletes
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.3.query.aql
new file mode 100644
index 0000000..f659fcf
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_01/avg_empty_01.3.query.aql
@@ -0,0 +1,13 @@
+/*
+ * Description    : Tests that sql-avg aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-avg(
+ for $x in [1, 2, 3]
+ where $x > 10
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.1.ddl.aql
new file mode 100644
index 0000000..1c7ee1c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.1.ddl.aql
@@ -0,0 +1,18 @@
+/*
+ * Description    : Tests that sql-avg aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type TestType as closed {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.2.update.aql
new file mode 100644
index 0000000..7b6bb9c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.2.update.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests that sql-avg aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+// no inserts, deletes
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.3.query.aql
new file mode 100644
index 0000000..7f7489c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_empty_02/avg_empty_02.3.query.aql
@@ -0,0 +1,12 @@
+/*
+ * Description    : Tests that sql-avg aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-avg(
+ for $x in dataset('Test')
+ return $x.val
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.1.ddl.aql
new file mode 100644
index 0000000..97b4670
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.1.ddl.aql
@@ -0,0 +1,4 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.3.query.aql
new file mode 100644
index 0000000..a106705
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float/avg_float.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-avg( 
+ for $x in [float("1"), float("2"), float("3")] 
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.3.query.aql
new file mode 100644
index 0000000..fdadd1d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_float_null/avg_float_nu.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $a := sql-avg( 
+ for $x in dataset('Numeric') 
+ return $x.floatField
+)
+return {"average": $a}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.1.ddl.aql
new file mode 100644
index 0000000..97b4670
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.1.ddl.aql
@@ -0,0 +1,4 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.3.query.aql
new file mode 100644
index 0000000..c204756
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16/avg_int16.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-avg( 
+ for $x in [int16("1"), int16("2"), int16("3")] 
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.3.query.aql
new file mode 100644
index 0000000..738cc6d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int16_null/avg_int16_null.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $a := sql-avg( 
+ for $x in dataset('Numeric') 
+ return $x.int16Field
+)
+return {"average": $a}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.1.ddl.aql
new file mode 100644
index 0000000..97b4670
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.1.ddl.aql
@@ -0,0 +1,4 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.3.query.aql
new file mode 100644
index 0000000..52d5e9b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32/avg_int32.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+sql-avg( 
+ for $x in [1, 2, 3] 
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.3.query.aql
new file mode 100644
index 0000000..a2f16e0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int32_null/avg_int32_null.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $a := sql-avg( 
+ for $x in dataset('Numeric') 
+ return $x.int32Field
+)
+return {"average": $a}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.1.ddl.aql
new file mode 100644
index 0000000..d330bc0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.1.ddl.aql
@@ -0,0 +1,3 @@
+drop dataverse test if exists;
+
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.3.query.aql
new file mode 100644
index 0000000..fa668c1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64/avg_int64.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-avg( 
+ for $x in [int64("1"), int64("2"), int64("3")] 
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.3.query.aql
new file mode 100644
index 0000000..9534dc6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int64_null/avg_int64_null.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $a := sql-avg( 
+ for $x in dataset('Numeric') 
+ return $x.int64Field
+)
+return {"average": $a}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.1.ddl.aql
new file mode 100644
index 0000000..d330bc0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.1.ddl.aql
@@ -0,0 +1,3 @@
+drop dataverse test if exists;
+
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.3.query.aql
new file mode 100644
index 0000000..fc77503
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8/avg_int8.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-avg( 
+ for $x in [int8("1"),int8("2"), int8("3")] 
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.1.ddl.aql
new file mode 100644
index 0000000..5cf8ddf
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.1.ddl.aql
@@ -0,0 +1,19 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.3.query.aql
new file mode 100644
index 0000000..f5d91bf
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_int8_null/avg_int8_null.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $a := sql-avg( 
+ for $x in dataset('Numeric') 
+ return $x.int8Field
+)
+return {"average": $a}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.1.ddl.aql
new file mode 100644
index 0000000..174f7c9
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.1.ddl.aql
@@ -0,0 +1,5 @@
+/*
+* Description  : Run sql-avg over an ordered list with mixed types
+* Expected Res : Failure
+* Date         : Jun 2nd 2013
+*/
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.3.query.aql
new file mode 100644
index 0000000..fbcc3a6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/avg_mixed/avg_mixed.3.query.aql
@@ -0,0 +1,11 @@
+/*
+* Description  : Run sql-avg over an ordered list with mixed types
+* Expected Res : Failure
+* Date         : Jun 2nd 2013
+*/
+
+sql-avg(
+ for $x in [float("2.0"), "hello world", 93847382783847382, date("2013-01-01")]
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.1.ddl.aql
new file mode 100644
index 0000000..55ab0f7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.1.ddl.aql
@@ -0,0 +1,6 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.3.query.aql
new file mode 100644
index 0000000..0d87f51
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_01/count_01.3.query.aql
@@ -0,0 +1,12 @@
+use dataverse test;
+
+sql-count( 
+ for $x in [1, 2, 3] 
+ return $x
+)
+
+
+
+
+
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.1.ddl.aql
new file mode 100644
index 0000000..22b6585
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.1.ddl.aql
@@ -0,0 +1,10 @@
+/*
+ * Description    : Tests that sql-count aggregation correctly returns 0 for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.2.update.aql
new file mode 100644
index 0000000..6d86705
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests that sql-count aggregation correctly returns 0 for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.3.query.aql
new file mode 100644
index 0000000..27a7aa7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_01/count_empty_01.3.query.aql
@@ -0,0 +1,11 @@
+/*
+ * Description    : Tests that sql-count aggregation correctly returns 0 for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+sql-count(
+ for $x in [1, 2, 3]
+ where $x > 10
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.1.ddl.aql
new file mode 100644
index 0000000..0770bfb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.1.ddl.aql
@@ -0,0 +1,17 @@
+/*
+ * Description    : Tests that sql-count aggregation correctly returns 0 for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type TestType as closed {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.2.update.aql
new file mode 100644
index 0000000..774e6ca
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests that sql-count aggregation correctly returns 0 for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.3.query.aql
new file mode 100644
index 0000000..33c080a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_empty_02/count_empty_02.3.query.aql
@@ -0,0 +1,11 @@
+/*
+ * Description    : Tests that sql-count aggregation correctly returns 0 for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+use dataverse test;
+
+sql-count(
+ for $x in dataset('Test')
+ return $x.val
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.3.query.aql
new file mode 100644
index 0000000..2e15415
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/count_null/count_null.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $c := sql-count( 
+ for $x in dataset('Numeric') 
+ return $x.doubleField
+)
+return {"sql-count": $c}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.1.ddl.aql
new file mode 100644
index 0000000..7c6368c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.1.ddl.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type Emp as open {
+id:int32,
+name:string ?
+}
+
+create dataset Employee(Emp) primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.2.update.aql
new file mode 100644
index 0000000..d92b582
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.2.update.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+insert into dataset Employee({"id":12,"name":"John Doe"});
+insert into dataset Employee({"id":42});
+insert into dataset Employee({"id":22,"name":"John Smith"});
+insert into dataset Employee({"id":19});
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.3.query.aql
new file mode 100644
index 0000000..809f0e2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue395/issue395.3.query.aql
@@ -0,0 +1,4 @@
+use dataverse test;
+
+sql-count(for $l in dataset Employee
+return $l.name)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.1.ddl.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.3.query.aql
new file mode 100644
index 0000000..0bced9f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_0/issue412_0.3.query.aql
@@ -0,0 +1,2 @@
+let $l := ["ASTERIX", "Hyracks", null]
+return sql-count($l)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.1.ddl.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.3.query.aql
new file mode 100644
index 0000000..de6ab96
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue412_1/issue412_1.3.query.aql
@@ -0,0 +1,2 @@
+let $l := [1, 60, null]
+return { "sql-count": sql-count($l), "average": sql-avg($l), "sql-sum": sql-sum($l), "sql-min": sql-min($l), "sql-max": sql-max($l) } 
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.1.ddl.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.3.query.aql
new file mode 100644
index 0000000..5a0e3b2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.3.query.aql
@@ -0,0 +1,2 @@
+let $l := [23, 748374857483]
+return sql-min($l)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.1.ddl.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.3.query.aql
new file mode 100644
index 0000000..9f436a5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.3.query.aql
@@ -0,0 +1,2 @@
+let $l := [748374857483, 23, 0.5]
+return sql-min($l)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.1.ddl.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.3.query.aql
new file mode 100644
index 0000000..f8fd365
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.3.query.aql
@@ -0,0 +1,2 @@
+let $l := [23, 748374857483]
+return sql-sum($l)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.1.ddl.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.3.query.aql
new file mode 100644
index 0000000..0512478
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.3.query.aql
@@ -0,0 +1,2 @@
+let $l := [748374857483, 23, 0.5]
+return sql-sum($l)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.1.ddl.aql
new file mode 100644
index 0000000..5f9957f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.1.ddl.aql
@@ -0,0 +1,18 @@
+/**
+ * issue531_string_sql-min_sql-max
+ * 
+ * Purpose: test the support of string values for sql-min and sql-max aggregation function
+ * Result: success
+ * 
+ */
+ 
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type TestType as open{
+id:int32,
+name:string
+}
+
+create dataset t1(TestType) primary key id;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.2.update.aql
new file mode 100644
index 0000000..59572b5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.2.update.aql
@@ -0,0 +1,18 @@
+/**
+ * issue531_string_sql-min_sql-max
+ * 
+ * Purpose: test the support of string values for sql-min and sql-max aggregation function
+ * Result: success
+ * 
+ */
+
+use dataverse test;
+
+insert into dataset t1({"id":5,"name":"Smith"});
+insert into dataset t1({"id":12,"name":"Roger"});
+insert into dataset t1({"id":67,"name":"Kevin"});
+insert into dataset t1({"id":32,"name":"Bob"});
+insert into dataset t1({"id":89,"name":"John"});
+insert into dataset t1({"id":10,"name":"Alex"});
+insert into dataset t1({"id":37,"name":"Calvin"});
+insert into dataset t1({"id":98,"name":"Susan"});
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.3.query.aql
new file mode 100644
index 0000000..1eca77a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/issue531_string_min_max/issue531_string_min_max.3.query.aql
@@ -0,0 +1,13 @@
+/**
+ * issue531_string_sql-min_sql-max
+ * 
+ * Purpose: test the support of string values for sql-min and sql-max aggregation function
+ * Result: success
+ * 
+ */
+
+use dataverse test;
+
+{"sql-min": sql-min(for $l in dataset t1
+return $l.name), "sql-max": sql-max(for $l in dataset t1
+return $l.name)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.1.ddl.aql
new file mode 100644
index 0000000..6a3be49
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.1.ddl.aql
@@ -0,0 +1,9 @@
+/*
+ * Description    : Tests that sql-max aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.2.update.aql
new file mode 100644
index 0000000..53df1c8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.2.update.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests that sql-max aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+// no inserts/deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.3.query.aql
new file mode 100644
index 0000000..e7bccb0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_01/max_empty_01.3.query.aql
@@ -0,0 +1,13 @@
+/*
+ * Description    : Tests that sql-max aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-max(
+ for $x in [1, 2, 3]
+ where $x > 10
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.1.ddl.aql
new file mode 100644
index 0000000..6f6b50a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.1.ddl.aql
@@ -0,0 +1,18 @@
+/*
+ * Description    : Tests that sql-max aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type TestType as closed {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.2.update.aql
new file mode 100644
index 0000000..421ae94
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests that sql-max aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.3.query.aql
new file mode 100644
index 0000000..02bfcf2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/max_empty_02/max_empty_02.3.query.aql
@@ -0,0 +1,12 @@
+/*
+ * Description    : Tests that sql-max aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-max(
+ for $x in dataset('Test')
+ return $x.val
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.1.ddl.aql
new file mode 100644
index 0000000..ead6e0d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests that sql-min aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.2.update.aql
new file mode 100644
index 0000000..a5d2f81
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.2.update.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests that sql-min aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+// no inserts/deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.3.query.aql
new file mode 100644
index 0000000..fba638c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_01/min_empty_01.3.query.aql
@@ -0,0 +1,13 @@
+/*
+ * Description    : Tests that sql-min aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-min(
+ for $x in [1, 2, 3]
+ where $x > 10
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.1.ddl.aql
new file mode 100644
index 0000000..4888947
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.1.ddl.aql
@@ -0,0 +1,18 @@
+/*
+ * Description    : Tests that sql-min aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type TestType as closed {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.2.update.aql
new file mode 100644
index 0000000..e88343a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.2.update.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests that sql-min aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+// no inserts and deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.3.query.aql
new file mode 100644
index 0000000..140759a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_empty_02/min_empty_02.3.query.aql
@@ -0,0 +1,12 @@
+/*
+ * Description    : Tests that sql-min aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-min(
+ for $x in dataset('Test')
+ return $x.val
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.1.ddl.aql
new file mode 100644
index 0000000..5ca35e0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.1.ddl.aql
@@ -0,0 +1,5 @@
+/*
+* Description  : Run sql-min over an ordered list with mixed types
+* Expected Res : Failure
+* Date         : Jun 2nd 2013
+*/
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.3.query.aql
new file mode 100644
index 0000000..5912d48
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/min_mixed/min_mixed.3.query.aql
@@ -0,0 +1,11 @@
+/*
+* Description  : Run sql-min over an ordered list with mixed types
+* Expected Res : Failure
+* Date         : Jun 2nd 2013
+*/
+
+sql-min(
+ for $x in [float("2.0"), "hello world", 93847382783847382, date("2013-01-01")]
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.1.ddl.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.1.ddl.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.3.query.aql
new file mode 100644
index 0000000..a36e018
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/query-issue400/query-issue400.3.query.aql
@@ -0,0 +1,9 @@
+/*
+ * Description  : This test case is to verify the fix for issue400
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=400
+ * Expected Res : Success
+ * Date         : 8th May 2013
+ */
+ 
+let $l := [[1,2,3,4,5],[6,7,8,9]]
+return sql-count(for $i in $l return $i)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.1.ddl.aql
new file mode 100644
index 0000000..5d15119
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-avg without nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.2.update.aql
new file mode 100644
index 0000000..e22fbfc
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-avg without nulls.
+ * Success        : Yes
+ */
+
+// no insert delete here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.3.query.aql
new file mode 100644
index 0000000..919767a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg/scalar_avg.3.query.aql
@@ -0,0 +1,15 @@
+/*
+ * Description    : Tests the scalar version of sql-avg without nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-avg([int8("1"), int8("2"), int8("3")])
+let $i16 := sql-avg([int16("1"), int16("2"), int16("3")])
+let $i32 := sql-avg([int32("1"), int32("2"), int32("3")])
+let $i64 := sql-avg([int64("1"), int64("2"), int64("3")])
+let $f := sql-avg([float("1"), float("2"), float("3")])
+let $d := sql-avg([double("1"), double("2"), double("3")])
+for $i in [$i8, $i16, $i32, $i64, $f, $d]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.1.ddl.aql
new file mode 100644
index 0000000..f219e4e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-avg with an empty list.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.2.update.aql
new file mode 100644
index 0000000..122b595
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-avg with an empty list.
+ * Success        : Yes
+ */
+
+// no insert delete here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.3.query.aql
new file mode 100644
index 0000000..e99927e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_empty/scalar_avg_empty.3.query.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-avg with an empty list.
+ * Success        : Yes
+ */
+
+sql-avg([ ])
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.1.ddl.aql
new file mode 100644
index 0000000..52f73bb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-avg with nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.2.update.aql
new file mode 100644
index 0000000..5871aba
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-avg with nulls.
+ * Success        : Yes
+ */
+
+// no inserts deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.3.query.aql
new file mode 100644
index 0000000..d44216d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_avg_null/scalar_avg_null.3.query.aql
@@ -0,0 +1,15 @@
+/*
+ * Description    : Tests the scalar version of sql-avg with nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-avg([int8("1"), int8("2"), int8("3"), null])
+let $i16 := sql-avg([int16("1"), int16("2"), int16("3"), null])
+let $i32 := sql-avg([int32("1"), int32("2"), int32("3"), null])
+let $i64 := sql-avg([int64("1"), int64("2"), int64("3"), null])
+let $f := sql-avg([float("1"), float("2"), float("3"), null])
+let $d := sql-avg([double("1"), double("2"), double("3"), null])
+for $i in [$i8, $i16, $i32, $i64, $f, $d]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.1.ddl.aql
new file mode 100644
index 0000000..6c7f633
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-count without nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.2.update.aql
new file mode 100644
index 0000000..2b20144
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-count without nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.3.query.aql
new file mode 100644
index 0000000..43fe3be
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count/scalar_count.3.query.aql
@@ -0,0 +1,16 @@
+/*
+ * Description    : Tests the scalar version of sql-count without nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-count([int8("1"), int8("2"), int8("3")])
+let $i16 := sql-count([int16("1"), int16("2"), int16("3")])
+let $i32 := sql-count([int32("1"), int32("2"), int32("3")])
+let $i64 := sql-count([int64("1"), int64("2"), int64("3")])
+let $f := sql-count([float("1"), float("2"), float("3")])
+let $d := sql-count([double("1"), double("2"), double("3")])
+let $s := sql-count(["a", "b", "c"])
+for $i in [$i8, $i16, $i32, $i64, $f, $d, $s]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.1.ddl.aql
new file mode 100644
index 0000000..3073723
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-count with an empty list.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.2.update.aql
new file mode 100644
index 0000000..4905d59
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-count with an empty list.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.3.query.aql
new file mode 100644
index 0000000..17f55b2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_empty/scalar_count_empty.3.query.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-count with an empty list.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-count([ ])
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.1.ddl.aql
new file mode 100644
index 0000000..b5f9603
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-count with nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.2.update.aql
new file mode 100644
index 0000000..e1216d3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-count with nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.3.query.aql
new file mode 100644
index 0000000..3bfa354
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_count_null/scalar_count_null.3.query.aql
@@ -0,0 +1,16 @@
+/*
+ * Description    : Tests the scalar version of sql-count with nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-count([int8("1"), int8("2"), int8("3"), null])
+let $i16 := sql-count([int16("1"), int16("2"), int16("3"), null])
+let $i32 := sql-count([int32("1"), int32("2"), int32("3"), null])
+let $i64 := sql-count([int64("1"), int64("2"), int64("3"), null])
+let $f := sql-count([float("1"), float("2"), float("3"), null])
+let $d := sql-count([double("1"), double("2"), double("3"), null])
+let $s := sql-count(["a", "b", "c", null])
+for $i in [$i8, $i16, $i32, $i64, $f, $d, $s]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.1.ddl.aql
new file mode 100644
index 0000000..5c72f61
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-max without nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.2.update.aql
new file mode 100644
index 0000000..be12602
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-max without nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.3.query.aql
new file mode 100644
index 0000000..dd55d7e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max/scalar_max.3.query.aql
@@ -0,0 +1,17 @@
+/*
+ * Description    : Tests the scalar version of sql-max without nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-max([int8("1"), int8("2"), int8("3")])
+let $i16 := sql-max([int16("1"), int16("2"), int16("3")])
+let $i32 := sql-max([int32("1"), int32("2"), int32("3")])
+let $i64 := sql-max([int64("1"), int64("2"), int64("3")])
+let $f := sql-max([float("1"), float("2"), float("3")])
+let $d := sql-max([double("1"), double("2"), double("3")])
+let $s := sql-max(["foo", "bar", "world"])
+let $dt := sql-max([datetime("2012-03-01T00:00:00Z"), datetime("2012-01-01T00:00:00Z"), datetime("2012-02-01T00:00:00Z")])
+for $i in [$i8, $i16, $i32, $i64, $f, $d, $s, $dt]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.1.ddl.aql
new file mode 100644
index 0000000..c593eb4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-max with an empty list.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.2.update.aql
new file mode 100644
index 0000000..c5c7707
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-max with an empty list.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.3.query.aql
new file mode 100644
index 0000000..4fb68a7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_empty/scalar_max_empty.3.query.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-max with an empty list.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-max([ ])
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.1.ddl.aql
new file mode 100644
index 0000000..79f8bd3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-max with nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.2.update.aql
new file mode 100644
index 0000000..9fb5537
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-max with nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.3.query.aql
new file mode 100644
index 0000000..2ef1361
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_max_null/scalar_max_null.3.query.aql
@@ -0,0 +1,17 @@
+/*
+ * Description    : Tests the scalar version of sql-max with nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-max([int8("1"), int8("2"), int8("3"), null])
+let $i16 := sql-max([int16("1"), int16("2"), int16("3"), null])
+let $i32 := sql-max([int32("1"), int32("2"), int32("3"), null])
+let $i64 := sql-max([int64("1"), int64("2"), int64("3"), null])
+let $f := sql-max([float("1"), float("2"), float("3"), null])
+let $d := sql-max([double("1"), double("2"), double("3"), null])
+let $s := sql-max(["foo", "bar", "world", null])
+let $dt := sql-max([datetime("2012-03-01T00:00:00Z"), datetime("2012-01-01T00:00:00Z"), datetime("2012-02-01T00:00:00Z"), null])
+for $i in [$i8, $i16, $i32, $i64, $f, $d, $s, $dt]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.1.ddl.aql
new file mode 100644
index 0000000..2a64ea03a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-min without nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.2.update.aql
new file mode 100644
index 0000000..e6f3c83
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-min without nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.3.query.aql
new file mode 100644
index 0000000..3758080
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min/scalar_min.3.query.aql
@@ -0,0 +1,17 @@
+/*
+ * Description    : Tests the scalar version of sql-min without nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-min([int8("1"), int8("2"), int8("3")])
+let $i16 := sql-min([int16("1"), int16("2"), int16("3")])
+let $i32 := sql-min([int32("1"), int32("2"), int32("3")])
+let $i64 := sql-min([int64("1"), int64("2"), int64("3")])
+let $f := sql-min([float("1"), float("2"), float("3")])
+let $d := sql-min([double("1"), double("2"), double("3")])
+let $s := sql-min(["foo", "bar", "world"])
+let $dt := sql-min([datetime("2012-03-01T00:00:00Z"), datetime("2012-01-01T00:00:00Z"), datetime("2012-02-01T00:00:00Z")])
+for $i in [$i8, $i16, $i32, $i64, $f, $d, $s, $dt]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.1.ddl.aql
new file mode 100644
index 0000000..57e61b7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-min with an empty list.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.2.update.aql
new file mode 100644
index 0000000..ab4b309
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-min with an empty list.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.3.query.aql
new file mode 100644
index 0000000..f3aafa1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_empty/scalar_min_empty.3.query.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-min with an empty list.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-min([ ])
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.1.ddl.aql
new file mode 100644
index 0000000..bb1e400
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-min with nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.2.update.aql
new file mode 100644
index 0000000..26c9a6b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-min with nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.3.query.aql
new file mode 100644
index 0000000..032f125
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_min_null/scalar_min_null.3.query.aql
@@ -0,0 +1,17 @@
+/*
+ * Description    : Tests the scalar version of sql-min with nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-min([int8("1"), int8("2"), int8("3"), null])
+let $i16 := sql-min([int16("1"), int16("2"), int16("3"), null])
+let $i32 := sql-min([int32("1"), int32("2"), int32("3"), null])
+let $i64 := sql-min([int64("1"), int64("2"), int64("3"), null])
+let $f := sql-min([float("1"), float("2"), float("3"), null])
+let $d := sql-min([double("1"), double("2"), double("3"), null])
+let $s := sql-min(["foo", "bar", "world", null])
+let $dt := sql-min([datetime("2012-03-01T00:00:00Z"), datetime("2012-01-01T00:00:00Z"), datetime("2012-02-01T00:00:00Z"), null])
+for $i in [$i8, $i16, $i32, $i64, $f, $d, $s, $dt]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.1.ddl.aql
new file mode 100644
index 0000000..6734cc6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-sum without nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.2.update.aql
new file mode 100644
index 0000000..cacdd99
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-sum without nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.3.query.aql
new file mode 100644
index 0000000..adc94d3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum/scalar_sum.3.query.aql
@@ -0,0 +1,15 @@
+/*
+ * Description    : Tests the scalar version of sql-sum without nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-sum([int8("1"), int8("2"), int8("3")])
+let $i16 := sql-sum([int16("1"), int16("2"), int16("3")])
+let $i32 := sql-sum([int32("1"), int32("2"), int32("3")])
+let $i64 := sql-sum([int64("1"), int64("2"), int64("3")])
+let $f := sql-sum([float("1"), float("2"), float("3")])
+let $d := sql-sum([double("1"), double("2"), double("3")])
+for $i in [$i8, $i16, $i32, $i64, $f, $d]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.1.ddl.aql
new file mode 100644
index 0000000..f292f68
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-sum with an empty list.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.2.update.aql
new file mode 100644
index 0000000..36453e6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-sum with an empty list.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.3.query.aql
new file mode 100644
index 0000000..5ef7bfa
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_empty/scalar_sum_empty.3.query.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests the scalar version of sql-sum with an empty list.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-sum([ ])
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.1.ddl.aql
new file mode 100644
index 0000000..e3b6154
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.1.ddl.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests the scalar version of sql-sum with nulls.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.2.update.aql
new file mode 100644
index 0000000..f35e671
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.2.update.aql
@@ -0,0 +1,6 @@
+/*
+ * Description    : Tests the scalar version of sql-sum with nulls.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.3.query.aql
new file mode 100644
index 0000000..2d0e120
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/scalar_sum_null/scalar_sum_null.3.query.aql
@@ -0,0 +1,15 @@
+/*
+ * Description    : Tests the scalar version of sql-sum with nulls.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+let $i8 := sql-sum([int8("1"), int8("2"), int8("3"), null])
+let $i16 := sql-sum([int16("1"), int16("2"), int16("3"), null])
+let $i32 := sql-sum([int32("1"), int32("2"), int32("3"), null])
+let $i64 := sql-sum([int64("1"), int64("2"), int64("3"), null])
+let $f := sql-sum([float("1"), float("2"), float("3"), null])
+let $d := sql-sum([double("1"), double("2"), double("3"), null])
+for $i in [$i8, $i16, $i32, $i64, $f, $d]
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.1.ddl.aql
new file mode 100644
index 0000000..97b4670
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.1.ddl.aql
@@ -0,0 +1,4 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.3.query.aql
new file mode 100644
index 0000000..ddf3598
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double/sum_double.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in [1.0, 2.0, 3.0] 
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.3.query.aql
new file mode 100644
index 0000000..80692dd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_double_null/sum_double_null.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in dataset('Numeric') 
+ return $x.doubleField
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.1.ddl.aql
new file mode 100644
index 0000000..d7a0f6b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.1.ddl.aql
@@ -0,0 +1,8 @@
+/*
+ * Description    : Tests that sql-sum aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.2.update.aql
new file mode 100644
index 0000000..1feb209
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.2.update.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests that sql-sum aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.3.query.aql
new file mode 100644
index 0000000..eb5fe35
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_01/sum_empty_01.3.query.aql
@@ -0,0 +1,13 @@
+/*
+ * Description    : Tests that sql-sum aggregation correctly returns null for an empty stream,
+ *                  without an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-sum(
+ for $x in [1, 2, 3]
+ where $x > 10
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.1.ddl.aql
new file mode 100644
index 0000000..d43610e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.1.ddl.aql
@@ -0,0 +1,18 @@
+/*
+ * Description    : Tests that sql-sum aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type TestType as closed {
+  id: int32,
+  val: double
+}
+
+create dataset Test(TestType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.2.update.aql
new file mode 100644
index 0000000..c1670f9
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.2.update.aql
@@ -0,0 +1,7 @@
+/*
+ * Description    : Tests that sql-sum aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.3.query.aql
new file mode 100644
index 0000000..f46bfc1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_empty_02/sum_empty_02.3.query.aql
@@ -0,0 +1,12 @@
+/*
+ * Description    : Tests that sql-sum aggregation correctly returns null for an empty stream,
+ *                  with an aggregate combiner.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+sql-sum(
+ for $x in dataset('Test')
+ return $x.val
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.1.ddl.aql
new file mode 100644
index 0000000..97b4670
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.1.ddl.aql
@@ -0,0 +1,4 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.3.query.aql
new file mode 100644
index 0000000..9fcd5e0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float/sum_float.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in [float("1"), float("2"), float("3")] 
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.3.query.aql
new file mode 100644
index 0000000..7e6a126
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_float_null/sum_float_null.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in dataset('Numeric') 
+ return $x.floatField
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.1.ddl.aql
new file mode 100644
index 0000000..d330bc0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.1.ddl.aql
@@ -0,0 +1,3 @@
+drop dataverse test if exists;
+
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.3.query.aql
new file mode 100644
index 0000000..d11671a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16/sum_int16.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in [int16("1"), int16("2"), int16("3")] 
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.3.query.aql
new file mode 100644
index 0000000..89f6773
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int16_null/sum_int16_null.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in dataset('Numeric') 
+ return $x.int16Field
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.1.ddl.aql
new file mode 100644
index 0000000..d330bc0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.1.ddl.aql
@@ -0,0 +1,3 @@
+drop dataverse test if exists;
+
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.3.query.aql
new file mode 100644
index 0000000..e5f47cb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32/sum_int32.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in [1, 2, int32("3")] 
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.3.query.aql
new file mode 100644
index 0000000..521d291
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int32_null/sum_int32_null.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in dataset('Numeric') 
+ return $x.int32Field
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.1.ddl.aql
new file mode 100644
index 0000000..97b4670
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.1.ddl.aql
@@ -0,0 +1,4 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.3.query.aql
new file mode 100644
index 0000000..03bda35
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64/sum_int64.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in [int64("1"), int64("2"), int64("3")] 
+ return $x
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.2.update.aql
new file mode 100644
index 0000000..d93253f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes here
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.3.query.aql
new file mode 100644
index 0000000..c266a22
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int64_null/sum_int64_null.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in dataset('Numeric') 
+ return $x.int64Field
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.1.ddl.aql
new file mode 100644
index 0000000..d330bc0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.1.ddl.aql
@@ -0,0 +1,3 @@
+drop dataverse test if exists;
+
+create dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.2.update.aql
new file mode 100644
index 0000000..1ecf3aa
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.3.query.aql
new file mode 100644
index 0000000..a21c80c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8/sum_int8.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in [int8("1"), int8("2"), int8("3")] 
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.1.ddl.aql
new file mode 100644
index 0000000..7cdcbea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.1.ddl.aql
@@ -0,0 +1,20 @@
+drop dataverse test if exists;
+
+create dataverse test;
+
+use dataverse test;
+
+create type NumericType as open {
+  id: int32,
+  int8Field: int8?,
+  int16Field: int16?,
+  int32Field: int32?,
+  int64Field: int64?,
+  floatField: float?,
+  doubleField: double?
+}
+
+create external dataset Numeric(NumericType)
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/nontagged/numericData.json"),("format"="adm"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.2.update.aql
new file mode 100644
index 0000000..1ecf3aa
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.2.update.aql
@@ -0,0 +1 @@
+// no inserts, deletes
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.3.query.aql
new file mode 100644
index 0000000..bc962c3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_int8_null/sum_int8_null.3.query.aql
@@ -0,0 +1,6 @@
+use dataverse test;
+
+sql-sum( 
+ for $x in dataset('Numeric') 
+ return $x.int8Field
+)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.1.ddl.aql
new file mode 100644
index 0000000..c2325f0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.1.ddl.aql
@@ -0,0 +1,5 @@
+/*
+* Description  : Run sql-sum over an ordered list with mixed types
+* Expected Res : Failure
+* Date         : Jun 2nd 2013
+*/
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.2.update.aql
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.2.update.aql
@@ -0,0 +1 @@
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.3.query.aql
new file mode 100644
index 0000000..73dd8f0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_mixed/sum_mixed.3.query.aql
@@ -0,0 +1,11 @@
+/*
+* Description  : Run sql-sum over an ordered list with mixed types
+* Expected Res : Failure
+* Date         : Jun 2nd 2013
+*/
+
+sql-sum(
+ for $x in [float("2.0"), "hello world", 93847382783847382, date("2013-01-01")]
+ return $x
+)
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.1.ddl.aql
new file mode 100644
index 0000000..02237c9
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.1.ddl.aql
@@ -0,0 +1,19 @@
+/*
+ * Description      :   sql-sum() aggregate function must return the numeric sql-sum, when non null values are given as input to sql-sum().
+ *                  :   Get the sql-sum for those tuples which are non null for salary fields.
+ * Expected result  :   Success
+ * Date             :   July 20th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type TestType as open {
+id:int32,
+sal:int32?
+}
+
+create dataset tdst(TestType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.2.update.aql
new file mode 100644
index 0000000..5fc1af1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.2.update.aql
@@ -0,0 +1,16 @@
+/*
+ * Description      :   sql-sum() aggregate function must return the numeric sql-sum, when non null values are given as input to sql-sum().
+ *                  :   Get the sql-sum for those tuples which are non null for salary fields.
+ * Expected result  :   Success
+ * Date             :   July 20th 2012
+ */
+
+use dataverse test;
+
+insert into dataset tdst({"id":123,"sal":1000});
+insert into dataset tdst({"id":113,"sal":2000});
+insert into dataset tdst({"id":163,"sal":3000});
+insert into dataset tdst({"id":161,"sal":4000});
+insert into dataset tdst({"id":173,"sal":5000});
+insert into dataset tdst({"id":183,"sal":null});
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.3.query.aql
new file mode 100644
index 0000000..8f15be1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_null-with-pred/sum_null-with-pred.3.query.aql
@@ -0,0 +1,13 @@
+/*
+ * Description      :   sql-sum() aggregate function must return the numeric sql-sum, when non null values are given as input to sql-sum().
+ *                  :   Get the sql-sum for those tuples which are non null for salary fields.
+ * Expected result  :   Success
+ * Date             :   July 20th 2012
+ */
+
+use dataverse test;
+set import-private-functions 'true';
+
+sql-sum(for $l in dataset('tdst')
+where not(is-null($l.sal))
+return $l.sal)
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.1.ddl.aql
new file mode 100644
index 0000000..b54f6ab
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.1.ddl.aql
@@ -0,0 +1,18 @@
+/*
+ * Description      :   Add numeric values with a null value, sql-sum() aggregate function must return null.
+ * Expected result  :   Success
+ * Date             :   July 20th 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type TestType as open {
+id:int32,
+sal:int32?
+}
+
+create dataset tdst(TestType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.2.update.aql
new file mode 100644
index 0000000..1d47c20
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.2.update.aql
@@ -0,0 +1,15 @@
+/*
+ * Description      :   Add numeric values with a null value, sql-sum() aggregate function must return null.
+ * Expected result  :   Success
+ * Date             :   July 20th 2012
+ */
+
+use dataverse test;
+
+insert into dataset tdst({"id":123,"sal":1000});
+insert into dataset tdst({"id":113,"sal":2000});
+insert into dataset tdst({"id":163,"sal":3000});
+insert into dataset tdst({"id":161,"sal":4000});
+insert into dataset tdst({"id":173,"sal":5000});
+insert into dataset tdst({"id":183,"sal":null});
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.3.query.aql
new file mode 100644
index 0000000..a632b16
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/aggregate-sql/sum_numeric_null/sum_numeric_null.3.query.aql
@@ -0,0 +1,13 @@
+/*
+ * Description      :   Add numeric values with a null value, sql-sum() aggregate function must return null.
+ * Expected result  :   Success
+ * Date             :   July 20th 2012
+ */
+
+use dataverse test;
+
+// In AQL
+// sql-sum(numeric + null) => null
+
+sql-sum(for $l in dataset('tdst')
+return $l.sal)
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null/agg_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null/agg_null.1.adm
new file mode 100644
index 0000000..3ca4bc7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null/agg_null.1.adm
@@ -0,0 +1 @@
+{ "sql-count1": 0i64, "average1": null, "sql-sum1": null, "sql-min1": null, "sql-max1": null, "sql-count2": 0i64, "average2": null, "sql-sum2": null, "sql-min2": null, "sql-max2": null }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null_rec/agg_null_rec.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null_rec/agg_null_rec.1.adm
new file mode 100644
index 0000000..0f82337
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null_rec/agg_null_rec.1.adm
@@ -0,0 +1 @@
+{ "sql-count": 2i64, "average": 26.0d, "sql-sum": 52, "sql-min": 21, "sql-max": 31 }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null_rec_1/agg_null_rec.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null_rec_1/agg_null_rec.1.adm
new file mode 100644
index 0000000..5897df3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_null_rec_1/agg_null_rec.1.adm
@@ -0,0 +1 @@
+{ "sql-count": 3i64, "average": 5.32d, "sql-sum": 15.96d, "sql-min": 473847i64, "sql-max": 38473827484738239i64 }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm
new file mode 100644
index 0000000..b4a93b6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm
@@ -0,0 +1 @@
+{ "sql-count1": 4i64, "sql-count2": 4i64, "average1": 2.3461845695961844E16d, "sql-sum1": 9.3847382783847376E16, "sql-min1": 1.0d, "sql-max1": 9.3847382783847376E16, "average2": 2.3461845695961844E16d, "sql-sum2": 9.3847382783847376E16, "sql-min2": 1.0d, "sql-max2": 9.3847382783847376E16 }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number_rec/agg_number_rec.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number_rec/agg_number_rec.1.adm
new file mode 100644
index 0000000..5953969
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number_rec/agg_number_rec.1.adm
@@ -0,0 +1 @@
+{ "sql-count": 3i64, "average": 1.2824609161579424E16d, "sql-sum": 3.8473827484738272E16d, "sql-min": 2.0d, "sql-max": 3.847382748473824E16d }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_double/avg_double.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_double/avg_double.1.adm
new file mode 100644
index 0000000..e64425e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_double/avg_double.1.adm
@@ -0,0 +1 @@
+2.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_double_null/avg_double_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_double_null/avg_double_null.1.adm
new file mode 100644
index 0000000..52032db
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_double_null/avg_double_null.1.adm
@@ -0,0 +1 @@
+{ "average": 64.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_empty_01/avg_empty_01.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_empty_01/avg_empty_01.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_empty_01/avg_empty_01.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_empty_02/avg_empty_02.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_empty_02/avg_empty_02.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_empty_02/avg_empty_02.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_float/avg_float.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_float/avg_float.1.adm
new file mode 100644
index 0000000..e64425e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_float/avg_float.1.adm
@@ -0,0 +1 @@
+2.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_float_null/avg_float_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_float_null/avg_float_null.1.adm
new file mode 100644
index 0000000..52032db
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_float_null/avg_float_null.1.adm
@@ -0,0 +1 @@
+{ "average": 64.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int16/avg_int16.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int16/avg_int16.1.adm
new file mode 100644
index 0000000..e64425e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int16/avg_int16.1.adm
@@ -0,0 +1 @@
+2.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int16_null/avg_int16_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int16_null/avg_int16_null.1.adm
new file mode 100644
index 0000000..6d462be
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int16_null/avg_int16_null.1.adm
@@ -0,0 +1 @@
+{ "average": -16.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int32/avg_int32.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int32/avg_int32.1.adm
new file mode 100644
index 0000000..e64425e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int32/avg_int32.1.adm
@@ -0,0 +1 @@
+2.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int32_null/avg_int32_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int32_null/avg_int32_null.1.adm
new file mode 100644
index 0000000..584fc0c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int32_null/avg_int32_null.1.adm
@@ -0,0 +1 @@
+{ "average": -32.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int64/avg_int64.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int64/avg_int64.1.adm
new file mode 100644
index 0000000..e64425e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int64/avg_int64.1.adm
@@ -0,0 +1 @@
+2.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int64_null/avg_int64_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int64_null/avg_int64_null.1.adm
new file mode 100644
index 0000000..3b54c9a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int64_null/avg_int64_null.1.adm
@@ -0,0 +1 @@
+{ "average": -64.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int8/avg_int8.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int8/avg_int8.1.adm
new file mode 100644
index 0000000..e64425e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int8/avg_int8.1.adm
@@ -0,0 +1 @@
+2.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int8_null/avg_int8_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int8_null/avg_int8_null.1.adm
new file mode 100644
index 0000000..7d08439
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_int8_null/avg_int8_null.1.adm
@@ -0,0 +1 @@
+{ "average": 48.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_mixed/avg_mixed.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_mixed/avg_mixed.1.adm
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/avg_mixed/avg_mixed.1.adm
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_01/count_01.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_01/count_01.1.adm
new file mode 100644
index 0000000..deb6a26
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_01/count_01.1.adm
@@ -0,0 +1 @@
+3i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_empty_01/count_empty_01.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_empty_01/count_empty_01.1.adm
new file mode 100644
index 0000000..2dd16db
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_empty_01/count_empty_01.1.adm
@@ -0,0 +1 @@
+0i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_empty_02/count_empty_02.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_empty_02/count_empty_02.1.adm
new file mode 100644
index 0000000..2dd16db
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_empty_02/count_empty_02.1.adm
@@ -0,0 +1 @@
+0i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_null/count_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_null/count_null.1.adm
new file mode 100644
index 0000000..5b8b1d0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/count_null/count_null.1.adm
@@ -0,0 +1 @@
+{ "sql-count": 1i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue395/issue395.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue395/issue395.1.adm
new file mode 100644
index 0000000..06e4a82
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue395/issue395.1.adm
@@ -0,0 +1 @@
+2i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue412_0/issue412_0.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue412_0/issue412_0.1.adm
new file mode 100644
index 0000000..06e4a82
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue412_0/issue412_0.1.adm
@@ -0,0 +1 @@
+2i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue412_1/issue412_1.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue412_1/issue412_1.1.adm
new file mode 100644
index 0000000..cd1dae2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue412_1/issue412_1.1.adm
@@ -0,0 +1 @@
+{ "sql-count": 2i64, "average": 30.5d, "sql-sum": 61, "sql-min": 1, "sql-max": 60 }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.1.adm
new file mode 100644
index 0000000..c874983
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_min_hetero_list/issue425_min_hetero_list.1.adm
@@ -0,0 +1 @@
+23i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.1.adm
new file mode 100644
index 0000000..697ccbb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_min_hetero_list_1/issue425_min_hetero_list_1.1.adm
@@ -0,0 +1 @@
+0.5d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.1.adm
new file mode 100644
index 0000000..9c65934
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_sum_hetero_list/issue425_sum_hetero_list.1.adm
@@ -0,0 +1 @@
+748374857506i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.1.adm
new file mode 100644
index 0000000..e26a893
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue425_sum_hetero_list_1/issue425_sum_hetero_list_1.1.adm
@@ -0,0 +1 @@
+748374857506.5d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue531_string_min_max/issue531_string_min_max.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue531_string_min_max/issue531_string_min_max.1.adm
new file mode 100644
index 0000000..a01d30e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/issue531_string_min_max/issue531_string_min_max.1.adm
@@ -0,0 +1 @@
+{ "sql-min": "Alex", "sql-max": "Susan" }
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/max_empty_01/max_empty_01.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/max_empty_01/max_empty_01.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/max_empty_01/max_empty_01.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/max_empty_02/max_empty_02.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/max_empty_02/max_empty_02.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/max_empty_02/max_empty_02.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_empty_01/min_empty_01.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_empty_01/min_empty_01.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_empty_01/min_empty_01.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_empty_02/min_empty_02.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_empty_02/min_empty_02.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_empty_02/min_empty_02.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_mixed/min_mixed.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_mixed/min_mixed.1.adm
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/min_mixed/min_mixed.1.adm
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/query-issue400/query-issue400.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/query-issue400/query-issue400.1.adm
new file mode 100644
index 0000000..06e4a82
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/query-issue400/query-issue400.1.adm
@@ -0,0 +1 @@
+2i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg/scalar_avg.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg/scalar_avg.1.adm
new file mode 100644
index 0000000..4d13c57
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg/scalar_avg.1.adm
@@ -0,0 +1,6 @@
+2.0
+2.0
+2.0
+2.0
+2.0
+2.0
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg_empty/scalar_avg_empty.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg_empty/scalar_avg_empty.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg_empty/scalar_avg_empty.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg_null/scalar_avg_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg_null/scalar_avg_null.1.adm
new file mode 100644
index 0000000..4d13c57
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_avg_null/scalar_avg_null.1.adm
@@ -0,0 +1,6 @@
+2.0
+2.0
+2.0
+2.0
+2.0
+2.0
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count/scalar_count.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count/scalar_count.1.adm
new file mode 100644
index 0000000..4378df9
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count/scalar_count.1.adm
@@ -0,0 +1,7 @@
+3i64
+3i64
+3i64
+3i64
+3i64
+3i64
+3i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count_empty/scalar_count_empty.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count_empty/scalar_count_empty.1.adm
new file mode 100644
index 0000000..2dd16db
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count_empty/scalar_count_empty.1.adm
@@ -0,0 +1 @@
+0i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count_null/scalar_count_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count_null/scalar_count_null.1.adm
new file mode 100644
index 0000000..4378df9
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_count_null/scalar_count_null.1.adm
@@ -0,0 +1,7 @@
+3i64
+3i64
+3i64
+3i64
+3i64
+3i64
+3i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max/scalar_max.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max/scalar_max.1.adm
new file mode 100644
index 0000000..3a0f763
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max/scalar_max.1.adm
@@ -0,0 +1,8 @@
+3i8
+3i16
+3
+3i64
+3.0f
+3.0d
+"world"
+datetime("2012-03-01T00:00:00.000Z")
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max_empty/scalar_max_empty.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max_empty/scalar_max_empty.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max_empty/scalar_max_empty.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max_null/scalar_max_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max_null/scalar_max_null.1.adm
new file mode 100644
index 0000000..3a0f763
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_max_null/scalar_max_null.1.adm
@@ -0,0 +1,8 @@
+3i8
+3i16
+3
+3i64
+3.0f
+3.0d
+"world"
+datetime("2012-03-01T00:00:00.000Z")
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min/scalar_min.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min/scalar_min.1.adm
new file mode 100644
index 0000000..e5749ff
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min/scalar_min.1.adm
@@ -0,0 +1,8 @@
+1i8
+1i16
+1
+1i64
+1.0f
+1.0d
+"bar"
+datetime("2012-01-01T00:00:00.000Z")
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min_empty/scalar_min_empty.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min_empty/scalar_min_empty.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min_empty/scalar_min_empty.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min_null/scalar_min_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min_null/scalar_min_null.1.adm
new file mode 100644
index 0000000..e5749ff
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_min_null/scalar_min_null.1.adm
@@ -0,0 +1,8 @@
+1i8
+1i16
+1
+1i64
+1.0f
+1.0d
+"bar"
+datetime("2012-01-01T00:00:00.000Z")
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum/scalar_sum.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum/scalar_sum.1.adm
new file mode 100644
index 0000000..819c752
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum/scalar_sum.1.adm
@@ -0,0 +1,6 @@
+6i8
+6i16
+6
+6i64
+6.0f
+6.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum_empty/scalar_sum_empty.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum_empty/scalar_sum_empty.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum_empty/scalar_sum_empty.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum_null/scalar_sum_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum_null/scalar_sum_null.1.adm
new file mode 100644
index 0000000..819c752
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/scalar_sum_null/scalar_sum_null.1.adm
@@ -0,0 +1,6 @@
+6i8
+6i16
+6
+6i64
+6.0f
+6.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_double/sum_double.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_double/sum_double.1.adm
new file mode 100644
index 0000000..617fd08
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_double/sum_double.1.adm
@@ -0,0 +1 @@
+6.0d
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_double_null/sum_double_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_double_null/sum_double_null.1.adm
new file mode 100644
index 0000000..35dcd47
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_double_null/sum_double_null.1.adm
@@ -0,0 +1 @@
+64.0d
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_empty_01/sum_empty_01.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_empty_01/sum_empty_01.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_empty_01/sum_empty_01.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_empty_02/sum_empty_02.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_empty_02/sum_empty_02.1.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_empty_02/sum_empty_02.1.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_float/sum_float.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_float/sum_float.1.adm
new file mode 100644
index 0000000..d840134
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_float/sum_float.1.adm
@@ -0,0 +1 @@
+6.0f
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_float_null/sum_float_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_float_null/sum_float_null.1.adm
new file mode 100644
index 0000000..29e6891
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_float_null/sum_float_null.1.adm
@@ -0,0 +1 @@
+64.0f
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int16/sum_int16.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int16/sum_int16.1.adm
new file mode 100644
index 0000000..fa2ec89
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int16/sum_int16.1.adm
@@ -0,0 +1 @@
+6i16
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int16_null/sum_int16_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int16_null/sum_int16_null.1.adm
new file mode 100644
index 0000000..1f13ece
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int16_null/sum_int16_null.1.adm
@@ -0,0 +1 @@
+-16i16
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int32/sum_int32.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int32/sum_int32.1.adm
new file mode 100644
index 0000000..1e8b314
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int32/sum_int32.1.adm
@@ -0,0 +1 @@
+6
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int32_null/sum_int32_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int32_null/sum_int32_null.1.adm
new file mode 100644
index 0000000..5ee602a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int32_null/sum_int32_null.1.adm
@@ -0,0 +1 @@
+-32
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int64/sum_int64.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int64/sum_int64.1.adm
new file mode 100644
index 0000000..1d21ae2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int64/sum_int64.1.adm
@@ -0,0 +1 @@
+6i64
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int64_null/sum_int64_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int64_null/sum_int64_null.1.adm
new file mode 100644
index 0000000..df81d5e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int64_null/sum_int64_null.1.adm
@@ -0,0 +1 @@
+-64i64
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int8/sum_int8.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int8/sum_int8.1.adm
new file mode 100644
index 0000000..7f3e31c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int8/sum_int8.1.adm
@@ -0,0 +1 @@
+6i8
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int8_null/sum_int8_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int8_null/sum_int8_null.1.adm
new file mode 100644
index 0000000..a0b5709
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_int8_null/sum_int8_null.1.adm
@@ -0,0 +1 @@
+48i8
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_mixed/sum_mixed.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_mixed/sum_mixed.1.adm
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_mixed/sum_mixed.1.adm
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_null-with-pred/sum_null-with-pred.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_null-with-pred/sum_null-with-pred.1.adm
new file mode 100644
index 0000000..9e70369
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_null-with-pred/sum_null-with-pred.1.adm
@@ -0,0 +1 @@
+15000
diff --git a/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_numeric_null/sum_numeric_null.1.adm b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_numeric_null/sum_numeric_null.1.adm
new file mode 100644
index 0000000..f0cc45c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/aggregate-sql/sum_numeric_null/sum_numeric_null.1.adm
@@ -0,0 +1 @@
+15000
\ 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 067fddb..9e17fed 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -491,6 +491,361 @@
       </compilation-unit>
     </test-case>
   </test-group>
+  <test-group name="aggregate-sql">
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue531_string_min_max">
+        <output-dir compare="Text">issue531_string_min_max</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="agg_null">
+        <output-dir compare="Text">agg_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="agg_null_rec">
+        <output-dir compare="Text">agg_null_rec</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="agg_null_rec_1">
+        <output-dir compare="Text">agg_null_rec_1</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="agg_number_rec">
+        <output-dir compare="Text">agg_number_rec</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_mixed">
+        <output-dir compare="Text">avg_mixed</output-dir>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_mixed">
+        <output-dir compare="Text">sum_mixed</output-dir>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="min_mixed">
+        <output-dir compare="Text">min_mixed</output-dir>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="agg_number">
+        <output-dir compare="Text">agg_number</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue425_min_hetero_list_1">
+        <output-dir compare="Text">issue425_min_hetero_list_1</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue425_min_hetero_list">
+        <output-dir compare="Text">issue425_min_hetero_list</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue425_sum_hetero_list_1">
+        <output-dir compare="Text">issue425_sum_hetero_list_1</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue425_sum_hetero_list">
+        <output-dir compare="Text">issue425_sum_hetero_list</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="query-issue400">
+        <output-dir compare="Text">query-issue400</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue395">
+        <output-dir compare="Text">issue395</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue412_0">
+        <output-dir compare="Text">issue412_0</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="issue412_1">
+        <output-dir compare="Text">issue412_1</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_double">
+        <output-dir compare="Text">avg_double</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_double_null">
+        <output-dir compare="Text">avg_double_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_empty_01">
+        <output-dir compare="Text">avg_empty_01</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_empty_02">
+        <output-dir compare="Text">avg_empty_02</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_float">
+        <output-dir compare="Text">avg_float</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_float_null">
+        <output-dir compare="Text">avg_float_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int16">
+        <output-dir compare="Text">avg_int16</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int16_null">
+        <output-dir compare="Text">avg_int16_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int32">
+        <output-dir compare="Text">avg_int32</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int32_null">
+        <output-dir compare="Text">avg_int32_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int64">
+        <output-dir compare="Text">avg_int64</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int64_null">
+        <output-dir compare="Text">avg_int64_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int8">
+        <output-dir compare="Text">avg_int8</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_int8_null">
+        <output-dir compare="Text">avg_int8_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="count_01">
+        <output-dir compare="Text">count_01</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="count_empty_01">
+        <output-dir compare="Text">count_empty_01</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="count_empty_02">
+        <output-dir compare="Text">count_empty_02</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="count_null">
+        <output-dir compare="Text">count_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="max_empty_01">
+        <output-dir compare="Text">max_empty_01</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="max_empty_02">
+        <output-dir compare="Text">max_empty_02</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="min_empty_01">
+        <output-dir compare="Text">min_empty_01</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="min_empty_02">
+        <output-dir compare="Text">min_empty_02</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_avg">
+        <output-dir compare="Text">scalar_avg</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_avg_empty">
+        <output-dir compare="Text">scalar_avg_empty</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_avg_null">
+        <output-dir compare="Text">scalar_avg_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_count">
+        <output-dir compare="Text">scalar_count</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_count_empty">
+        <output-dir compare="Text">scalar_count_empty</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_count_null">
+        <output-dir compare="Text">scalar_count_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_max">
+        <output-dir compare="Text">scalar_max</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_max_empty">
+        <output-dir compare="Text">scalar_max_empty</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_max_null">
+        <output-dir compare="Text">scalar_max_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_min">
+        <output-dir compare="Text">scalar_min</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_min_empty">
+        <output-dir compare="Text">scalar_min_empty</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_min_null">
+        <output-dir compare="Text">scalar_min_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_sum">
+        <output-dir compare="Text">scalar_sum</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_sum_empty">
+        <output-dir compare="Text">scalar_sum_empty</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="scalar_sum_null">
+        <output-dir compare="Text">scalar_sum_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_double">
+        <output-dir compare="Text">sum_double</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_double_null">
+        <output-dir compare="Text">sum_double_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_empty_01">
+        <output-dir compare="Text">sum_empty_01</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_empty_02">
+        <output-dir compare="Text">sum_empty_02</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_float">
+        <output-dir compare="Text">sum_float</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_float_null">
+        <output-dir compare="Text">sum_float_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int16">
+        <output-dir compare="Text">sum_int16</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int16_null">
+        <output-dir compare="Text">sum_int16_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int32">
+        <output-dir compare="Text">sum_int32</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int32_null">
+        <output-dir compare="Text">sum_int32_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int64">
+        <output-dir compare="Text">sum_int64</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int64_null">
+        <output-dir compare="Text">sum_int64_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int8">
+        <output-dir compare="Text">sum_int8</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_int8_null">
+        <output-dir compare="Text">sum_int8_null</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_null-with-pred">
+        <output-dir compare="Text">sum_null-with-pred</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_numeric_null">
+        <output-dir compare="Text">sum_numeric_null</output-dir>
+      </compilation-unit>
+    </test-case>
+  </test-group>
   <test-group name="boolean">
     <test-case FilePath="boolean">
       <compilation-unit name="and_01">