asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dl...@apache.org
Subject [2/7] asterixdb git commit: [ASTERIXDB-2078][SQL] DISTINCT modifier for aggregate functions
Date Tue, 19 Sep 2017 17:52:12 GMT
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
index 11cb25f..f05d5e3 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
@@ -10,7 +10,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_count]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       (
         SELECT ELEMENT [
         FunctionCall Metadata.resolve@-1[
@@ -31,7 +31,7 @@ RecordConstructor [
     OperatorExpr [
       LiteralExpr [DOUBLE] [0.2]
       *
-      FunctionCall tpch.avg@1[
+      FunctionCall asterix.avg@1[
         (
           SELECT ELEMENT [
           FieldAccessor [
@@ -60,7 +60,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_max_suppkey]
     :
-    FunctionCall tpch.max@1[
+    FunctionCall asterix.max@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -88,7 +88,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_max_linenumber]
     :
-    FunctionCall tpch.max@1[
+    FunctionCall asterix.max@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -116,7 +116,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_avg_extendedprice]
     :
-    FunctionCall tpch.avg@1[
+    FunctionCall asterix.avg@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -144,7 +144,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_avg_discount]
     :
-    FunctionCall tpch.avg@1[
+    FunctionCall asterix.avg@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -172,7 +172,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_avg_tax]
     :
-    FunctionCall tpch.avg@1[
+    FunctionCall asterix.avg@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -200,7 +200,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_max_shipdate]
     :
-    FunctionCall tpch.max@1[
+    FunctionCall asterix.max@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -228,7 +228,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_min_commitdate]
     :
-    FunctionCall tpch.min@1[
+    FunctionCall asterix.min@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -256,7 +256,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_min_receiptdate]
     :
-    FunctionCall tpch.min@1[
+    FunctionCall asterix.min@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -284,7 +284,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [t_max_comment]
     :
-    FunctionCall tpch.max@1[
+    FunctionCall asterix.max@1[
       (
         SELECT ELEMENT [
         FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
index 6bb9429..adb46b5 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
@@ -30,7 +30,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [sum_quantity]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -82,7 +82,7 @@ FROM [  FunctionCall Metadata.dataset@1[
       (
         LiteralExpr [STRING] [t_sum_quantity]
         :
-        FunctionCall tpch.sum@1[
+        FunctionCall asterix.sum@1[
           (
             SELECT ELEMENT [
             FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q19_discounted_revenue/q19_discounted_revenue.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q19_discounted_revenue/q19_discounted_revenue.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q19_discounted_revenue/q19_discounted_revenue.3.ast
index cc6a71b..8afd86a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q19_discounted_revenue/q19_discounted_revenue.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q19_discounted_revenue/q19_discounted_revenue.3.ast
@@ -2,7 +2,7 @@ DataverseUse tpch
 Set import-private-functions=true
 Query:
 SELECT ELEMENT [
-FunctionCall tpch.sum@1[
+FunctionCall asterix.sum@1[
   (
     SELECT ELEMENT [
     OperatorExpr [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q20_potential_part_promotion/q20_potential_part_promotion.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q20_potential_part_promotion/q20_potential_part_promotion.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q20_potential_part_promotion/q20_potential_part_promotion.3.ast
index 88f61d2..aa7187e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q20_potential_part_promotion/q20_potential_part_promotion.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q20_potential_part_promotion/q20_potential_part_promotion.3.ast
@@ -52,7 +52,7 @@ FROM [  (
             OperatorExpr [
               LiteralExpr [DOUBLE] [0.5]
               *
-              FunctionCall tpch.sum@1[
+              FunctionCall asterix.sum@1[
                 (
                   SELECT ELEMENT [
                   FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
index 51bdde2..01b9b14 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
@@ -11,7 +11,7 @@ FunctionDecl tmp1([]) {
       (
         LiteralExpr [STRING] [count_suppkey]
         :
-        FunctionCall tpch.count@1[
+        FunctionCall asterix.count@1[
           (
             SELECT ELEMENT [
             FieldAccessor [
@@ -38,7 +38,7 @@ FunctionDecl tmp1([]) {
       (
         LiteralExpr [STRING] [max_suppkey]
         :
-        FunctionCall tpch.max@1[
+        FunctionCall asterix.max@1[
           (
             SELECT ELEMENT [
             FieldAccessor [
@@ -123,7 +123,7 @@ FunctionDecl tmp2([]) {
       (
         LiteralExpr [STRING] [count_suppkey]
         :
-        FunctionCall tpch.count@1[
+        FunctionCall asterix.count@1[
           (
             SELECT ELEMENT [
             FieldAccessor [
@@ -150,7 +150,7 @@ FunctionDecl tmp2([]) {
       (
         LiteralExpr [STRING] [max_suppkey]
         :
-        FunctionCall tpch.max@1[
+        FunctionCall asterix.max@1[
           (
             SELECT ELEMENT [
             FieldAccessor [
@@ -481,7 +481,7 @@ Groupby
 
 Let Variable [ Name=$numwait ]
   :=
-  FunctionCall tpch.sql-count@1[
+  FunctionCall asterix.sql-count@1[
     (
       SELECT ELEMENT [
       (

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
index 1ca3eb5..45790cd 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
@@ -42,7 +42,7 @@ FunctionDecl q22_customer_tmp([]) {
 Query:
 Let Variable [ Name=$avg ]
   :=
-  FunctionCall tpch.avg@1[
+  FunctionCall asterix.avg@1[
     (
       SELECT ELEMENT [
       FieldAccessor [
@@ -76,7 +76,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [numcust]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       (
         SELECT ELEMENT [
         FunctionCall Metadata.resolve@-1[
@@ -94,7 +94,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [totacctbal]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
index a77edfe..45c344d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
@@ -89,7 +89,7 @@ FunctionDecl q22_customer_tmp([]) {
 Query:
 Let Variable [ Name=$avg ]
   :=
-  FunctionCall tpch.avg@1[
+  FunctionCall asterix.avg@1[
     (
       SELECT ELEMENT [
       FieldAccessor [
@@ -179,7 +179,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [numcust]
     :
-    FunctionCall tpch.sql-count@1[
+    FunctionCall asterix.sql-count@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -196,7 +196,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [totacctbal]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -229,7 +229,7 @@ FROM [  FunctionCall tpch.q22_customer_tmp@0[
 ]
 Where
   OperatorExpr [
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       (
         SELECT ELEMENT [
         Variable [ Name=$o ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue601/query-issue601.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue601/query-issue601.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue601/query-issue601.3.ast
index d12032a..3dde59d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue601/query-issue601.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue601/query-issue601.3.ast
@@ -17,7 +17,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [count_order]
     :
-    FunctionCall tpch.sql-count@1[
+    FunctionCall asterix.sql-count@1[
       (
         SELECT ELEMENT [
         (

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue638/query-issue638.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue638/query-issue638.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue638/query-issue638.3.ast
index 14ed390..177f281 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue638/query-issue638.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue638/query-issue638.3.ast
@@ -15,7 +15,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [sum_profit]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
index f4cb736..3681810 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
@@ -129,7 +129,7 @@ Let Variable [ Name=$X ]
 
     Let Variable [ Name=$sum ]
       :=
-      FunctionCall tpch.sum@1[
+      FunctionCall asterix.sum@1[
         (
           SELECT ELEMENT [
           FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
index a3643c5..9d44d8f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
@@ -45,7 +45,7 @@ RecordConstructor [
 
       Let Variable [ Name=$sum ]
         :=
-        FunctionCall tpch.sum@1[
+        FunctionCall asterix.sum@1[
           (
             SELECT ELEMENT [
             FieldAccessor [
@@ -90,7 +90,7 @@ FROM [  (
       (
         LiteralExpr [STRING] [sum_price]
         :
-        FunctionCall tpch.sum@1[
+        FunctionCall asterix.sum@1[
           (
             SELECT ELEMENT [
             FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
index 78d629d..9302eb3 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
@@ -87,7 +87,7 @@ RecordConstructor [
 
       Let Variable [ Name=$sum ]
         :=
-        FunctionCall tpch.sum@1[
+        FunctionCall asterix.sum@1[
           (
             SELECT ELEMENT [
             FieldAccessor [

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-2/query-issue810-2.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-2/query-issue810-2.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-2/query-issue810-2.3.ast
index ab45142..4f8a868 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-2/query-issue810-2.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-2/query-issue810-2.3.ast
@@ -15,14 +15,14 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [count_cheaps]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       Variable [ Name=$cheaps ]
     ]
   )
   (
     LiteralExpr [STRING] [total_charges]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       Variable [ Name=$charges ]
     ]
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-3/query-issue810-3.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-3/query-issue810-3.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-3/query-issue810-3.3.ast
index 0fe8f7e..bc03eae 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-3/query-issue810-3.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810-3/query-issue810-3.3.ast
@@ -15,28 +15,28 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [count_cheaps]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       Variable [ Name=$cheaps ]
     ]
   )
   (
     LiteralExpr [STRING] [avg_expensive_discounts]
     :
-    FunctionCall tpch.avg@1[
+    FunctionCall asterix.avg@1[
       Variable [ Name=$expensives ]
     ]
   )
   (
     LiteralExpr [STRING] [sum_disc_prices]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       Variable [ Name=$disc_prices ]
     ]
   )
   (
     LiteralExpr [STRING] [total_charges]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       Variable [ Name=$charges ]
     ]
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810/query-issue810.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810/query-issue810.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810/query-issue810.3.ast
index 6787c4f..6a25433 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810/query-issue810.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue810/query-issue810.3.ast
@@ -15,14 +15,14 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [count_cheaps]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       Variable [ Name=$cheap ]
     ]
   )
   (
     LiteralExpr [STRING] [count_expensives]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       Variable [ Name=$expensive ]
     ]
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827-2/query-issue827-2.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827-2/query-issue827-2.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827-2/query-issue827-2.3.ast
index a11b5e2..13647f7 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827-2/query-issue827-2.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827-2/query-issue827-2.3.ast
@@ -4,7 +4,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [sum_qty_partial]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -32,7 +32,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [sum_base_price]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -51,7 +51,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [sum_disc_price]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         OperatorExpr [
@@ -81,7 +81,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [sum_charge]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         OperatorExpr [
@@ -120,7 +120,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [ave_qty]
     :
-    FunctionCall tpch.avg@1[
+    FunctionCall asterix.avg@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -148,7 +148,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [ave_price]
     :
-    FunctionCall tpch.avg@1[
+    FunctionCall asterix.avg@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -167,7 +167,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [ave_disc]
     :
-    FunctionCall tpch.avg@1[
+    FunctionCall asterix.avg@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -186,7 +186,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [count_order]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       (
         SELECT ELEMENT [
         Variable [ Name=$l ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827/query-issue827.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827/query-issue827.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827/query-issue827.3.ast
index 7ebf5f7..c970c9f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827/query-issue827.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue827/query-issue827.3.ast
@@ -4,7 +4,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [count_cheaps]
     :
-    FunctionCall tpch.count@1[
+    FunctionCall asterix.count@1[
       (
         SELECT ELEMENT [
         FieldAccessor [
@@ -23,7 +23,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [count_expensives]
     :
-    FunctionCall tpch.sum@1[
+    FunctionCall asterix.sum@1[
       (
         SELECT ELEMENT [
         Variable [ Name=$e ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.2.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.2.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.2.ast
index 4826f57..d5b9c31 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.2.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.2.ast
@@ -1,6 +1,6 @@
 Query:
 SELECT ELEMENT [
-FunctionCall null.count@1[
+FunctionCall asterix.count@1[
   (
     SELECT ELEMENT [
     Variable [ Name=$x ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.4.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.4.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.4.ast
index 4826f57..d5b9c31 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.4.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/user-defined-functions/query-issue489/query-issue489.4.ast
@@ -1,6 +1,6 @@
 Query:
 SELECT ELEMENT [
-FunctionCall null.count@1[
+FunctionCall asterix.count@1[
   (
     SELECT ELEMENT [
     Variable [ Name=$x ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 16d4cb3..920f0f0 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -295,6 +295,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
+      <compilation-unit name="avg_distinct">
+        <output-dir compare="Text">avg_distinct</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate">
       <compilation-unit name="count_01">
         <output-dir compare="Text">count_01</output-dir>
       </compilation-unit>
@@ -314,6 +319,11 @@
         <output-dir compare="Text">count_null</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="aggregate">
+      <compilation-unit name="count_distinct">
+        <output-dir compare="Text">count_distinct</output-dir>
+      </compilation-unit>
+    </test-case>
     <!--
         <test-case FilePath="aggregate">
           <compilation-unit name="droptype">
@@ -406,6 +416,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
+      <compilation-unit name="max_distinct">
+        <output-dir compare="Text">max_distinct</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate">
       <compilation-unit name="min_empty_01">
         <output-dir compare="Text">min_empty_01</output-dir>
       </compilation-unit>
@@ -416,6 +431,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
+      <compilation-unit name="min_distinct">
+        <output-dir compare="Text">min_distinct</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="aggregate">
       <compilation-unit name="scalar_avg">
         <output-dir compare="Text">scalar_avg</output-dir>
       </compilation-unit>
@@ -570,6 +590,11 @@
         <output-dir compare="Text">sum_numeric_null</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="aggregate">
+      <compilation-unit name="sum_distinct">
+        <output-dir compare="Text">sum_distinct</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="aggregate-sql">
     <test-case FilePath="aggregate-sql">
@@ -731,6 +756,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
+      <compilation-unit name="avg_distinct">
+        <output-dir compare="Text">avg_distinct</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>
@@ -751,6 +781,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
+      <compilation-unit name="count_distinct">
+        <output-dir compare="Text">count_distinct</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>
@@ -761,6 +796,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
+      <compilation-unit name="max_distinct">
+        <output-dir compare="Text">max_distinct</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>
@@ -771,6 +811,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
+      <compilation-unit name="min_distinct">
+        <output-dir compare="Text">min_distinct</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>
@@ -925,6 +970,11 @@
         <output-dir compare="Text">sum_numeric_null</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="aggregate-sql">
+      <compilation-unit name="sum_distinct">
+        <output-dir compare="Text">sum_distinct</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="boolean">
     <test-case FilePath="boolean">
@@ -2832,6 +2882,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="group-by">
+      <compilation-unit name="sugar-06-distinct">
+        <output-dir compare="Text">sugar-06-distinct</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="group-by">
       <compilation-unit name="null">
         <output-dir compare="Text">null</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
index fb5a6fb..60ccea6 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
@@ -56,6 +56,7 @@ import org.apache.asterix.lang.sqlpp.rewrites.visitor.InlineWithExpressionVisito
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.OperatorExpressionVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SetOperationVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppBuiltinFunctionRewriteVisitor;
+import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppDistinctAggregationSugarVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppGlobalAggregationSugarVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppGroupByVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppInlineUdfsVisitor;
@@ -135,6 +136,9 @@ class SqlppQueryRewriter implements IQueryRewriter {
         // names could be case sensitive.
         rewriteFunctionNames();
 
+        // Rewrites distinct aggregates into regular aggregates
+        rewriteDistinctAggregations();
+
         // Resets the variable counter to the previous marked value.
         // Therefore, the variable ids in the final query plans will not be perturbed
         // by the additon or removal of intermediate AST rewrites.
@@ -152,6 +156,12 @@ class SqlppQueryRewriter implements IQueryRewriter {
         topExpr.accept(globalAggregationVisitor, null);
     }
 
+    protected void rewriteDistinctAggregations() throws CompilationException {
+        SqlppDistinctAggregationSugarVisitor distinctAggregationVisitor =
+                new SqlppDistinctAggregationSugarVisitor(context);
+        topExpr.accept(distinctAggregationVisitor, null);
+    }
+
     protected void rewriteListInputFunctions() throws CompilationException {
         SqlppListInputFunctionRewriteVisitor listInputFunctionVisitor = new SqlppListInputFunctionRewriteVisitor();
         topExpr.accept(listInputFunctionVisitor, null);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppDistinctAggregationSugarVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppDistinctAggregationSugarVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppDistinctAggregationSugarVisitor.java
new file mode 100644
index 0000000..e9b8334
--- /dev/null
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppDistinctAggregationSugarVisitor.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.lang.sqlpp.rewrites.visitor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.functions.FunctionSignature;
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.base.ILangExpression;
+import org.apache.asterix.lang.common.expression.CallExpr;
+import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
+import org.apache.asterix.lang.common.util.FunctionUtil;
+import org.apache.asterix.lang.sqlpp.clause.FromClause;
+import org.apache.asterix.lang.sqlpp.clause.FromTerm;
+import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
+import org.apache.asterix.lang.sqlpp.clause.SelectClause;
+import org.apache.asterix.lang.sqlpp.clause.SelectElement;
+import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
+import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
+import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppExpressionScopingVisitor;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
+
+/**
+ * An AST pre-processor to rewrite distinct aggregates into regular aggregates as follows: <br/>
+ * {@code agg-distinct(expr) -> agg((FROM expr AS i SELECT DISTINCT VALUE i))} <br/>
+ * where {@code agg-distinct} is a distinct aggregate function, {@code agg} - a regular aggregate function
+ */
+public class SqlppDistinctAggregationSugarVisitor extends AbstractSqlppExpressionScopingVisitor {
+    public SqlppDistinctAggregationSugarVisitor(LangRewritingContext context) {
+        super(context);
+    }
+
+    @Override
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
+        FunctionSignature signature = callExpr.getFunctionSignature();
+        IFunctionInfo finfo = FunctionUtil.getFunctionInfo(signature);
+        FunctionIdentifier aggFn =
+                finfo != null ? BuiltinFunctions.getAggregateFunction(finfo.getFunctionIdentifier()) : null;
+        FunctionIdentifier newAggFn = aggFn != null ? BuiltinFunctions.getAggregateFunctionForDistinct(aggFn) : null;
+        if (newAggFn == null) {
+            return super.visit(callExpr, arg);
+        }
+        List<Expression> exprList = callExpr.getExprList();
+        List<Expression> newExprList = new ArrayList<>(exprList.size());
+        for (Expression expr : exprList) {
+            Expression newExpr = rewriteArgument(expr);
+            newExprList.add(newExpr.accept(this, arg));
+        }
+        callExpr.setFunctionSignature(
+                new FunctionSignature(newAggFn.getNamespace(), newAggFn.getName(), newAggFn.getArity()));
+        callExpr.setExprList(newExprList);
+        return callExpr;
+    }
+
+    /**
+     * rewrites {@code expr -> FROM expr AS i SELECT DISTINCT VALUE i}
+     */
+    private Expression rewriteArgument(Expression argExpr) throws CompilationException {
+        // From clause
+        VariableExpr fromBindingVar = new VariableExpr(context.newVariable());
+        FromTerm fromTerm = new FromTerm(argExpr, fromBindingVar, null, null);
+        FromClause fromClause = new FromClause(Collections.singletonList(fromTerm));
+
+        // Select clause.
+        SelectClause selectClause = new SelectClause(new SelectElement(fromBindingVar), null, true);
+
+        // Construct the select expression.
+        SelectBlock selectBlock = new SelectBlock(selectClause, fromClause, null, null, null, null, null);
+        SelectSetOperation selectSetOperation = new SelectSetOperation(new SetOperationInput(selectBlock, null), null);
+        return new SelectExpression(null, selectSetOperation, null, null, true);
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
index 6346994..b7604ab 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
@@ -72,10 +72,10 @@ import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppExpressionScoping
 // GROUP AS eis(e AS e, i AS i, s AS s)
 // SELECT ELEMENT {
 //          'deptId': deptId,
-//          'star_cost': coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) )
+//          'star_cost': array_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) )
 // };
 //
-// where SUM(e.salary + i.bonus) is turned into coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) ).
+// where SUM(e.salary + i.bonus) is turned into array_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) ).
 
 public class SqlppGroupBySugarVisitor extends AbstractSqlppExpressionScopingVisitor {
 
@@ -102,7 +102,7 @@ public class SqlppGroupBySugarVisitor extends AbstractSqlppExpressionScopingVisi
         }
         if (rewritten) {
             // Rewrites the SQL-92 function name to core functions,
-            // e.g., SUM --> coll_sum
+            // e.g., SUM --> array_sum
             callExpr.setFunctionSignature(FunctionMapUtil.sql92ToCoreAggregateFunction(signature));
         }
         callExpr.setExprList(newExprList);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
index 7f2e6c9..dfe371e 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
@@ -72,7 +72,7 @@ import org.apache.hyracks.algebricks.common.utils.Pair;
 // GROUP AS eis(e AS e, i AS i, s AS s)
 // SELECT ELEMENT {
 //  'deptId': deptId,
-//  'star_cost': coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) )
+//  'star_cost': array_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) )
 // };
 /**
  * The transformation include three things:
@@ -81,7 +81,7 @@ import org.apache.hyracks.algebricks.common.utils.Pair;
  * expression is not a subquery;
  * 3. Turn a SQL-92 aggregate function into a SQL++ core aggregate function when performing 2, e.g.,
  * SUM(e.salary + i.bonus) becomes
- * coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) ).
+ * array_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) ).
  */
 
 public class SqlppGroupByVisitor extends AbstractSqlppExpressionScopingVisitor {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
index 8f04980..8a8465d 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
@@ -104,7 +104,7 @@ public class FunctionMapUtil {
         if (!isSql92AggregateFunction(fs)) {
             return fs;
         }
-        return new FunctionSignature(fs.getNamespace(), CORE_SQL_AGGREGATE_PREFIX + fs.getName(),
+        return new FunctionSignature(FunctionConstants.ASTERIX_NS, CORE_SQL_AGGREGATE_PREFIX + fs.getName(),
                 fs.getArity());
     }
 
@@ -161,7 +161,7 @@ public class FunctionMapUtil {
         boolean coreAgg = name.startsWith(CORE_AGGREGATE_PREFIX);
         String lowerCaseName = coreAgg ? name.substring(CORE_AGGREGATE_PREFIX.length())
                 : (INTERNAL_SQL_AGGREGATE_PREFIX + name.substring(CORE_SQL_AGGREGATE_PREFIX.length()));
-        return new FunctionSignature(fs.getNamespace(), lowerCaseName, fs.getArity());
+        return new FunctionSignature(FunctionConstants.ASTERIX_NS, lowerCaseName, fs.getArity());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index b76adb8..68c1cba 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -2484,13 +2484,16 @@ Expression FunctionCallExpr() throws ParseException:
   FunctionName funcName = null;
   String hint = null;
   boolean star = false;
+  boolean distinct = false;
 }
 {
   funcName = FunctionName()
     {
       hint = funcName.hint;
     }
-  <LEFTPAREN> ( ( tmp = Expression() | <MUL> { star = true; } )
+  <LEFTPAREN> (
+    ( <DISTINCT> { distinct = true; } )?
+    ( tmp = Expression() | <MUL> { star = true; } )
     {
       if(star){
         if(!funcName.function.toLowerCase().equals("count")){
@@ -2509,8 +2512,12 @@ Expression FunctionCallExpr() throws ParseException:
     }
   )*)? <RIGHTPAREN>
     {
+      String name = funcName.function;
+      if (distinct) {
+        name += "-distinct";
+      }
       // TODO use funcName.library
-      String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
+      String fqFunctionName = funcName.library == null ? name : funcName.library + "#" + name;
       FunctionSignature signature
         = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
       if (signature == null) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AbstractFunctionDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AbstractFunctionDescriptor.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AbstractFunctionDescriptor.java
index c070719..35440e4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AbstractFunctionDescriptor.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AbstractFunctionDescriptor.java
@@ -40,31 +40,31 @@ public abstract class AbstractFunctionDescriptor implements IFunctionDescriptor
 
     @Override
     public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) throws AlgebricksException {
-        throw new NotImplementedException("Not Implemented");
+        throw new NotImplementedException("Not Implemented: " + getIdentifier());
     }
 
     @Override
     public IRunningAggregateEvaluatorFactory createRunningAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args)
             throws AlgebricksException {
-        throw new NotImplementedException("Not Implemented");
+        throw new NotImplementedException("Not Implemented: " + getIdentifier());
     }
 
     @Override
     public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
             IScalarEvaluatorFactory[] args) throws AlgebricksException {
-        throw new NotImplementedException("Not Implemented");
+        throw new NotImplementedException("Not Implemented: " + getIdentifier());
     }
 
     @Override
     public IUnnestingEvaluatorFactory createUnnestingEvaluatorFactory(IScalarEvaluatorFactory[] args)
             throws AlgebricksException {
-        throw new NotImplementedException("Not Implemented");
+        throw new NotImplementedException("Not Implemented: " + getIdentifier());
     }
 
     @Override
     public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args)
             throws AlgebricksException {
-        throw new NotImplementedException("Not Implemented");
+        throw new NotImplementedException("Not Implemented: " + getIdentifier());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index 695483b..863847b 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -143,6 +143,9 @@ public class BuiltinFunctions {
     private static final Map<IFunctionInfo, IFunctionInfo> aggregateToSerializableAggregate = new HashMap<>();
     private static final Map<IFunctionInfo, Boolean> builtinUnnestingFunctions = new HashMap<>();
     private static final Map<IFunctionInfo, IFunctionInfo> scalarToAggregateFunctionMap = new HashMap<>();
+    private static final Map<IFunctionInfo, IFunctionInfo> distinctToRegularScalarAggregateFunctionMap =
+            new HashMap<>();
+
     private static final Map<IFunctionInfo, SpatialFilterKind> spatialFilterFunctions = new HashMap<>();
 
     public static final FunctionIdentifier TYPE_OF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "type-of", 1);
@@ -398,6 +401,29 @@ public class BuiltinFunctions {
     public static final FunctionIdentifier SERIAL_INTERMEDIATE_AVG = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "intermediate-avg-serial", 1);
 
+    // distinct aggregate functions
+
+    public static final FunctionIdentifier COUNT_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-count-distinct", 1);
+    public static final FunctionIdentifier SCALAR_COUNT_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "count-distinct", 1);
+    public static final FunctionIdentifier SUM_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-sum-distinct", 1);
+    public static final FunctionIdentifier SCALAR_SUM_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "sum-distinct", 1);
+    public static final FunctionIdentifier AVG_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-avg-distinct", 1);
+    public static final FunctionIdentifier SCALAR_AVG_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "avg-distinct", 1);
+    public static final FunctionIdentifier MAX_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-max-distinct", 1);
+    public static final FunctionIdentifier SCALAR_MAX_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "max-distinct", 1);
+    public static final FunctionIdentifier MIN_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-min-distinct", 1);
+    public static final FunctionIdentifier SCALAR_MIN_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "min-distinct", 1);
+
     // sql aggregate functions
     public static final FunctionIdentifier SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-avg",
             1);
@@ -453,6 +479,28 @@ public class BuiltinFunctions {
     public static final FunctionIdentifier SERIAL_LOCAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "local-sql-avg-serial", 1);
 
+    // distinct sql aggregate functions
+    public static final FunctionIdentifier SQL_COUNT_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-sql-count-distinct", 1);
+    public static final FunctionIdentifier SCALAR_SQL_COUNT_DISTINCT = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "sql-count-distinct", 1);
+    public static final FunctionIdentifier SQL_SUM_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-sql-sum-distinct", 1);
+    public static final FunctionIdentifier SCALAR_SQL_SUM_DISTINCT = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "sql-sum-distinct", 1);
+    public static final FunctionIdentifier SQL_AVG_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-sql-avg-distinct", 1);
+    public static final FunctionIdentifier SCALAR_SQL_AVG_DISTINCT = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "sql-avg-distinct", 1);
+    public static final FunctionIdentifier SQL_MAX_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-sql-max-distinct", 1);
+    public static final FunctionIdentifier SCALAR_SQL_MAX_DISTINCT = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "sql-max-distinct", 1);
+    public static final FunctionIdentifier SQL_MIN_DISTINCT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "agg-sql-min-distinct", 1);
+    public static final FunctionIdentifier SCALAR_SQL_MIN_DISTINCT = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "sql-min-distinct", 1);
+
     public static final FunctionIdentifier SCAN_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "scan-collection", 1);
     public static final FunctionIdentifier SUBSET_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
@@ -899,9 +947,9 @@ public class BuiltinFunctions {
         addPrivateFunction(GRAM_TOKENS, OrderedListOfAStringTypeComputer.INSTANCE, true);
         addPrivateFunction(HASHED_GRAM_TOKENS, OrderedListOfAInt32TypeComputer.INSTANCE, true);
         addPrivateFunction(HASHED_WORD_TOKENS, OrderedListOfAInt32TypeComputer.INSTANCE, true);
-        addFunction(IF_MISSING_OR_NULL, IfMissingOrNullTypeComputer.INSTANCE,  true);
-        addFunction(IF_MISSING, IfMissingTypeComputer.INSTANCE,  true);
-        addFunction(IF_NULL, IfNullTypeComputer.INSTANCE,  true);
+        addFunction(IF_MISSING_OR_NULL, IfMissingOrNullTypeComputer.INSTANCE, true);
+        addFunction(IF_MISSING, IfMissingTypeComputer.INSTANCE, true);
+        addFunction(IF_NULL, IfNullTypeComputer.INSTANCE, true);
         addPrivateFunction(INDEX_SEARCH, AnyTypeComputer.INSTANCE, true);
         addFunction(INT8_CONSTRUCTOR, AInt8TypeComputer.INSTANCE, true);
         addFunction(INT16_CONSTRUCTOR, AInt16TypeComputer.INSTANCE, true);
@@ -1056,6 +1104,33 @@ public class BuiltinFunctions {
         addPrivateFunction(SERIAL_SUM, NumericAggTypeComputer.INSTANCE, true);
         addPrivateFunction(SERIAL_LOCAL_SUM, NumericAggTypeComputer.INSTANCE, true);
 
+        // Distinct aggregate functions
+
+        addFunction(COUNT_DISTINCT, AInt64TypeComputer.INSTANCE, true);
+        addFunction(SCALAR_COUNT_DISTINCT, AInt64TypeComputer.INSTANCE, true);
+        addFunction(SQL_COUNT_DISTINCT, AInt64TypeComputer.INSTANCE, true);
+        addFunction(SCALAR_SQL_COUNT_DISTINCT, AInt64TypeComputer.INSTANCE, true);
+
+        addFunction(SUM_DISTINCT, NumericAggTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_SUM_DISTINCT, ScalarVersionOfAggregateResultType.INSTANCE, true);
+        addFunction(SQL_SUM_DISTINCT, NumericAggTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_SQL_SUM_DISTINCT, ScalarVersionOfAggregateResultType.INSTANCE, true);
+
+        addFunction(AVG_DISTINCT, NullableDoubleTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_AVG_DISTINCT, NullableDoubleTypeComputer.INSTANCE, true);
+        addFunction(SQL_AVG_DISTINCT, NullableDoubleTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_SQL_AVG_DISTINCT, NullableDoubleTypeComputer.INSTANCE, true);
+
+        addFunction(MAX_DISTINCT, MinMaxAggTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_MAX_DISTINCT, ScalarVersionOfAggregateResultType.INSTANCE, true);
+        addFunction(SQL_MAX_DISTINCT, MinMaxAggTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_SQL_MAX_DISTINCT, ScalarVersionOfAggregateResultType.INSTANCE, true);
+
+        addFunction(MIN_DISTINCT, MinMaxAggTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_MIN_DISTINCT, ScalarVersionOfAggregateResultType.INSTANCE, true);
+        addFunction(SQL_MIN_DISTINCT, MinMaxAggTypeComputer.INSTANCE, true);
+        addFunction(SCALAR_SQL_MIN_DISTINCT, ScalarVersionOfAggregateResultType.INSTANCE, true);
+
         // Similarity functions
         addFunction(EDIT_DISTANCE_CONTAINS, OrderedListOfAnyTypeComputer.INSTANCE, true);
         addFunction(SIMILARITY_JACCARD, AFloatTypeComputer.INSTANCE, true);
@@ -1212,28 +1287,10 @@ public class BuiltinFunctions {
     }
 
     static {
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_AVG), getAsterixFunctionInfo(AVG));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_COUNT), getAsterixFunctionInfo(COUNT));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_GLOBAL_AVG), getAsterixFunctionInfo(GLOBAL_AVG));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_LOCAL_AVG), getAsterixFunctionInfo(LOCAL_AVG));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_MAX), getAsterixFunctionInfo(MAX));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_MIN), getAsterixFunctionInfo(MIN));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_SUM), getAsterixFunctionInfo(SUM));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_FIRST_ELEMENT),
-                getAsterixFunctionInfo(FIRST_ELEMENT));
-        // SQL Aggregate Functions
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_SQL_AVG), getAsterixFunctionInfo(SQL_AVG));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_SQL_COUNT), getAsterixFunctionInfo(SQL_COUNT));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_GLOBAL_SQL_AVG),
-                getAsterixFunctionInfo(GLOBAL_SQL_AVG));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_LOCAL_SQL_AVG),
-                getAsterixFunctionInfo(LOCAL_SQL_AVG));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_SQL_MAX), getAsterixFunctionInfo(SQL_MAX));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_SQL_MIN), getAsterixFunctionInfo(SQL_MIN));
-        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(SCALAR_SQL_SUM), getAsterixFunctionInfo(SQL_SUM));
-    }
+        //  Aggregate functions
+
+        // AVG
 
-    static {
         addAgg(AVG);
         addAgg(LOCAL_AVG);
         addAgg(GLOBAL_AVG);
@@ -1243,11 +1300,49 @@ public class BuiltinFunctions {
         addIntermediateAgg(GLOBAL_AVG, INTERMEDIATE_AVG);
         addGlobalAgg(AVG, GLOBAL_AVG);
 
+        addScalarAgg(AVG, SCALAR_AVG);
+        addScalarAgg(GLOBAL_AVG, SCALAR_GLOBAL_AVG);
+        addScalarAgg(LOCAL_AVG, SCALAR_LOCAL_AVG);
+
+        addSerialAgg(AVG, SERIAL_AVG);
+        addSerialAgg(LOCAL_AVG, SERIAL_LOCAL_AVG);
+        addSerialAgg(GLOBAL_AVG, SERIAL_GLOBAL_AVG);
+        addAgg(SERIAL_AVG);
+        addAgg(SERIAL_LOCAL_AVG);
+        addAgg(SERIAL_GLOBAL_AVG);
+        addLocalAgg(SERIAL_AVG, SERIAL_LOCAL_AVG);
+        addIntermediateAgg(SERIAL_AVG, SERIAL_INTERMEDIATE_AVG);
+        addIntermediateAgg(SERIAL_LOCAL_AVG, SERIAL_INTERMEDIATE_AVG);
+        addIntermediateAgg(SERIAL_GLOBAL_AVG, SERIAL_INTERMEDIATE_AVG);
+        addGlobalAgg(SERIAL_AVG, SERIAL_GLOBAL_AVG);
+
+        // AVG DISTINCT
+
+        addDistinctAgg(AVG_DISTINCT, SCALAR_AVG);
+        addScalarAgg(AVG_DISTINCT, SCALAR_AVG_DISTINCT);
+
+        // COUNT
+
         addAgg(COUNT);
         addLocalAgg(COUNT, COUNT);
         addIntermediateAgg(COUNT, SUM);
         addGlobalAgg(COUNT, SUM);
 
+        addScalarAgg(COUNT, SCALAR_COUNT);
+
+        addSerialAgg(COUNT, SERIAL_COUNT);
+        addAgg(SERIAL_COUNT);
+        addLocalAgg(SERIAL_COUNT, SERIAL_COUNT);
+        addIntermediateAgg(SERIAL_COUNT, SERIAL_SUM);
+        addGlobalAgg(SERIAL_COUNT, SERIAL_SUM);
+
+        // COUNT DISTINCT
+
+        addDistinctAgg(COUNT_DISTINCT, SCALAR_COUNT);
+        addScalarAgg(COUNT_DISTINCT, SCALAR_COUNT_DISTINCT);
+
+        // MAX
+
         addAgg(MAX);
         addAgg(LOCAL_MAX);
         addLocalAgg(MAX, LOCAL_MAX);
@@ -1255,6 +1350,15 @@ public class BuiltinFunctions {
         addIntermediateAgg(MAX, MAX);
         addGlobalAgg(MAX, MAX);
 
+        addScalarAgg(MAX, SCALAR_MAX);
+
+        // MAX DISTINCT
+
+        addDistinctAgg(MAX_DISTINCT, SCALAR_MAX);
+        addScalarAgg(MAX_DISTINCT, SCALAR_MAX_DISTINCT);
+
+        // FIRST_ELEMENT
+
         addAgg(SCALAR_FIRST_ELEMENT);
         addAgg(LOCAL_FIRST_ELEMENT);
         addLocalAgg(FIRST_ELEMENT, LOCAL_FIRST_ELEMENT);
@@ -1262,12 +1366,25 @@ public class BuiltinFunctions {
         addIntermediateAgg(FIRST_ELEMENT, FIRST_ELEMENT);
         addGlobalAgg(FIRST_ELEMENT, FIRST_ELEMENT);
 
+        addScalarAgg(FIRST_ELEMENT, SCALAR_FIRST_ELEMENT);
+
+        // MIN
+
         addAgg(MIN);
         addLocalAgg(MIN, LOCAL_MIN);
         addIntermediateAgg(LOCAL_MIN, MIN);
         addIntermediateAgg(MIN, MIN);
         addGlobalAgg(MIN, MIN);
 
+        addScalarAgg(MIN, SCALAR_MIN);
+
+        // MIN DISTINCT
+
+        addDistinctAgg(MIN_DISTINCT, SCALAR_MIN);
+        addScalarAgg(MIN_DISTINCT, SCALAR_MIN_DISTINCT);
+
+        // SUM
+
         addAgg(SUM);
         addAgg(LOCAL_SUM);
         addLocalAgg(SUM, LOCAL_SUM);
@@ -1275,30 +1392,10 @@ public class BuiltinFunctions {
         addIntermediateAgg(SUM, SUM);
         addGlobalAgg(SUM, SUM);
 
-        addAgg(LISTIFY);
+        addScalarAgg(SUM, SCALAR_SUM);
 
-        // serializable aggregate functions
-        addSerialAgg(AVG, SERIAL_AVG);
-        addSerialAgg(COUNT, SERIAL_COUNT);
         addSerialAgg(SUM, SERIAL_SUM);
         addSerialAgg(LOCAL_SUM, SERIAL_LOCAL_SUM);
-        addSerialAgg(LOCAL_AVG, SERIAL_LOCAL_AVG);
-        addSerialAgg(GLOBAL_AVG, SERIAL_GLOBAL_AVG);
-
-        addAgg(SERIAL_COUNT);
-        addLocalAgg(SERIAL_COUNT, SERIAL_COUNT);
-        addIntermediateAgg(SERIAL_COUNT, SERIAL_SUM);
-        addGlobalAgg(SERIAL_COUNT, SERIAL_SUM);
-
-        addAgg(SERIAL_AVG);
-        addAgg(SERIAL_LOCAL_AVG);
-        addAgg(SERIAL_GLOBAL_AVG);
-        addLocalAgg(SERIAL_AVG, SERIAL_LOCAL_AVG);
-        addIntermediateAgg(SERIAL_AVG, SERIAL_INTERMEDIATE_AVG);
-        addIntermediateAgg(SERIAL_LOCAL_AVG, SERIAL_INTERMEDIATE_AVG);
-        addIntermediateAgg(SERIAL_GLOBAL_AVG, SERIAL_INTERMEDIATE_AVG);
-        addGlobalAgg(SERIAL_AVG, SERIAL_GLOBAL_AVG);
-
         addAgg(SERIAL_SUM);
         addAgg(SERIAL_LOCAL_SUM);
         addLocalAgg(SERIAL_SUM, SERIAL_LOCAL_SUM);
@@ -1306,7 +1403,19 @@ public class BuiltinFunctions {
         addIntermediateAgg(SERIAL_LOCAL_SUM, SERIAL_SUM);
         addGlobalAgg(SERIAL_SUM, SERIAL_SUM);
 
+        // SUM DISTINCT
+
+        addDistinctAgg(SUM_DISTINCT, SCALAR_SUM);
+        addScalarAgg(SUM_DISTINCT, SCALAR_SUM_DISTINCT);
+
+        // LISTIFY
+
+        addAgg(LISTIFY);
+
         // SQL Aggregate Functions
+
+        // SQL AVG
+
         addAgg(SQL_AVG);
         addAgg(LOCAL_SQL_AVG);
         addAgg(GLOBAL_SQL_AVG);
@@ -1316,11 +1425,49 @@ public class BuiltinFunctions {
         addIntermediateAgg(GLOBAL_SQL_AVG, INTERMEDIATE_SQL_AVG);
         addGlobalAgg(SQL_AVG, GLOBAL_SQL_AVG);
 
+        addScalarAgg(SQL_AVG, SCALAR_SQL_AVG);
+        addScalarAgg(GLOBAL_SQL_AVG, SCALAR_GLOBAL_SQL_AVG);
+        addScalarAgg(LOCAL_SQL_AVG, SCALAR_LOCAL_SQL_AVG);
+
+        addSerialAgg(SQL_AVG, SERIAL_SQL_AVG);
+        addSerialAgg(LOCAL_SQL_AVG, SERIAL_LOCAL_SQL_AVG);
+        addSerialAgg(GLOBAL_SQL_AVG, SERIAL_GLOBAL_SQL_AVG);
+        addAgg(SERIAL_SQL_AVG);
+        addAgg(SERIAL_LOCAL_SQL_AVG);
+        addAgg(SERIAL_GLOBAL_SQL_AVG);
+        addLocalAgg(SERIAL_SQL_AVG, SERIAL_LOCAL_SQL_AVG);
+        addIntermediateAgg(SERIAL_SQL_AVG, SERIAL_INTERMEDIATE_SQL_AVG);
+        addIntermediateAgg(SERIAL_LOCAL_SQL_AVG, SERIAL_INTERMEDIATE_SQL_AVG);
+        addIntermediateAgg(SERIAL_GLOBAL_SQL_AVG, SERIAL_INTERMEDIATE_SQL_AVG);
+        addGlobalAgg(SERIAL_SQL_AVG, SERIAL_GLOBAL_SQL_AVG);
+
+        // SQL AVG DISTINCT
+
+        addDistinctAgg(SQL_AVG_DISTINCT, SCALAR_SQL_AVG);
+        addScalarAgg(SQL_AVG_DISTINCT, SCALAR_SQL_AVG_DISTINCT);
+
+        // SQL COUNT
+
         addAgg(SQL_COUNT);
         addLocalAgg(SQL_COUNT, SQL_COUNT);
         addIntermediateAgg(SQL_COUNT, SQL_SUM);
         addGlobalAgg(SQL_COUNT, SQL_SUM);
 
+        addScalarAgg(SQL_COUNT, SCALAR_SQL_COUNT);
+
+        addSerialAgg(SQL_COUNT, SERIAL_SQL_COUNT);
+        addAgg(SERIAL_SQL_COUNT);
+        addLocalAgg(SERIAL_SQL_COUNT, SERIAL_SQL_COUNT);
+        addIntermediateAgg(SERIAL_SQL_COUNT, SERIAL_SQL_SUM);
+        addGlobalAgg(SERIAL_SQL_COUNT, SERIAL_SQL_SUM);
+
+        // SQL COUNT DISTINCT
+
+        addDistinctAgg(SQL_COUNT_DISTINCT, SCALAR_SQL_COUNT);
+        addScalarAgg(SQL_COUNT_DISTINCT, SCALAR_SQL_COUNT_DISTINCT);
+
+        // SQL MAX
+
         addAgg(SQL_MAX);
         addAgg(LOCAL_SQL_MAX);
         addLocalAgg(SQL_MAX, LOCAL_SQL_MAX);
@@ -1328,12 +1475,30 @@ public class BuiltinFunctions {
         addIntermediateAgg(SQL_MAX, SQL_MAX);
         addGlobalAgg(SQL_MAX, SQL_MAX);
 
+        addScalarAgg(SQL_MAX, SCALAR_SQL_MAX);
+
+        // SQL MAX DISTINCT
+
+        addDistinctAgg(SQL_MAX_DISTINCT, SCALAR_SQL_MAX);
+        addScalarAgg(SQL_MAX_DISTINCT, SCALAR_SQL_MAX_DISTINCT);
+
+        // SQL MIN
+
         addAgg(SQL_MIN);
         addLocalAgg(SQL_MIN, LOCAL_SQL_MIN);
         addIntermediateAgg(LOCAL_SQL_MIN, SQL_MIN);
         addIntermediateAgg(SQL_MIN, SQL_MIN);
         addGlobalAgg(SQL_MIN, SQL_MIN);
 
+        addScalarAgg(SQL_MIN, SCALAR_SQL_MIN);
+
+        // SQL MIN DISTINCT
+
+        addDistinctAgg(SQL_MIN_DISTINCT, SCALAR_SQL_MIN);
+        addScalarAgg(SQL_MIN_DISTINCT, SCALAR_SQL_MIN_DISTINCT);
+
+        // SQL SUM
+
         addAgg(SQL_SUM);
         addAgg(LOCAL_SQL_SUM);
         addLocalAgg(SQL_SUM, LOCAL_SQL_SUM);
@@ -1341,28 +1506,10 @@ public class BuiltinFunctions {
         addIntermediateAgg(SQL_SUM, SQL_SUM);
         addGlobalAgg(SQL_SUM, SQL_SUM);
 
-        // SQL serializable aggregate functions
-        addSerialAgg(SQL_AVG, SERIAL_SQL_AVG);
-        addSerialAgg(SQL_COUNT, SERIAL_SQL_COUNT);
+        addScalarAgg(SQL_SUM, SCALAR_SQL_SUM);
+
         addSerialAgg(SQL_SUM, SERIAL_SQL_SUM);
         addSerialAgg(LOCAL_SQL_SUM, SERIAL_LOCAL_SQL_SUM);
-        addSerialAgg(LOCAL_SQL_AVG, SERIAL_LOCAL_SQL_AVG);
-        addSerialAgg(GLOBAL_SQL_AVG, SERIAL_GLOBAL_SQL_AVG);
-
-        addAgg(SERIAL_SQL_COUNT);
-        addLocalAgg(SERIAL_SQL_COUNT, SERIAL_SQL_COUNT);
-        addIntermediateAgg(SERIAL_SQL_COUNT, SERIAL_SQL_SUM);
-        addGlobalAgg(SERIAL_SQL_COUNT, SERIAL_SQL_SUM);
-
-        addAgg(SERIAL_SQL_AVG);
-        addAgg(SERIAL_LOCAL_SQL_AVG);
-        addAgg(SERIAL_GLOBAL_SQL_AVG);
-        addLocalAgg(SERIAL_SQL_AVG, SERIAL_LOCAL_SQL_AVG);
-        addIntermediateAgg(SERIAL_SQL_AVG, SERIAL_INTERMEDIATE_SQL_AVG);
-        addIntermediateAgg(SERIAL_LOCAL_SQL_AVG, SERIAL_INTERMEDIATE_SQL_AVG);
-        addIntermediateAgg(SERIAL_GLOBAL_SQL_AVG, SERIAL_INTERMEDIATE_SQL_AVG);
-        addGlobalAgg(SERIAL_SQL_AVG, SERIAL_GLOBAL_SQL_AVG);
-
         addAgg(SERIAL_SQL_SUM);
         addAgg(SERIAL_LOCAL_SQL_SUM);
         addLocalAgg(SERIAL_SQL_SUM, SERIAL_LOCAL_SQL_SUM);
@@ -1370,6 +1517,10 @@ public class BuiltinFunctions {
         addIntermediateAgg(SERIAL_SQL_SUM, SERIAL_SQL_SUM);
         addGlobalAgg(SERIAL_SQL_SUM, SERIAL_SQL_SUM);
 
+        // SQL SUM DISTINCT
+
+        addDistinctAgg(SQL_SUM_DISTINCT, SCALAR_SQL_SUM);
+        addScalarAgg(SQL_SUM_DISTINCT, SCALAR_SQL_SUM_DISTINCT);
     }
 
     static {
@@ -1502,6 +1653,12 @@ public class BuiltinFunctions {
         return finfo == null ? null : finfo.getFunctionIdentifier();
     }
 
+    public static FunctionIdentifier getAggregateFunctionForDistinct(FunctionIdentifier distinctVersionOfAggregate) {
+        IFunctionInfo finfo =
+                distinctToRegularScalarAggregateFunctionMap.get(getAsterixFunctionInfo(distinctVersionOfAggregate));
+        return finfo == null ? null : finfo.getFunctionIdentifier();
+    }
+
     public static void addFunction(FunctionIdentifier fi, IResultTypeComputer typeComputer, boolean isFunctional) {
         addFunctionWithDomain(fi, ATypeHierarchy.Domain.ANY, typeComputer, isFunctional);
     }
@@ -1548,6 +1705,15 @@ public class BuiltinFunctions {
         aggregateToSerializableAggregate.put(getAsterixFunctionInfo(fi), getAsterixFunctionInfo(serialfi));
     }
 
+    private static void addScalarAgg(FunctionIdentifier fi, FunctionIdentifier scalarfi) {
+        scalarToAggregateFunctionMap.put(getAsterixFunctionInfo(scalarfi), getAsterixFunctionInfo(fi));
+    }
+
+    private static void addDistinctAgg(FunctionIdentifier distinctfi, FunctionIdentifier regularscalarfi) {
+        distinctToRegularScalarAggregateFunctionMap.put(getAsterixFunctionInfo(distinctfi),
+                getAsterixFunctionInfo(regularscalarfi));
+    }
+
     static {
         spatialFilterFunctions.put(getAsterixFunctionInfo(BuiltinFunctions.SPATIAL_INTERSECT),
                 SpatialFilterKind.SI);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java
index 4ceeb5c..75b63f1 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java
@@ -43,6 +43,7 @@ public enum PhysicalOperatorTag {
     LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH,
     MATERIALIZE,
     MICRO_PRE_CLUSTERED_GROUP_BY,
+    MICRO_PRE_SORTED_DISTINCT_BY,
     NESTED_LOOP,
     NESTED_TUPLE_SOURCE,
     ONE_TO_ONE_EXCHANGE,

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AbstractFunctionCallExpression.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AbstractFunctionCallExpression.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AbstractFunctionCallExpression.java
index 8bc39b8..80d6f95 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AbstractFunctionCallExpression.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AbstractFunctionCallExpression.java
@@ -193,9 +193,14 @@ public abstract class AbstractFunctionCallExpression extends AbstractLogicalExpr
             if (!equal) {
                 return false;
             }
-            for (int i = 0; i < arguments.size(); i++) {
+            int argumentCount = arguments.size();
+            List<Mutable<ILogicalExpression>> fceArguments = fce.getArguments();
+            if (argumentCount != fceArguments.size()) {
+                return false;
+            }
+            for (int i = 0; i < argumentCount; i++) {
                 ILogicalExpression argument = arguments.get(i).getValue();
-                ILogicalExpression fceArgument = fce.getArguments().get(i).getValue();
+                ILogicalExpression fceArgument = fceArguments.get(i).getValue();
                 if (!argument.equals(fceArgument)) {
                     return false;
                 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/AbstractPreSortedDistinctByPOperator.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/AbstractPreSortedDistinctByPOperator.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/AbstractPreSortedDistinctByPOperator.java
new file mode 100644
index 0000000..c604e5c
--- /dev/null
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/AbstractPreSortedDistinctByPOperator.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hyracks.algebricks.core.algebra.operators.physical;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hyracks.algebricks.common.utils.ListSet;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.IOperatorSchema;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator;
+import org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty;
+import org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty;
+import org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningRequirementsCoordinator;
+import org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector;
+import org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty;
+import org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn;
+import org.apache.hyracks.algebricks.core.algebra.properties.PhysicalRequirements;
+import org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector;
+import org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty;
+import org.apache.hyracks.algebricks.core.jobgen.impl.JobGenHelper;
+
+public abstract class AbstractPreSortedDistinctByPOperator extends AbstractPhysicalOperator {
+
+    protected List<LogicalVariable> columnList;
+
+    public AbstractPreSortedDistinctByPOperator(List<LogicalVariable> columnList) {
+        this.columnList = columnList;
+    }
+
+    public void setDistinctByColumns(List<LogicalVariable> distinctByColumns) {
+        this.columnList = distinctByColumns;
+    }
+
+    @Override
+    public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) {
+        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
+        IPartitioningProperty pp = op2.getDeliveredPhysicalProperties().getPartitioningProperty();
+        List<ILocalStructuralProperty> propsLocal = op2.getDeliveredPhysicalProperties().getLocalProperties();
+        deliveredProperties = new StructuralPropertiesVector(pp, propsLocal);
+    }
+
+    @Override
+    public PhysicalRequirements getRequiredPropertiesForChildren(ILogicalOperator op,
+            IPhysicalPropertiesVector reqdByParent, IOptimizationContext context) {
+        StructuralPropertiesVector[] pv = new StructuralPropertiesVector[1];
+        List<ILocalStructuralProperty> localProps = new ArrayList<>();
+        List<OrderColumn> orderColumns = new ArrayList<>();
+        for (LogicalVariable column : columnList) {
+            orderColumns.add(new OrderColumn(column, OrderOperator.IOrder.OrderKind.ASC));
+        }
+        localProps.add(new LocalOrderProperty(orderColumns));
+        IPartitioningProperty pp = null;
+        AbstractLogicalOperator aop = (AbstractLogicalOperator) op;
+        if (aop.getExecutionMode() == AbstractLogicalOperator.ExecutionMode.PARTITIONED) {
+            pp = new UnorderedPartitionedProperty(new ListSet<>(columnList), context.getComputationNodeDomain());
+        }
+        pv[0] = new StructuralPropertiesVector(pp, localProps);
+        return new PhysicalRequirements(pv, IPartitioningRequirementsCoordinator.NO_COORDINATION);
+    }
+
+    @Override
+    public boolean expensiveThanMaterialization() {
+        return true;
+    }
+
+    protected int[] getKeysAndDecs(IOperatorSchema inputSchema) {
+        int keys[] = JobGenHelper.variablesToFieldIndexes(columnList, inputSchema);
+        int sz = inputSchema.getSize();
+        int fdSz = sz - columnList.size();
+        int[] fdColumns = new int[fdSz];
+        int j = 0;
+        for (LogicalVariable v : inputSchema) {
+            if (!columnList.contains(v)) {
+                fdColumns[j++] = inputSchema.findVariable(v);
+            }
+        }
+        int[] keysAndDecs = new int[keys.length + fdColumns.length];
+        for (int i = 0; i < keys.length; i++) {
+            keysAndDecs[i] = keys[i];
+        }
+        for (int i = 0; i < fdColumns.length; i++) {
+            keysAndDecs[i + keys.length] = fdColumns[i];
+        }
+        return keysAndDecs;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7a4b5681/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/MicroPreSortedDistinctByPOperator.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/MicroPreSortedDistinctByPOperator.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/MicroPreSortedDistinctByPOperator.java
new file mode 100644
index 0000000..94d5fd4
--- /dev/null
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/physical/MicroPreSortedDistinctByPOperator.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hyracks.algebricks.core.algebra.operators.physical;
+
+import java.util.List;
+
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.IHyracksJobBuilder;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import org.apache.hyracks.algebricks.core.algebra.base.PhysicalOperatorTag;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.IOperatorSchema;
+import org.apache.hyracks.algebricks.core.jobgen.impl.JobGenContext;
+import org.apache.hyracks.algebricks.core.jobgen.impl.JobGenHelper;
+import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.operators.aggreg.SimpleAlgebricksAccumulatingAggregatorFactory;
+import org.apache.hyracks.algebricks.runtime.operators.group.MicroPreClusteredGroupRuntimeFactory;
+import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
+import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
+import org.apache.hyracks.dataflow.std.group.IAggregatorDescriptorFactory;
+
+public class MicroPreSortedDistinctByPOperator extends AbstractPreSortedDistinctByPOperator {
+
+    public MicroPreSortedDistinctByPOperator(List<LogicalVariable> columnList) {
+        super(columnList);
+    }
+
+    @Override
+    public PhysicalOperatorTag getOperatorTag() {
+        return PhysicalOperatorTag.MICRO_PRE_SORTED_DISTINCT_BY;
+    }
+
+    @Override
+    public boolean isMicroOperator() {
+        return true;
+    }
+
+    @Override
+    public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op,
+            IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema)
+            throws AlgebricksException {
+
+        int[] keysAndDecs = getKeysAndDecs(inputSchemas[0]);
+
+        IBinaryComparatorFactory[] comparatorFactories = JobGenHelper
+                .variablesToAscBinaryComparatorFactories(columnList, context.getTypeEnvironment(op), context);
+        IAggregateEvaluatorFactory[] aggFactories = new IAggregateEvaluatorFactory[] {};
+        IAggregatorDescriptorFactory aggregatorFactory =
+                new SimpleAlgebricksAccumulatingAggregatorFactory(aggFactories, keysAndDecs);
+
+        RecordDescriptor recordDescriptor =
+                JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
+        RecordDescriptor inputRecordDesc = JobGenHelper.mkRecordDescriptor(
+                context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas[0], context);
+
+        /* make fd columns part of the key but the comparator only compares the distinct key columns */
+        MicroPreClusteredGroupRuntimeFactory runtime = new MicroPreClusteredGroupRuntimeFactory(keysAndDecs,
+                comparatorFactories, aggregatorFactory, inputRecordDesc, recordDescriptor, null);
+        builder.contributeMicroOperator(op, runtime, recordDescriptor);
+        ILogicalOperator src = op.getInputs().get(0).getValue();
+        builder.contributeGraphEdge(src, 0, op, 0);
+    }
+}


Mime
View raw message