Yingyi Bu has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/763

Change subject: PLEASE EDIT to provide a meaningful commit message!
......................................................................

PLEASE EDIT to provide a meaningful commit message!

The following commits from your working branch will be included:

commit ba0b93491fa36deac64e34bc5a401ed014240e77
Merge: 0ec114f 54ba057
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 16:12:39 2016 -0700

    merge master

commit 0ec114fefec85267b571f19b97534b94ed0271f7
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 13:13:32 2016 -0700

    update

commit 4c15d9c90e0f626a8d7757a0f60c9884fec5415b
Merge: bf07099 d7df13c
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 12:39:53 2016 -0700

    update

commit d7df13c6fe2162e552b52ff701c4f7ffcbd22c8b
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 11:25:12 2016 -0700

    fix agg over empty datsaet

commit 89b885b5e3cb3526a3171eb75e0d9e6f6c5bca36
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 10:54:57 2016 -0700

    update

commit bf07099bc4fc29d59db52277f3d6b45656d15a75
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 09:28:13 2016 -0700

    update tests

commit 760d8e73e3cbc8c4af55d104e805a77be94bae79
Merge: 702004d 9d560c1
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 08:32:17 2016 -0700

    Merge branch 'yingyi/funcname' into yingyi/demo

commit 702004d4d4298cf0a5491d056f090f29462d0ade
Merge: e56da0c d5751b1
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 08:32:06 2016 -0700

    update

commit d5751b11f3eff5cb163b993e57733bcf454a135b
Author: Yingyi Bu <[email protected]>
Date:   Thu Mar 24 23:33:46 2016 -0700

    update

commit 9398e458a45e35ff8e73ff3ee01e0358cb89abe4
Author: Yingyi Bu <[email protected]>
Date:   Thu Mar 24 22:40:34 2016 -0700

    update

commit 9fc7ab4f0492ed19cff67ae76085cb117dcc28fe
Author: Yingyi Bu <[email protected]>
Date:   Thu Mar 24 22:10:25 2016 -0700

    update

commit af4cb0ce9cbabf118fa489507972776ef6a78bf4
Author: Yingyi Bu <[email protected]>
Date:   Thu Mar 24 22:05:34 2016 -0700

    update

commit 2ff1dbec110e64d66ab269a882abeaa1df6cd1e9
Author: Yingyi Bu <[email protected]>
Date:   Thu Mar 24 21:43:04 2016 -0700

    sql++ gby

commit 9d560c183f89df2aae47a3cc18959fc8bb2122a1
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 00:49:02 2016 -0700

    update

commit 0d7c2c0fdaf20c06b987a3298cda3b3aa9b69aa5
Author: Yingyi Bu <[email protected]>
Date:   Mon Mar 28 00:16:04 2016 -0700

    update

commit e56da0ce11402d8bd82268afd3f34d9d8a5bc32a
Merge: b71a9d0 213d848
Author: Yingyi Bu <[email protected]>
Date:   Sun Mar 27 23:42:15 2016 -0700

    Merge branch 'yingyi/funcname' into yingyi/demo

commit 213d8480e9938f78dc82e18864841900046133ef
Author: Yingyi Bu <[email protected]>
Date:   Sun Mar 27 23:39:52 2016 -0700

    update

commit 314fab5c244b5b5f2d7f9116d22b221fa4b817eb
Author: Yingyi Bu <[email protected]>
Date:   Sat Mar 26 23:01:53 2016 -0700

    update

Change-Id: I97ad557ac19da50effe45a243d97dd317540fb0d
---
M 
asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/list/listify_03/listify_03.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q15_top_supplier/q15_top_supplier.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue638/query-issue638.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.query.sqlpp
M 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
A 
asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.query.sqlpp
A 
asterix-app/src/test/resources/runtimets/results/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.2.adm
M 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
M 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
M 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.ast
M 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
M 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
M 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
M 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.ast
A 
asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.ast
M 
asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
M 
asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
M 
asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
M 
asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
A 
asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
A 
asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSqlAggregateVisitor.java
M 
asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
A 
asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppBuiltinFunctionRewriteVisitor.java
A 
asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
53 files changed, 1,148 insertions(+), 261 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/63/763/1

diff --git 
a/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
 
b/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index 49e9399..9cbc88a 100644
--- 
a/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ 
b/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -725,33 +725,7 @@
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(GroupbyClause gc, 
Mutable<ILogicalOperator> tupSource)
             throws AsterixException {
-        GroupByOperator gOp = new GroupByOperator();
         Mutable<ILogicalOperator> topOp = tupSource;
-        for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
-            LogicalVariable v;
-            VariableExpr vexpr = ve.getVar();
-            if (vexpr != null) {
-                v = context.newVar(vexpr);
-            } else {
-                v = context.newVar();
-            }
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = 
langExprToAlgExpression(ve.getExpr(), topOp);
-            gOp.addGbyExpression(v, eo.first);
-            topOp = eo.second;
-        }
-        for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
-            LogicalVariable v;
-            VariableExpr vexpr = ve.getVar();
-            if (vexpr != null) {
-                v = context.newVar(vexpr);
-            } else {
-                v = context.newVar();
-            }
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = 
langExprToAlgExpression(ve.getExpr(), topOp);
-            gOp.addDecorExpression(v, eo.first);
-            topOp = eo.second;
-        }
-
         if (gc.hasGroupVar()) {
             List<Pair<Expression, Identifier>> groupFieldList = 
gc.getGroupFieldList();
             List<Mutable<ILogicalExpression>> groupRecordConstructorArgList = 
new ArrayList<>();
@@ -770,29 +744,75 @@
             groupVarAssignOp.getInputs().add(topOp);
             topOp = new MutableObject<ILogicalOperator>(groupVarAssignOp);
         }
+        if (gc.isGroupAll()) {
+            List<LogicalVariable> aggVars = new ArrayList<>();
+            List<Mutable<ILogicalExpression>> aggFuncs = new ArrayList<>();
+            for (VariableExpr var : gc.getWithVarList()) {
+                LogicalVariable aggVar = context.newVar();
+                LogicalVariable oldVar = context.getVar(var);
+                List<Mutable<ILogicalExpression>> flArgs = new 
ArrayList<Mutable<ILogicalExpression>>();
+                flArgs.add(new MutableObject<ILogicalExpression>(new 
VariableReferenceExpression(oldVar)));
+                AggregateFunctionCallExpression fListify = 
AsterixBuiltinFunctions
+                        
.makeAggregateFunctionExpression(AsterixBuiltinFunctions.LISTIFY, flArgs);
+                aggVars.add(aggVar);
+                aggFuncs.add(new MutableObject<ILogicalExpression>(fListify));
+                // Hide the variable that was part of the "with", replacing it 
with
+                // the one bound by the aggregation op.
+                context.setVar(var, aggVar);
+            }
+            AggregateOperator aggOp = new AggregateOperator(aggVars, aggFuncs);
+            aggOp.getInputs().add(topOp);
+            return new Pair<ILogicalOperator, LogicalVariable>(aggOp, null);
+        } else {
+            GroupByOperator gOp = new GroupByOperator();
+            for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
+                LogicalVariable v;
+                VariableExpr vexpr = ve.getVar();
+                if (vexpr != null) {
+                    v = context.newVar(vexpr);
+                } else {
+                    v = context.newVar();
+                }
+                Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = 
langExprToAlgExpression(ve.getExpr(), topOp);
+                gOp.addGbyExpression(v, eo.first);
+                topOp = eo.second;
+            }
+            for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
+                LogicalVariable v;
+                VariableExpr vexpr = ve.getVar();
+                if (vexpr != null) {
+                    v = context.newVar(vexpr);
+                } else {
+                    v = context.newVar();
+                }
+                Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = 
langExprToAlgExpression(ve.getExpr(), topOp);
+                gOp.addDecorExpression(v, eo.first);
+                topOp = eo.second;
+            }
 
-        gOp.getInputs().add(topOp);
-        for (VariableExpr var : gc.getWithVarList()) {
-            LogicalVariable aggVar = context.newVar();
-            LogicalVariable oldVar = context.getVar(var);
-            List<Mutable<ILogicalExpression>> flArgs = new 
ArrayList<Mutable<ILogicalExpression>>(1);
-            flArgs.add(new MutableObject<ILogicalExpression>(new 
VariableReferenceExpression(oldVar)));
-            AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions
-                    
.makeAggregateFunctionExpression(AsterixBuiltinFunctions.LISTIFY, flArgs);
-            AggregateOperator agg = new 
AggregateOperator(mkSingletonArrayList(aggVar),
-                    (List) mkSingletonArrayList(new 
MutableObject<ILogicalExpression>(fListify)));
+            gOp.getInputs().add(topOp);
+            for (VariableExpr var : gc.getWithVarList()) {
+                LogicalVariable aggVar = context.newVar();
+                LogicalVariable oldVar = context.getVar(var);
+                List<Mutable<ILogicalExpression>> flArgs = new 
ArrayList<Mutable<ILogicalExpression>>(1);
+                flArgs.add(new MutableObject<ILogicalExpression>(new 
VariableReferenceExpression(oldVar)));
+                AggregateFunctionCallExpression fListify = 
AsterixBuiltinFunctions
+                        
.makeAggregateFunctionExpression(AsterixBuiltinFunctions.LISTIFY, flArgs);
+                AggregateOperator agg = new 
AggregateOperator(mkSingletonArrayList(aggVar),
+                        (List) mkSingletonArrayList(new 
MutableObject<ILogicalExpression>(fListify)));
 
-            agg.getInputs().add(new MutableObject<ILogicalOperator>(
-                    new NestedTupleSourceOperator(new 
MutableObject<ILogicalOperator>(gOp))));
-            ILogicalPlan plan = new ALogicalPlanImpl(new 
MutableObject<ILogicalOperator>(agg));
-            gOp.getNestedPlans().add(plan);
-            // Hide the variable that was part of the "with", replacing it with
-            // the one bound by the aggregation op.
-            context.setVar(var, aggVar);
+                agg.getInputs().add(new MutableObject<ILogicalOperator>(
+                        new NestedTupleSourceOperator(new 
MutableObject<ILogicalOperator>(gOp))));
+                ILogicalPlan plan = new ALogicalPlanImpl(new 
MutableObject<ILogicalOperator>(agg));
+                gOp.getNestedPlans().add(plan);
+                // Hide the variable that was part of the "with", replacing it 
with
+                // the one bound by the aggregation op.
+                context.setVar(var, aggVar);
+            }
+            gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, 
gc.hasHashGroupByHint());
+            return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
         }
 
-        gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, 
gc.hasHashGroupByHint());
-        return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
     }
 
     @Override
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/listify_03/listify_03.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/listify_03/listify_03.3.query.sqlpp
index 8f6444e..5e73b39 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/listify_03/listify_03.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/listify_03/listify_03.3.query.sqlpp
@@ -25,10 +25,10 @@
 use test;
 
 
-select element test.min(y)
+select element coll_min(y)
 from  [1,2] as x
 with  y as (
-      select element test.min(i)
+      select element coll_min(i)
       from  [[1,2,3],[10,20,30],[-2,-5,0]] as i
   )
 ;
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp
index 8ccf4ef..845a5e6 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp
@@ -22,7 +22,7 @@
 USE TinySocial;
 
 SELECT ELEMENT avg((
-select element "string-length"(message.message)
+select element LENGTH(message.message)
 FROM FacebookMessages AS message
 WHERE message."in-response-to" >= 1 and
       message."in-response-to" < 11
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp
index 7c22f59..63ebe19 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp
@@ -20,7 +20,7 @@
 USE TinySocial;
 
 SELECT ELEMENT avg((
-select element "string-length"(message.message)
+select element LENGTH(message.message)
 FROM FacebookMessages AS message
 WHERE message."in-response-to" >= 1 and
       message."in-response-to" < 11
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
index 94b313f..d2c1cb5 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
@@ -22,28 +22,28 @@
 
 set "import-private-functions" "true";
 
-select element 
{'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'sum_qty':tpch.sum((
+select element 
{'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'sum_qty':SUM((
         select element i.l_quantity
         from  l as i
-    )),'sum_base_price':tpch.sum((
+    )),'sum_base_price':SUM((
         select element i.l_extendedprice
         from  l as i
-    )),'sum_disc_price':tpch.sum((
+    )),'sum_disc_price':SUM((
         select element (i.l_extendedprice * (1 - i.l_discount))
         from  l as i
-    )),'sum_charge':tpch.sum((
+    )),'sum_charge':SUM((
         select element (i.l_extendedprice * (1 - i.l_discount) * (1 + i.l_tax))
         from  l as i
-    )),'ave_qty':tpch.avg((
+    )),'ave_qty':AVG((
         select element i.l_quantity
         from  l as i
-    )),'ave_price':tpch.avg((
+    )),'ave_price':AVG((
         select element i.l_extendedprice
         from  l as i
-    )),'ave_disc':tpch.avg((
+    )),'ave_disc':AVG((
         select element i.l_discount
         from  l as i
-    )),'count_order':tpch.count(l)}
+    )),'count_order':COUNT(l)}
 from  LineItem as l
 where (l.l_shipdate <= '1998-09-02')
 /* +hash */
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
index a55c74d..795bdc7 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
@@ -45,7 +45,7 @@
 };
 declare function tmp2() {
 (
-    select element {'p_partkey':p_partkey,'ps_min_supplycost':tpch.min((
+    select element {'p_partkey':p_partkey,'ps_min_supplycost':MIN((
             select element i.ps_supplycost
             from  pssrn as i
         ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
index d30c6d3..e46182e 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
@@ -27,7 +27,7 @@
 where (((c.c_mktsegment = 'BUILDING') and (c.c_custkey = o.o_custkey)) and 
((l.l_orderkey = o.o_orderkey) and (o.o_orderdate < '1995-03-15') and 
(l.l_shipdate > '1995-03-15')))
 /* +hash */
 group by l.l_orderkey as l_orderkey,o.o_orderdate as 
o_orderdate,o.o_shippriority as o_shippriority
-with  revenue as tpch.sum((
+with  revenue as SUM((
       select element (i.l_extendedprice * (1 - i.l_discount))
       from  l as i
   ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.sqlpp
index faca581..088e35b 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.sqlpp
@@ -27,7 +27,7 @@
     where (l.l_commitdate < l.l_receiptdate)
 )
 };
-select element {'order_priority':o_orderpriority,'count':tpch.count(o)}
+select element {'order_priority':o_orderpriority,'count':COUNT(o)}
 from  Orders as o,
       tpch.tmp() as t
 where ((o.o_orderkey = t.o_orderkey) and (o.o_orderdate >= '1993-07-01') and 
(o.o_orderdate < '1993-10-01'))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
index 150e4b1..e3ddd5b 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
@@ -46,7 +46,7 @@
 where ((c.c_nationkey = o1.s_nationkey) and (c.c_custkey = o1.o_custkey))
 /* +hash */
 group by o1.n_name as n_name
-with  revenue as tpch.sum((
+with  revenue as SUM((
       select element (i.l_extendedprice * (1 - i.l_discount))
       from  o1 as i
   ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
index 9dee61f..35fbfcf 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
@@ -20,7 +20,7 @@
 use tpch;
 
 
-{'revenue':tpch.sum((
+{'revenue':SUM((
     select element (l.l_extendedprice * l.l_discount)
     from  LineItem as l
     where ((l.l_shipdate >= '1994-01-01') and (l.l_shipdate < '1995-01-01') 
and (l.l_discount >= 0.05) and (l.l_discount <= 0.07) and (l.l_quantity < 24))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
index 74d3b5a..dc69063 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
@@ -49,7 +49,7 @@
 with  l_year0 as tpch."get-year"(locs.l_shipdate)
 where ((locs.c_nationkey = t.c_nationkey) and (locs.s_nationkey = 
t.s_nationkey))
 group by t.supp_nation as supp_nation,t.cust_nation as cust_nation,l_year0 as 
l_year
-with  revenue as tpch.sum((
+with  revenue as SUM((
       select element (i.l_extendedprice * (1 - i.l_discount))
       from  locs as i
   ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.sqlpp
index 77d3881..1824478 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.sqlpp
@@ -20,10 +20,10 @@
 use tpch;
 
 
-select element {'year':year,'mkt_share':(tpch.sum((
+select element {'year':year,'mkt_share':(SUM((
           select element tpch."switch-case"((i.s_name = 
'BRAZIL'),true,i.revenue,false,0.0)
           from  t as i
-      )) / tpch.sum((
+      )) / SUM((
           select element i.revenue
           from  t as i
       )))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
index f7e2e8f..c1a2bc5 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
@@ -20,7 +20,7 @@
 use tpch;
 
 
-select element {'nation':nation,'o_year':o_year,'sum_profit':tpch.sum((
+select element {'nation':nation,'o_year':o_year,'sum_profit':SUM((
         select element pr.amount
         from  profit as pr
     ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.sqlpp
index f75030c..65835b9 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.sqlpp
@@ -34,7 +34,7 @@
     where ((l.l_orderkey = ocn.o_orderkey) and (l.l_selectflag = 'R'))
 ) as locn
 group by locn.c_custkey as c_custkey,locn.c_name as c_name,locn.c_acctbal as 
c_acctbal,locn.c_phone as c_phone,locn.n_name as n_name,locn.c_address as 
c_address,locn.c_comment as c_comment
-with  revenue as tpch.sum((
+with  revenue as SUM((
       select element (i.l_extendedprice * (1 - i.l_discount))
       from  locn as i
   ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
index f75030c..65835b9 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
@@ -34,7 +34,7 @@
     where ((l.l_orderkey = ocn.o_orderkey) and (l.l_selectflag = 'R'))
 ) as locn
 group by locn.c_custkey as c_custkey,locn.c_name as c_name,locn.c_acctbal as 
c_acctbal,locn.c_phone as c_phone,locn.n_name as n_name,locn.c_address as 
c_address,locn.c_comment as c_comment
-with  revenue as tpch.sum((
+with  revenue as SUM((
       select element (i.l_extendedprice * (1 - i.l_discount))
       from  locn as i
   ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.query.sqlpp
index ea3bd5a..c76a6ea 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.query.sqlpp
@@ -20,7 +20,7 @@
 use tpch;
 
 
-with  sum as tpch.sum((
+with  sum as SUM((
       select element (ps.ps_supplycost * ps.ps_availqty)
       from  Partsupp as ps,
             (
@@ -33,7 +33,7 @@
   ))
 select element {'partkey':t1.ps_partkey,'part_value':t1.part_value}
 from  (
-    select element {'ps_partkey':ps_partkey,'part_value':tpch.sum((
+    select element {'ps_partkey':ps_partkey,'part_value':SUM((
             select element (i.ps_supplycost * i.ps_availqty)
             from  ps as i
         ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.query.sqlpp
index 61b685e..18d12b4 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.query.sqlpp
@@ -20,10 +20,10 @@
 use tpch;
 
 
-select element {'l_shipmode':l_shipmode,'high_line_count':tpch.sum((
+select element {'l_shipmode':l_shipmode,'high_line_count':SUM((
         select element tpch."switch-case"(((i.o_orderpriority = '1-URGENT') or 
(i.o_orderpriority = '2-HIGH')),true,1,false,0)
         from  o as i
-    )),'low_line_count':tpch.sum((
+    )),'low_line_count':SUM((
         select element tpch."switch-case"(((i.o_orderpriority = '1-URGENT') or 
(i.o_orderpriority = '2-HIGH')),true,0,false,1)
         from  o as i
     ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
index afa7c9b..83c8959 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
@@ -24,7 +24,7 @@
 
 select element {'c_count':c_count,'custdist':custdist}
 from  (
-    select element {'c_custkey':c_custkey,'c_count':tpch.sum((
+    select element {'c_custkey':c_custkey,'c_count':SUM((
             select element i.o_orderkey_count
             from  co as i
         ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
index a8f29d3..178c521 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
@@ -20,10 +20,10 @@
 use tpch;
 
 
-select element (100.0 * tpch.sum((
-      select element 
tpch."switch-case"(tpch.like(i.p_type,'PROMO%'),true,(i.l_extendedprice * (1 - 
i.l_discount)),false,0.0)
+select element (100.0 * SUM((
+      select element 
tpch."switch-case"(LIKE(i.p_type,'PROMO%'),true,(i.l_extendedprice * (1 - 
i.l_discount)),false,0.0)
       from  lp as i
-  )) / tpch.sum((
+  )) / SUM((
       select element (i.l_extendedprice * (1 - i.l_discount))
       from  lp as i
   )))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q15_top_supplier/q15_top_supplier.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q15_top_supplier/q15_top_supplier.3.query.sqlpp
index e21104b..daf74bf 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q15_top_supplier/q15_top_supplier.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q15_top_supplier/q15_top_supplier.3.query.sqlpp
@@ -22,7 +22,7 @@
 
 declare function revenue() {
 (
-    select element {'supplier_no':l_suppkey,'total_revenue':tpch.sum((
+    select element {'supplier_no':l_suppkey,'total_revenue':SUM((
             select element (i.l_extendedprice * (1 - i.l_discount))
             from  l as i
         ))}
@@ -31,7 +31,7 @@
     group by l.l_suppkey as l_suppkey
 )
 };
-with  m as tpch.max((
+with  m as MAX((
       select element r2.total_revenue
       from  tpch.revenue() as r2
   ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
index cc4d01a..b695120 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
@@ -27,10 +27,10 @@
         select element 
{'p_brand':p.p_brand,'p_type':p.p_type,'p_size':p.p_size,'ps_suppkey':ps.ps_suppkey}
         from  Partsupp as ps,
               Part as p
-        where ((p.p_partkey = ps.ps_partkey) and (p.p_brand != 'Brand#45') and 
tpch.not(tpch.like(p.p_type,'MEDIUM POLISHED%')))
+        where ((p.p_partkey = ps.ps_partkey) and (p.p_brand != 'Brand#45') and 
NOT(tpch.like(p.p_type,'MEDIUM POLISHED%')))
     ) as psp,
           Supplier as s
-    where ((psp.ps_suppkey = s.s_suppkey) and 
tpch.not(tpch.like(s.s_comment,'%Customer%Complaints%')))
+    where ((psp.ps_suppkey = s.s_suppkey) and 
tpch.not(LIKE(s.s_comment,'%Customer%Complaints%')))
 )
 };
 select element 
{'p_brand':p_brand,'p_type':p_type,'p_size':p_size,'supplier_cnt':supplier_cnt}
@@ -41,7 +41,7 @@
     group by t.p_brand as p_brand1,t.p_type as p_type1,t.p_size as 
p_size1,t.ps_suppkey as ps_suppkey1
 ) as t2
 group by t2.p_brand as p_brand,t2.p_type as p_type,t2.p_size as p_size
-with  supplier_cnt as tpch.count((
+with  supplier_cnt as COUNT((
       select element i.ps_suppkey
       from  t2 as i
   ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
index ada4f75..60c1cc4 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
@@ -20,34 +20,34 @@
 use tpch;
 
 
-select element 
{'t_partkey':l_partkey,'t_count':tpch.count(l),'t_avg_quantity':(0.2 * 
tpch.avg((
+select element {'t_partkey':l_partkey,'t_count':COUNT(l),'t_avg_quantity':(0.2 
* AVG((
           select element i.l_quantity
           from  l as i
-      ))),'t_max_suppkey':tpch.max((
+      ))),'t_max_suppkey':MAX((
         select element i.l_suppkey
         from  l as i
-    )),'t_max_linenumber':tpch.max((
+    )),'t_max_linenumber':MAX((
         select element i.l_linenumber
         from  l as i
-    )),'t_avg_extendedprice':tpch.avg((
+    )),'t_avg_extendedprice':AVG((
         select element i.l_extendedprice
         from  l as i
-    )),'t_avg_discount':tpch.avg((
+    )),'t_avg_discount':AVG((
         select element i.l_discount
         from  l as i
-    )),'t_avg_tax':tpch.avg((
+    )),'t_avg_tax':AVG((
         select element i.l_tax
         from  l as i
-    )),'t_max_shipdate':tpch.max((
+    )),'t_max_shipdate':MAX((
         select element i.l_shipdate
         from  l as i
-    )),'t_min_commitdate':tpch.min((
+    )),'t_min_commitdate':MIN((
         select element i.l_commitdate
         from  l as i
-    )),'t_min_receiptdate':tpch.min((
+    )),'t_min_receiptdate':MIN((
         select element i.l_receiptdate
         from  l as i
-    )),'t_max_comment':tpch.max((
+    )),'t_max_comment':MAX((
         select element i.l_comment
         from  l as i
     ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
index 5aa971e..9819965 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
@@ -22,7 +22,7 @@
 
 declare function tmp() {
 (
-    select element {'t_partkey':l_partkey,'t_avg_quantity':(0.2 * tpch.avg((
+    select element {'t_partkey':l_partkey,'t_avg_quantity':(0.2 * AVG((
               select element i.l_quantity
               from  l as i
           )))}
@@ -31,7 +31,7 @@
 )
 };
 
-select element (tpch.sum((
+select element (SUM((
       select element l.l_extendedprice
       from  LineItem as l,
             Part as p,
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
index 15081ff..6fa2a65 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
@@ -20,14 +20,14 @@
 use tpch;
 
 
-select element 
{'c_name':c_name,'c_custkey':c_custkey,'o_orderkey':o_orderkey,'o_orderdate':o_orderdate,'o_totalprice':o_totalprice,'sum_quantity':tpch.sum((
+select element 
{'c_name':c_name,'c_custkey':c_custkey,'o_orderkey':o_orderkey,'o_orderdate':o_orderdate,'o_totalprice':o_totalprice,'sum_quantity':SUM((
         select element j.l_quantity
         from  l as j
     ))}
 from  Customer as c,
       Orders as o,
       (
-    select element {'l_orderkey':l_orderkey,'t_sum_quantity':tpch.sum((
+    select element {'l_orderkey':l_orderkey,'t_sum_quantity':SUM((
             select element i.l_quantity
             from  l as i
         ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
index 7065f87..9c80a67 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
@@ -22,7 +22,7 @@
 
 set "import-private-functions" "true";
 
-select element tpch.sum((
+select element SUM((
     select element (l.l_extendedprice * (1 - l.l_discount))
     from  LineItem as l,
           Part as p
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
index 0657ad3..25ee43c 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
@@ -24,7 +24,7 @@
 from  (
     select distinct element {'ps_suppkey':pst1.ps_suppkey}
     from  (
-        select element 
{'l_partkey':l_partkey,'l_suppkey':l_suppkey,'sum_quantity':(0.5 * tpch.sum((
+        select element 
{'l_partkey':l_partkey,'l_suppkey':l_suppkey,'sum_quantity':(0.5 * SUM((
                   select element i.l_quantity
                   from  l as i
               )))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
index 5382019..b25d826 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
@@ -22,7 +22,7 @@
 
 declare function tmp1() {
 (
-    select element {'l_orderkey':l_orderkey,'count_suppkey':tpch.count((
+    select element {'l_orderkey':l_orderkey,'count_suppkey':COUNT((
             select element i.l_suppkey
             from  l2 as i
         )),'max_suppkey':tpch.max((
@@ -39,10 +39,10 @@
 };
 declare function tmp2() {
 (
-    select element {'l_orderkey':l_orderkey,'count_suppkey':tpch.count((
+    select element {'l_orderkey':l_orderkey,'count_suppkey':COUNT((
             select element i.l_suppkey
             from  l2 as i
-        )),'max_suppkey':tpch.max((
+        )),'max_suppkey':MAX((
             select element i.l_suppkey
             from  l2 as i
         ))}
@@ -75,6 +75,6 @@
     where ((t2.count_suppkey >= 0) and (t3.l_orderkey = t2.l_orderkey))
 ) as t4
 group by t4.s_name as s_name
-with  numwait as tpch.count(t4)
+with  numwait as COUNT(t4)
 order by numwait desc,s_name
 ;
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
index 6136008..8f8bd30 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
@@ -22,7 +22,7 @@
 
 declare function q22_customer_tmp() {
 (
-    select element 
{'c_acctbal':c.c_acctbal,'c_custkey':c.c_custkey,'cntrycode':tpch.substring(c.c_phone,1,2)}
+    select element 
{'c_acctbal':c.c_acctbal,'c_custkey':c.c_custkey,'cntrycode':SUBSTR(c.c_phone,1,2)}
     from  Customer as c
 )
 };
@@ -31,7 +31,7 @@
       from  Customer as c
       where (c.c_acctbal > 0.0)
   ))
-select element 
{'cntrycode':cntrycode,'numcust':tpch.count(ct),'totacctbal':tpch.sum((
+select element {'cntrycode':cntrycode,'numcust':COUNT(ct),'totacctbal':SUM((
         select element i.c_acctbal
         from  ct as i
     ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.query.sqlpp
index 44852ec..f49b744 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.query.sqlpp
@@ -26,7 +26,7 @@
 use tpch;
 
 
-select element {'l_linenumber':l_linenumber,'count_order':tpch.count(l)}
+select element {'l_linenumber':l_linenumber,'count_order':COUNT(l)}
 from  LineItem as l
 group by l.l_linenumber as l_linenumber
 ;
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue638/query-issue638.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue638/query-issue638.3.query.sqlpp
index d2e8a7e..9d1fd99 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue638/query-issue638.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue638/query-issue638.3.query.sqlpp
@@ -26,7 +26,7 @@
 use tpch;
 
 
-select element {'nation':nation,'o_year':o_year,'sum_profit':tpch.sum((
+select element {'nation':nation,'o_year':o_year,'sum_profit':SUM((
         select element pr.amount
         from  profit as pr
     ))}
@@ -52,7 +52,7 @@
             ) as l1
             where ((ps.ps_suppkey = l1.l_suppkey) and (ps.ps_partkey = 
l1.l_partkey))
         ) as l2
-        where (tpch.contains(p.p_name,'green') and (p.p_partkey = 
l2.l_partkey))
+        where (CONTAINS(p.p_name,'green') and (p.p_partkey = l2.l_partkey))
     ) as l3
     with  amount as ((l3.l_extendedprice * (1 - l3.l_discount)) - 
(l3.ps_supplycost * l3.l_quantity)),
           o_year as tpch."get-year"(o.o_orderdate)
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.sqlpp
index 341d824..be09a4d 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.sqlpp
@@ -39,7 +39,7 @@
             Orders as orders
       where ((orders.o_custkey = customer.c_custkey) and (customer.c_nationkey 
= n.n_nationkey))
       group by orders.o_orderdate as orderdate,n.n_nationkey as nation_key
-      with  sum as tpch.sum((
+      with  sum as SUM((
             select element o.o_totalprice
             from  orders as o
         ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.query.sqlpp
index 0f31629..50dae4d 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.query.sqlpp
@@ -30,7 +30,7 @@
         select element {'orderdate':od,'sum_price':sum}
         from  x as i
         group by i.order_date as od
-        with  sum as tpch.sum((
+        with  sum as SUM((
               select element s.sum_price
               from  i as s
           ))
@@ -38,7 +38,7 @@
         limit 3
     )}
 from  (
-    select element 
{'nation_key':nation_key,'order_date':orderdate,'sum_price':tpch.sum((
+    select element 
{'nation_key':nation_key,'order_date':orderdate,'sum_price':SUM((
             select element o.o_totalprice
             from  orders as o
         ))}
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.query.sqlpp
index c35853c..4e73306 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.query.sqlpp
@@ -32,7 +32,7 @@
               Customer as customer
         where ((orders.o_custkey = customer.c_custkey) and 
(customer.c_nationkey = nation.n_nationkey))
         group by orders.o_orderdate as orderdate
-        with  sum as tpch.sum((
+        with  sum as SUM((
               select element o.o_totalprice
               from  orders as o
           ))
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
index 9dee61f..17757b9 100644
--- 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
@@ -20,8 +20,8 @@
 use tpch;
 
 
-{'revenue':tpch.sum((
-    select element (l.l_extendedprice * l.l_discount)
-    from  LineItem as l
-    where ((l.l_shipdate >= '1994-01-01') and (l.l_shipdate < '1995-01-01') 
and (l.l_discount >= 0.05) and (l.l_discount <= 0.07) and (l.l_quantity < 24))
-))};
+select sum(( select element l.l_extendedprice * l.l_discount from l as l )) as 
revenue
+from  LineItem as l
+where l.l_shipdate >= '1994-01-01' and l.l_shipdate < '1995-01-01' and 
l.l_discount >= 0.05
+  and l.l_discount <= 0.07 and l.l_quantity < 24
+;
diff --git 
a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.query.sqlpp
 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.query.sqlpp
new file mode 100644
index 0000000..1da2a8a
--- /dev/null
+++ 
b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+use tpch;
+
+
+select count(l) as count
+from  LineItem as l
+where l.l_shipdate >= '1994-01-01' and l.l_shipdate < '1995-01-01' and 
l.l_discount >= 0.05
+  and l.l_discount <= 0.07 and l.l_quantity < 24
+;
diff --git 
a/asterix-app/src/test/resources/runtimets/results/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.2.adm
 
b/asterix-app/src/test/resources/runtimets/results/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.2.adm
new file mode 100644
index 0000000..cebc6b5
--- /dev/null
+++ 
b/asterix-app/src/test/resources/runtimets/results/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.2.adm
@@ -0,0 +1 @@
+{ "count": 116 }
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
index cafd221..65c709a 100644
--- 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
@@ -174,18 +174,7 @@
     LiteralExpr [STRING] [count_order]
     :
     FunctionCall tpch.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=l
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS
-          Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$l ]
     ]
   )
 ]
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
index bf4a408..94b1fb1 100644
--- 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
@@ -44,18 +44,7 @@
     LiteralExpr [STRING] [count]
     :
     FunctionCall tpch.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=o
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS
-          Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$o ]
     ]
   )
 ]
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.ast
index fb8f2cd..e449469 100644
--- 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.ast
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.ast
@@ -11,18 +11,7 @@
     LiteralExpr [STRING] [t_count]
     :
     FunctionCall tpch.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=l
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS
-          Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$l ]
     ]
   )
   (
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
index c756a58..26cecdb 100644
--- 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.ast
@@ -461,18 +461,7 @@
 Let Variable [ Name=$numwait ]
   :=
   FunctionCall tpch.count@1[
-    (
-      SELECT ELEMENT [
-      FieldAccessor [
-        Variable [ Name=#2 ]
-        Field=t4
-      ]
-      ]
-      FROM [        Variable [ Name=#1 ]
-        AS
-        Variable [ Name=#2 ]
-      ]
-    )
+    Variable [ Name=$t4 ]
   ]
 Orderby
   Variable [ Name=$numwait ]
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
index 063914d..c3c1c24 100644
--- 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
@@ -79,18 +79,7 @@
     LiteralExpr [STRING] [numcust]
     :
     FunctionCall tpch.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=ct
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS
-          Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$ct ]
     ]
   )
   (
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
index 85c3c0d..54d2ab4 100644
--- 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
@@ -11,18 +11,7 @@
     LiteralExpr [STRING] [count_order]
     :
     FunctionCall tpch.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=l
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS
-          Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$l ]
     ]
   )
 ]
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.ast
index 592238f..4b78e86 100644
--- 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.ast
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.3.ast
@@ -1,78 +1,79 @@
 DataverseUse tpch
 Query:
-RecordConstructor [
+SELECT [
+FunctionCall tpch.sum@1[
   (
-    LiteralExpr [STRING] [revenue]
-    :
-    FunctionCall tpch.sum@1[
-      (
-        SELECT ELEMENT [
-        OperatorExpr [
-          FieldAccessor [
-            Variable [ Name=$l ]
-            Field=l_extendedprice
-          ]
-          *
-          FieldAccessor [
-            Variable [ Name=$l ]
-            Field=l_discount
-          ]
-        ]
-        ]
-        FROM [          FunctionCall Metadata.dataset@1[
-            LiteralExpr [STRING] [LineItem]
-          ]
-          AS
-          Variable [ Name=$l ]
-        ]
-        Where
-          OperatorExpr [
-            OperatorExpr [
-              FieldAccessor [
-                Variable [ Name=$l ]
-                Field=l_shipdate
-              ]
-              >=
-              LiteralExpr [STRING] [1994-01-01]
-            ]
-            and
-            OperatorExpr [
-              FieldAccessor [
-                Variable [ Name=$l ]
-                Field=l_shipdate
-              ]
-              <
-              LiteralExpr [STRING] [1995-01-01]
-            ]
-            and
-            OperatorExpr [
-              FieldAccessor [
-                Variable [ Name=$l ]
-                Field=l_discount
-              ]
-              >=
-              LiteralExpr [DOUBLE] [0.05]
-            ]
-            and
-            OperatorExpr [
-              FieldAccessor [
-                Variable [ Name=$l ]
-                Field=l_discount
-              ]
-              <=
-              LiteralExpr [DOUBLE] [0.07]
-            ]
-            and
-            OperatorExpr [
-              FieldAccessor [
-                Variable [ Name=$l ]
-                Field=l_quantity
-              ]
-              <
-              LiteralExpr [LONG] [24]
-            ]
-          ]
-      )
+    SELECT ELEMENT [
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_extendedprice
+      ]
+      *
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_discount
+      ]
+    ]
+    ]
+    FROM [      Variable [ Name=$l ]
+      AS
+      Variable [ Name=$l ]
     ]
   )
 ]
+revenue
+]
+FROM [  FunctionCall Metadata.dataset@1[
+    LiteralExpr [STRING] [LineItem]
+  ]
+  AS
+  Variable [ Name=$l ]
+]
+Where
+  OperatorExpr [
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_shipdate
+      ]
+      >=
+      LiteralExpr [STRING] [1994-01-01]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_shipdate
+      ]
+      <
+      LiteralExpr [STRING] [1995-01-01]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_discount
+      ]
+      >=
+      LiteralExpr [DOUBLE] [0.05]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_discount
+      ]
+      <=
+      LiteralExpr [DOUBLE] [0.07]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_quantity
+      ]
+      <
+      LiteralExpr [LONG] [24]
+    ]
+  ]
diff --git 
a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.ast
 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.ast
new file mode 100644
index 0000000..346b01f
--- /dev/null
+++ 
b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q06_forecast_revenue_change/q06_forecast_revenue_change.4.ast
@@ -0,0 +1,61 @@
+DataverseUse tpch
+Query:
+SELECT [
+FunctionCall tpch.count@1[
+  Variable [ Name=$l ]
+]
+count
+]
+FROM [  FunctionCall Metadata.dataset@1[
+    LiteralExpr [STRING] [LineItem]
+  ]
+  AS
+  Variable [ Name=$l ]
+]
+Where
+  OperatorExpr [
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_shipdate
+      ]
+      >=
+      LiteralExpr [STRING] [1994-01-01]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_shipdate
+      ]
+      <
+      LiteralExpr [STRING] [1995-01-01]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_discount
+      ]
+      >=
+      LiteralExpr [DOUBLE] [0.05]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_discount
+      ]
+      <=
+      LiteralExpr [DOUBLE] [0.07]
+    ]
+    and
+    OperatorExpr [
+      FieldAccessor [
+        Variable [ Name=$l ]
+        Field=l_quantity
+      ]
+      <
+      LiteralExpr [LONG] [24]
+    ]
+  ]
diff --git 
a/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
 
b/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
index 50e0ae2..b5d78e2 100644
--- 
a/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
+++ 
b/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
@@ -38,6 +38,7 @@
     private VariableExpr groupVar;
     private List<Pair<Expression, Identifier>> groupFieldList = new 
ArrayList<Pair<Expression, Identifier>>();
     private boolean hashGroupByHint;
+    private boolean groupAll;
 
     public GroupbyClause() {
     }
@@ -45,6 +46,12 @@
     public GroupbyClause(List<GbyVariableExpressionPair> gbyPairList, 
List<GbyVariableExpressionPair> decorPairList,
             List<VariableExpr> withVarList, VariableExpr groupVarExpr,
             List<Pair<Expression, Identifier>> groupFieldList, boolean 
hashGroupByHint) {
+        this(gbyPairList, decorPairList, withVarList, groupVarExpr, 
groupFieldList, hashGroupByHint, false);
+    }
+
+    public GroupbyClause(List<GbyVariableExpressionPair> gbyPairList, 
List<GbyVariableExpressionPair> decorPairList,
+            List<VariableExpr> withVarList, VariableExpr groupVarExpr,
+            List<Pair<Expression, Identifier>> groupFieldList, boolean 
hashGroupByHint, boolean groupAll) {
         this.gbyPairList = gbyPairList;
         this.decorPairList = decorPairList;
         this.withVarList = withVarList;
@@ -53,6 +60,7 @@
             this.groupFieldList = groupFieldList;
         }
         this.hashGroupByHint = hashGroupByHint;
+        this.groupAll = groupAll;
     }
 
     public List<GbyVariableExpressionPair> getGbyPairList() {
@@ -128,4 +136,8 @@
     public boolean hasGroupFieldList() {
         return groupFieldList != null && groupFieldList.size() > 0;
     }
+
+    public boolean isGroupAll() {
+        return groupAll;
+    }
 }
diff --git 
a/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
 
b/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
index 8cff0e8..c7d48b6 100644
--- 
a/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
+++ 
b/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
@@ -27,7 +27,7 @@
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 
 public class CallExpr extends AbstractExpression {
-    private final FunctionSignature functionSignature;
+    private FunctionSignature functionSignature;
     private List<Expression> exprList;
     private boolean isBuiltin;
 
@@ -53,6 +53,10 @@
         return Kind.CALL_EXPRESSION;
     }
 
+    public void setFunctionSignature(FunctionSignature functionSignature) {
+        this.functionSignature = functionSignature;
+    }
+
     public void setExprList(List<Expression> exprList) {
         this.exprList = exprList;
     }
diff --git 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
index 646e150..f63eced 100644
--- 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
+++ 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
@@ -112,4 +112,8 @@
     public boolean hasHavingClause() {
         return havingClause != null;
     }
+
+    public void setGroupbyClause(GroupbyClause groupbyClause) {
+        this.groupbyClause = groupbyClause;
+    }
 }
diff --git 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
index a2c84ba..5329337 100644
--- 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
+++ 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
@@ -49,7 +49,9 @@
 import org.apache.asterix.lang.sqlpp.parser.FunctionParser;
 import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
+import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
 import org.apache.asterix.lang.sqlpp.visitor.InlineColumnAliasVisitor;
+import 
org.apache.asterix.lang.sqlpp.visitor.SqlppBuiltinFunctionRewriteVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.SqlppGroupByVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.SqlppInlineUdfsVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.VariableCheckAndRewriteVisitor;
@@ -95,11 +97,27 @@
         // Inlines functions.
         inlineDeclaredUdfs();
 
+        // Rewrites function names.
+        // This should be done after inlineDeclaredUdfs() because user-defined 
function
+        // names could be case sensitive.
+        rewriteFunctionNames();
+
+        // Group-by core/sugar rewrites after function name rewrite.
+        rewriteGroupBys();
+
         // Replace global variable access with the dataset function for 
inlined expressions.
         variableCheckAndRewrite(true);
 
         // Sets the var counter of the query.
         topExpr.setVarCounter(context.getVarCounter());
+    }
+
+    protected void rewriteFunctionNames() throws AsterixException {
+        if (topExpr == null) {
+            return;
+        }
+        SqlppBuiltinFunctionRewriteVisitor functionNameMapVisitor = new 
SqlppBuiltinFunctionRewriteVisitor();
+        functionNameMapVisitor.visit(topExpr, null);
     }
 
     protected void inlineColumnAlias() throws AsterixException {
@@ -167,7 +185,8 @@
 
             Function function = lookupUserDefinedFunctionDecl(signature);
             if (function == null) {
-                if 
(AsterixBuiltinFunctions.isBuiltinCompilerFunction(signature, 
includePrivateFunctions)) {
+                FunctionSignature normalizedSignature = 
FunctionMapUtil.normalizeBuiltinFunctionSignature(signature);
+                if 
(AsterixBuiltinFunctions.isBuiltinCompilerFunction(normalizedSignature, 
includePrivateFunctions)) {
                     continue;
                 }
                 StringBuilder messageBuilder = new StringBuilder();
diff --git 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
new file mode 100644
index 0000000..f126e09
--- /dev/null
+++ 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
@@ -0,0 +1,90 @@
+/*
+ * 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.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.asterix.common.functions.FunctionSignature;
+
+public class FunctionMapUtil {
+
+    private final static String CORE_AGGREGATE_PREFIX = "coll_";
+
+    // Maps from a SQL function name to an AQL function name (i.e., AsterixDB 
internal name).
+    private static final Map<String, String> FUNCTION_NAME_MAP = new 
HashMap<>();
+
+    static {
+        FUNCTION_NAME_MAP.put("ceil", "ceiling"); //SQL: ceil,  AQL: ceiling
+        FUNCTION_NAME_MAP.put("length", "string-length"); // SQL: length,  
AQL: string-length
+        FUNCTION_NAME_MAP.put("lower", "lowercase"); // SQL: lower, AQL: 
lowercase
+        FUNCTION_NAME_MAP.put("substr", "substring"); // SQL: substr,  AQL: 
substring
+        FUNCTION_NAME_MAP.put("upper", "uppercase"); //SQL: upper, AQL: 
uppercase
+    }
+
+    /**
+     * Note: function name normalization can ONLY be called
+     * after all user-defined functions (by either "DECLARE FUNCTION" or 
"CREATE FUNCTION")
+     * are inlined, because user-defined function names are case-sensitive.
+     *
+     * @param name
+     *            the user-input function name in the query.
+     * @return the mapped internal name.
+     */
+    private static String normalizeBuiltinFunctionName(String name) {
+        String lowerCaseName = name.toLowerCase();
+        String mappedName = FUNCTION_NAME_MAP.get(lowerCaseName);
+        if (mappedName != null) {
+            return mappedName;
+        }
+        return lowerCaseName;
+    }
+
+    private static String normalizeCoreAggregateFunctionName(String name) {
+        if (name.startsWith(CORE_AGGREGATE_PREFIX)) {
+            return name.substring(CORE_AGGREGATE_PREFIX.length());
+        }
+        return name;
+    }
+
+    /**
+     * Whether a function signature is a SQL++ core aggregate function.
+     *
+     * @param fs,
+     *            the function signature.
+     * @return true if the function signature is a SQL++ core aggregate,
+     *         false otherwise.
+     */
+    public static boolean isCoreAggregationFunction(FunctionSignature fs) {
+        return fs.getName().startsWith(CORE_AGGREGATE_PREFIX);
+    }
+
+    /**
+     * Maps a user invoked function signature to a system internal function 
signature
+     *
+     * @param fs,
+     *            the user typed function.
+     * @return the system internal function.
+     */
+    public static FunctionSignature 
normalizeBuiltinFunctionSignature(FunctionSignature fs) {
+        String mappedName = normalizeBuiltinFunctionName(fs.getName());
+        mappedName = normalizeCoreAggregateFunctionName(mappedName);
+        return new FunctionSignature(fs.getNamespace(), mappedName, 
fs.getArity());
+    }
+}
diff --git 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSqlAggregateVisitor.java
 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSqlAggregateVisitor.java
new file mode 100644
index 0000000..5ed0c3d
--- /dev/null
+++ 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSqlAggregateVisitor.java
@@ -0,0 +1,267 @@
+/*
+ * 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.visitor;
+
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.functions.FunctionConstants;
+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.clause.GroupbyClause;
+import org.apache.asterix.lang.common.clause.LetClause;
+import org.apache.asterix.lang.common.clause.LimitClause;
+import org.apache.asterix.lang.common.clause.OrderbyClause;
+import org.apache.asterix.lang.common.clause.WhereClause;
+import org.apache.asterix.lang.common.expression.CallExpr;
+import org.apache.asterix.lang.common.expression.FieldAccessor;
+import org.apache.asterix.lang.common.expression.FieldBinding;
+import org.apache.asterix.lang.common.expression.IfExpr;
+import org.apache.asterix.lang.common.expression.IndexAccessor;
+import org.apache.asterix.lang.common.expression.ListConstructor;
+import org.apache.asterix.lang.common.expression.LiteralExpr;
+import org.apache.asterix.lang.common.expression.OperatorExpr;
+import org.apache.asterix.lang.common.expression.QuantifiedExpression;
+import org.apache.asterix.lang.common.expression.RecordConstructor;
+import org.apache.asterix.lang.common.expression.UnaryExpr;
+import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.statement.FunctionDecl;
+import org.apache.asterix.lang.common.statement.Query;
+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.HavingClause;
+import org.apache.asterix.lang.sqlpp.clause.JoinClause;
+import org.apache.asterix.lang.sqlpp.clause.NestClause;
+import org.apache.asterix.lang.sqlpp.clause.Projection;
+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.SelectRegular;
+import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
+import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
+import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import 
org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppQueryExpressionVisitor;
+import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
+
+/**
+ * This visitor checks if a language construct contains SQL-92 aggregates.
+ */
+public class CheckSqlAggregateVisitor extends 
AbstractSqlppQueryExpressionVisitor<Boolean, ILangExpression> {
+
+    @Override
+    public Boolean visit(Query q, ILangExpression arg) throws AsterixException 
{
+        return false;
+    }
+
+    @Override
+    public Boolean visit(FunctionDecl fd, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(LiteralExpr l, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(VariableExpr v, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(ListConstructor lc, ILangExpression arg) throws 
AsterixException {
+        return visitExprList(lc.getExprList(), arg);
+    }
+
+    @Override
+    public Boolean visit(RecordConstructor rc, ILangExpression arg) throws 
AsterixException {
+        for (FieldBinding fieldBinding : rc.getFbList()) {
+            if (!fieldBinding.getRightExpr().accept(this, arg)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public Boolean visit(OperatorExpr ifbo, ILangExpression arg) throws 
AsterixException {
+        return visitExprList(ifbo.getExprList(), arg);
+    }
+
+    @Override
+    public Boolean visit(FieldAccessor fa, ILangExpression arg) throws 
AsterixException {
+        return fa.getExpr().accept(this, arg);
+    }
+
+    @Override
+    public Boolean visit(IndexAccessor ia, ILangExpression arg) throws 
AsterixException {
+        return ia.getExpr().accept(this, arg);
+    }
+
+    @Override
+    public Boolean visit(IfExpr ifexpr, ILangExpression arg) throws 
AsterixException {
+        if (ifexpr.getCondExpr().accept(this, arg)) {
+            return true;
+        } else {
+            return ifexpr.getThenExpr().accept(this, arg) || 
ifexpr.getElseExpr().accept(this, arg);
+        }
+    }
+
+    @Override
+    public Boolean visit(QuantifiedExpression qe, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(UnaryExpr u, ILangExpression arg) throws 
AsterixException {
+        return u.getExpr().accept(this, arg);
+    }
+
+    @Override
+    public Boolean visit(CallExpr pf, ILangExpression arg) throws 
AsterixException {
+        FunctionSignature fs = pf.getFunctionSignature();
+        if (isAggregateFunction(fs)) {
+            return true;
+        }
+        for (Expression parameter : pf.getExprList()) {
+            if (parameter.accept(this, arg)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Boolean visit(LetClause lc, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(WhereClause wc, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(OrderbyClause oc, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(GroupbyClause gc, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(LimitClause lc, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(FromClause fromClause, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(FromTerm fromTerm, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(JoinClause joinClause, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(NestClause nestClause, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(Projection projection, ILangExpression arg) throws 
AsterixException {
+        return projection.getExpression().accept(this, arg);
+    }
+
+    @Override
+    public Boolean visit(SelectBlock selectBlock, ILangExpression arg) throws 
AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(SelectClause selectClause, ILangExpression arg) 
throws AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(SelectElement selectElement, ILangExpression arg) 
throws AsterixException {
+        return selectElement.getExpression().accept(this, arg);
+    }
+
+    @Override
+    public Boolean visit(SelectRegular selectRegular, ILangExpression arg) 
throws AsterixException {
+        for (Projection projection : selectRegular.getProjections()) {
+            if (!projection.accept(this, arg)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public Boolean visit(SelectSetOperation selectSetOperation, 
ILangExpression arg) throws AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(SelectExpression selectStatement, ILangExpression 
arg) throws AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(UnnestClause unnestClause, ILangExpression arg) 
throws AsterixException {
+        return false;
+    }
+
+    @Override
+    public Boolean visit(HavingClause havingClause, ILangExpression arg) 
throws AsterixException {
+        return false;
+    }
+
+    private Boolean visitExprList(List<Expression> exprs, ILangExpression arg) 
throws AsterixException {
+        for (Expression element : exprs) {
+            if (element.accept(this, arg)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean isAggregateFunction(FunctionSignature signature) throws 
AsterixException {
+        IFunctionInfo finfo = FunctionUtil.getFunctionInfo(
+                new FunctionIdentifier(FunctionConstants.ASTERIX_NS, 
signature.getName(), signature.getArity()));
+        if (finfo == null) {
+            return false;
+        }
+        return 
AsterixBuiltinFunctions.getAggregateFunction(finfo.getFunctionIdentifier()) != 
null;
+    }
+
+}
diff --git 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
index df32b01..bd24d24 100644
--- 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
+++ 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
@@ -21,9 +21,11 @@
 import java.io.PrintWriter;
 
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
+import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.QueryPrintVisitor;
@@ -42,7 +44,9 @@
 import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
 import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
+import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
 import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
+import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 
 public class SqlppAstPrintVisitor extends QueryPrintVisitor implements 
ISqlppVisitor<Void, Integer> {
@@ -243,6 +247,22 @@
     }
 
     @Override
+    public Void visit(CallExpr pf, Integer step) throws AsterixException {
+        FunctionSignature functionSignature = pf.getFunctionSignature();
+        FunctionSignature normalizedFunctionSignature = FunctionMapUtil
+                .normalizeBuiltinFunctionSignature(functionSignature);
+        if 
(AsterixBuiltinFunctions.isBuiltinCompilerFunction(normalizedFunctionSignature, 
true)) {
+            functionSignature = normalizedFunctionSignature;
+        }
+        out.println(skip(step) + "FunctionCall " + 
functionSignature.toString() + "[");
+        for (Expression expr : pf.getExprList()) {
+            expr.accept(this, step + 1);
+        }
+        out.println(skip(step) + "]");
+        return null;
+    }
+
+    @Override
     public Void visit(GroupbyClause gc, Integer step) throws AsterixException {
         out.println(skip(step) + "Groupby");
         for (GbyVariableExpressionPair pair : gc.getGbyPairList()) {
diff --git 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppBuiltinFunctionRewriteVisitor.java
 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppBuiltinFunctionRewriteVisitor.java
new file mode 100644
index 0000000..3dfb5be
--- /dev/null
+++ 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppBuiltinFunctionRewriteVisitor.java
@@ -0,0 +1,83 @@
+/*
+ * 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.visitor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+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.clause.GroupbyClause;
+import org.apache.asterix.lang.common.expression.CallExpr;
+import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
+import org.apache.asterix.lang.common.expression.LiteralExpr;
+import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.literal.IntegerLiteral;
+import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
+import org.apache.asterix.lang.sqlpp.clause.SelectClause;
+import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
+import 
org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppSimpleExpressionVisitor;
+
+public class SqlppBuiltinFunctionRewriteVisitor extends 
AbstractSqlppSimpleExpressionVisitor {
+
+    @Override
+    public Expression visit(SelectBlock selectBlock, Void arg) throws 
AsterixException {
+        SelectClause selectClause = selectBlock.getSelectClause();
+        if (!selectBlock.hasGroupbyClause() && selectBlock.hasFromClause()) {
+            boolean addImplicitGby = false;
+            if (selectClause.selectRegular()) {
+                addImplicitGby = 
isSqlAggregate(selectClause.getSelectRegular());
+            } else {
+                addImplicitGby = 
isSqlAggregate(selectClause.getSelectElement());
+            }
+            if (addImplicitGby) {
+                // Adds an implicit group-by clause for SQL-92 global 
aggregate.
+                List<GbyVariableExpressionPair> gbyPairList = new 
ArrayList<>();
+                gbyPairList.add(new GbyVariableExpressionPair(null, new 
LiteralExpr(new IntegerLiteral(1))));
+                List<GbyVariableExpressionPair> decorPairList = new 
ArrayList<>();
+                List<VariableExpr> withVarList = new ArrayList<>();
+                GroupbyClause gbyClause = new GroupbyClause(gbyPairList, 
decorPairList, withVarList, null, null, false,
+                        true);
+                selectBlock.setGroupbyClause(gbyClause);
+            }
+        }
+        return super.visit(selectBlock, arg);
+    }
+
+    @Override
+    public Expression visit(CallExpr callExpr, Void arg) throws 
AsterixException {
+        //TODO(buyingyi): rewrite SQL temporal functions
+        FunctionSignature functionSignature = callExpr.getFunctionSignature();
+        
callExpr.setFunctionSignature(FunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature));
+        List<Expression> newExprList = new ArrayList<Expression>();
+        for (Expression expr : callExpr.getExprList()) {
+            newExprList.add(expr.accept(this, arg));
+        }
+        callExpr.setExprList(newExprList);
+        return callExpr;
+    }
+
+    private boolean isSqlAggregate(ILangExpression expr) throws 
AsterixException {
+        CheckSqlAggregateVisitor visitor = new CheckSqlAggregateVisitor();
+        return expr.accept(visitor, null);
+    }
+
+}
diff --git 
a/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
new file mode 100644
index 0000000..e60f3a5
--- /dev/null
+++ 
b/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
@@ -0,0 +1,344 @@
+/*
+ * 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.visitor.base;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.clause.GroupbyClause;
+import org.apache.asterix.lang.common.clause.LetClause;
+import org.apache.asterix.lang.common.clause.LimitClause;
+import org.apache.asterix.lang.common.clause.OrderbyClause;
+import org.apache.asterix.lang.common.clause.WhereClause;
+import org.apache.asterix.lang.common.expression.CallExpr;
+import org.apache.asterix.lang.common.expression.FieldAccessor;
+import org.apache.asterix.lang.common.expression.FieldBinding;
+import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
+import org.apache.asterix.lang.common.expression.IfExpr;
+import org.apache.asterix.lang.common.expression.IndexAccessor;
+import org.apache.asterix.lang.common.expression.ListConstructor;
+import org.apache.asterix.lang.common.expression.LiteralExpr;
+import org.apache.asterix.lang.common.expression.OperatorExpr;
+import org.apache.asterix.lang.common.expression.QuantifiedExpression;
+import org.apache.asterix.lang.common.expression.RecordConstructor;
+import org.apache.asterix.lang.common.expression.UnaryExpr;
+import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.statement.FunctionDecl;
+import org.apache.asterix.lang.common.statement.Query;
+import org.apache.asterix.lang.common.struct.QuantifiedPair;
+import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause;
+import org.apache.asterix.lang.sqlpp.clause.FromClause;
+import org.apache.asterix.lang.sqlpp.clause.FromTerm;
+import org.apache.asterix.lang.sqlpp.clause.HavingClause;
+import org.apache.asterix.lang.sqlpp.clause.JoinClause;
+import org.apache.asterix.lang.sqlpp.clause.NestClause;
+import org.apache.asterix.lang.sqlpp.clause.Projection;
+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.SelectRegular;
+import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
+import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
+import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
+
+public class AbstractSqlppSimpleExpressionVisitor extends 
AbstractSqlppQueryExpressionVisitor<Expression, Void> {
+
+    @Override
+    public Expression visit(FromClause fromClause, Void arg) throws 
AsterixException {
+        for (FromTerm fromTerm : fromClause.getFromTerms()) {
+            fromTerm.accept(this, arg);
+        }
+        return null;
+    }
+
+    @Override
+    public Expression visit(FromTerm fromTerm, Void arg) throws 
AsterixException {
+        // Visit the left expression of a from term.
+        fromTerm.setLeftExpression(fromTerm.getLeftExpression().accept(this, 
arg));
+
+        // Visits join/unnest/nest clauses.
+        for (AbstractBinaryCorrelateClause correlateClause : 
fromTerm.getCorrelateClauses()) {
+            correlateClause.accept(this, arg);
+        }
+        return null;
+    }
+
+    @Override
+    public Expression visit(JoinClause joinClause, Void arg) throws 
AsterixException {
+        
joinClause.setRightExpression(joinClause.getRightExpression().accept(this, 
arg));
+        
joinClause.setConditionExpression(joinClause.getConditionExpression().accept(this,
 arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(NestClause nestClause, Void arg) throws 
AsterixException {
+        
nestClause.setRightExpression(nestClause.getRightExpression().accept(this, 
arg));
+        
nestClause.setConditionExpression(nestClause.getConditionExpression().accept(this,
 arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(UnnestClause unnestClause, Void arg) throws 
AsterixException {
+        
unnestClause.setRightExpression(unnestClause.getRightExpression().accept(this, 
arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(Projection projection, Void arg) throws 
AsterixException {
+        projection.setExpression(projection.getExpression().accept(this, arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(SelectBlock selectBlock, Void arg) throws 
AsterixException {
+        // Traverses the select block in the order of "from", "let"s, "where",
+        // "group by", "let"s, "having" and "select".
+        if (selectBlock.hasFromClause()) {
+            selectBlock.getFromClause().accept(this, arg);
+        }
+        if (selectBlock.hasLetClauses()) {
+            List<LetClause> letList = selectBlock.getLetList();
+            for (LetClause letClause : letList) {
+                letClause.accept(this, arg);
+            }
+        }
+        if (selectBlock.hasWhereClause()) {
+            selectBlock.getWhereClause().accept(this, arg);
+        }
+        if (selectBlock.hasGroupbyClause()) {
+            selectBlock.getGroupbyClause().accept(this, arg);
+        }
+        if (selectBlock.hasLetClausesAfterGroupby()) {
+            List<LetClause> letListAfterGby = 
selectBlock.getLetListAfterGroupby();
+            for (LetClause letClauseAfterGby : letListAfterGby) {
+                letClauseAfterGby.accept(this, arg);
+            }
+        }
+        if (selectBlock.hasHavingClause()) {
+            selectBlock.getHavingClause().accept(this, arg);
+        }
+        selectBlock.getSelectClause().accept(this, arg);
+        return null;
+    }
+
+    @Override
+    public Expression visit(SelectClause selectClause, Void arg) throws 
AsterixException {
+        if (selectClause.selectElement()) {
+            selectClause.getSelectElement().accept(this, arg);
+        }
+        if (selectClause.selectRegular()) {
+            selectClause.getSelectRegular().accept(this, arg);
+        }
+        return null;
+    }
+
+    @Override
+    public Expression visit(SelectElement selectElement, Void arg) throws 
AsterixException {
+        selectElement.setExpression(selectElement.getExpression().accept(this, 
arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(SelectRegular selectRegular, Void arg) throws 
AsterixException {
+        for (Projection projection : selectRegular.getProjections()) {
+            projection.accept(this, arg);
+        }
+        return null;
+    }
+
+    @Override
+    public Expression visit(SelectSetOperation selectSetOperation, Void arg) 
throws AsterixException {
+        selectSetOperation.getLeftInput().accept(this, arg);
+        for (SetOperationRight right : selectSetOperation.getRightInputs()) {
+            right.getSetOperationRightInput().accept(this, arg);
+        }
+        return null;
+    }
+
+    @Override
+    public Expression visit(HavingClause havingClause, Void arg) throws 
AsterixException {
+        
havingClause.setFilterExpression(havingClause.getFilterExpression().accept(this,
 arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(Query q, Void arg) throws AsterixException {
+        q.setBody(q.getBody().accept(this, arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(FunctionDecl fd, Void arg) throws AsterixException 
{
+        fd.setFuncBody(fd.getFuncBody().accept(this, arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(WhereClause whereClause, Void arg) throws 
AsterixException {
+        whereClause.setWhereExpr(whereClause.getWhereExpr().accept(this, arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(OrderbyClause oc, Void arg) throws 
AsterixException {
+        List<Expression> newOrderbyList = new ArrayList<Expression>();
+        for (Expression orderExpr : oc.getOrderbyList()) {
+            newOrderbyList.add(orderExpr.accept(this, arg));
+        }
+        oc.setOrderbyList(newOrderbyList);
+        return null;
+    }
+
+    @Override
+    public Expression visit(GroupbyClause gc, Void arg) throws 
AsterixException {
+        for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
+            gbyVarExpr.setExpr(gbyVarExpr.getExpr().accept(this, arg));
+        }
+        return null;
+    }
+
+    @Override
+    public Expression visit(LimitClause limitClause, Void arg) throws 
AsterixException {
+        limitClause.setLimitExpr(limitClause.getLimitExpr().accept(this, arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(LetClause letClause, Void arg) throws 
AsterixException {
+        letClause.setBindingExpr(letClause.getBindingExpr().accept(this, arg));
+        return null;
+    }
+
+    @Override
+    public Expression visit(SelectExpression selectExpression, Void arg) 
throws AsterixException {
+        // visit let list
+        if (selectExpression.hasLetClauses()) {
+            for (LetClause letClause : selectExpression.getLetList()) {
+                letClause.accept(this, arg);
+            }
+        }
+
+        // visit the main select.
+        selectExpression.getSelectSetOperation().accept(this, arg);
+
+        // visit order by
+        if (selectExpression.hasOrderby()) {
+            for (Expression orderExpr : 
selectExpression.getOrderbyClause().getOrderbyList()) {
+                orderExpr.accept(this, arg);
+            }
+        }
+
+        // visit limit
+        if (selectExpression.hasLimit()) {
+            selectExpression.getLimitClause().accept(this, arg);
+        }
+        return selectExpression;
+    }
+
+    @Override
+    public Expression visit(LiteralExpr l, Void arg) throws AsterixException {
+        return l;
+    }
+
+    @Override
+    public Expression visit(ListConstructor lc, Void arg) throws 
AsterixException {
+        List<Expression> newExprList = new ArrayList<Expression>();
+        for (Expression expr : lc.getExprList()) {
+            newExprList.add(expr.accept(this, arg));
+        }
+        lc.setExprList(newExprList);
+        return lc;
+    }
+
+    @Override
+    public Expression visit(RecordConstructor rc, Void arg) throws 
AsterixException {
+        for (FieldBinding binding : rc.getFbList()) {
+            binding.setLeftExpr(binding.getLeftExpr().accept(this, arg));
+            binding.setRightExpr(binding.getRightExpr().accept(this, arg));
+        }
+        return rc;
+    }
+
+    @Override
+    public Expression visit(OperatorExpr operatorExpr, Void arg) throws 
AsterixException {
+        List<Expression> newExprList = new ArrayList<Expression>();
+        for (Expression expr : operatorExpr.getExprList()) {
+            newExprList.add(expr.accept(this, arg));
+        }
+        operatorExpr.setExprList(newExprList);
+        return operatorExpr;
+    }
+
+    @Override
+    public Expression visit(IfExpr ifExpr, Void arg) throws AsterixException {
+        ifExpr.setCondExpr(ifExpr.getCondExpr().accept(this, arg));
+        ifExpr.setThenExpr(ifExpr.getThenExpr().accept(this, arg));
+        ifExpr.setElseExpr(ifExpr.getElseExpr().accept(this, arg));
+        return ifExpr;
+    }
+
+    @Override
+    public Expression visit(QuantifiedExpression qe, Void arg) throws 
AsterixException {
+        for (QuantifiedPair pair : qe.getQuantifiedList()) {
+            pair.setExpr(pair.getExpr().accept(this, arg));
+        }
+        qe.setSatisfiesExpr(qe.getSatisfiesExpr().accept(this, arg));
+        return qe;
+    }
+
+    @Override
+    public Expression visit(CallExpr callExpr, Void arg) throws 
AsterixException {
+        List<Expression> newExprList = new ArrayList<Expression>();
+        for (Expression expr : callExpr.getExprList()) {
+            newExprList.add(expr.accept(this, arg));
+        }
+        callExpr.setExprList(newExprList);
+        return callExpr;
+    }
+
+    @Override
+    public Expression visit(VariableExpr varExpr, Void arg) throws 
AsterixException {
+        return varExpr;
+    }
+
+    @Override
+    public Expression visit(UnaryExpr u, Void arg) throws AsterixException {
+        u.setExpr(u.getExpr().accept(this, arg));
+        return u;
+    }
+
+    @Override
+    public Expression visit(FieldAccessor fa, Void arg) throws 
AsterixException {
+        fa.setExpr(fa.getExpr().accept(this, arg));
+        return fa;
+    }
+
+    @Override
+    public Expression visit(IndexAccessor ia, Void arg) throws 
AsterixException {
+        ia.setExpr(ia.getExpr().accept(this, arg));
+        if (ia.getIndexExpr() != null) {
+            ia.setIndexExpr(ia.getIndexExpr());
+        }
+        return ia;
+    }
+
+}

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/763
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I97ad557ac19da50effe45a243d97dd317540fb0d
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Yingyi Bu <[email protected]>

Reply via email to