You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by bu...@apache.org on 2016/08/15 15:45:35 UTC

[4/8] asterixdb git commit: Clean up GROUP BY and WITH clause.

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/fuzzyjoin/dblp-csx-3_5/dblp-csx-3_5.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/fuzzyjoin/dblp-csx-3_5/dblp-csx-3_5.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/fuzzyjoin/dblp-csx-3_5/dblp-csx-3_5.3.ast
index 44ac6dd..43d5d8d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/fuzzyjoin/dblp-csx-3_5/dblp-csx-3_5.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/fuzzyjoin/dblp-csx-3_5/dblp-csx-3_5.3.ast
@@ -145,26 +145,16 @@ FROM [  (
               Variable [ Name=$token ]
               GROUP AS Variable [ Name=#1 ]
               (
-                id:=Variable [ Name=$id ]
-                token:=Variable [ Name=$token ]
                 paper:=Variable [ Name=$paper ]
-                tokenUnranked:=Variable [ Name=$tokenUnranked ]
-                lenDBLP:=Variable [ Name=$lenDBLP ]
-                tokensUnrankedDBLP:=Variable [ Name=$tokensUnrankedDBLP ]
-                idDBLP:=Variable [ Name=$idDBLP ]
-                prefixTokenCSX:=Variable [ Name=$prefixTokenCSX ]
-                paperCSX:=Variable [ Name=$paperCSX ]
-                prefixTokenDBLP:=Variable [ Name=$prefixTokenDBLP ]
-                paperDBLP:=Variable [ Name=$paperDBLP ]
+                token:=Variable [ Name=$token ]
               )
 
             Orderby
               FunctionCall fuzzyjoin.sql-count@1[
                 (
                   SELECT ELEMENT [
-                  FieldAccessor [
-                    Variable [ Name=#2 ]
-                    Field=id
+                  FunctionCall Metadata.dataset@1[
+                    LiteralExpr [STRING] [id]
                   ]
                   ]
                   FROM [                    Variable [ Name=#1 ]
@@ -249,30 +239,16 @@ Variable [ Name=$i ]
               Variable [ Name=$token ]
               GROUP AS Variable [ Name=#3 ]
               (
-                id:=Variable [ Name=$id ]
-                token:=Variable [ Name=$token ]
                 paper:=Variable [ Name=$paper ]
-                tokenUnranked:=Variable [ Name=$tokenUnranked ]
-                lenCSX:=Variable [ Name=$lenCSX ]
-                tokensUnrankedCSX:=Variable [ Name=$tokensUnrankedCSX ]
-                idCSX:=Variable [ Name=$idCSX ]
-                tokensDBLP:=Variable [ Name=$tokensDBLP ]
-                lenDBLP:=Variable [ Name=$lenDBLP ]
-                tokensUnrankedDBLP:=Variable [ Name=$tokensUnrankedDBLP ]
-                idDBLP:=Variable [ Name=$idDBLP ]
-                prefixTokenCSX:=Variable [ Name=$prefixTokenCSX ]
-                paperCSX:=Variable [ Name=$paperCSX ]
-                prefixTokenDBLP:=Variable [ Name=$prefixTokenDBLP ]
-                paperDBLP:=Variable [ Name=$paperDBLP ]
+                token:=Variable [ Name=$token ]
               )
 
             Orderby
               FunctionCall fuzzyjoin.sql-count@1[
                 (
                   SELECT ELEMENT [
-                  FieldAccessor [
-                    Variable [ Name=#4 ]
-                    Field=id
+                  FunctionCall Metadata.dataset@1[
+                    LiteralExpr [STRING] [id]
                   ]
                   ]
                   FROM [                    Variable [ Name=#3 ]
@@ -336,19 +312,10 @@ Variable [ Name=$i ]
       Variable [ Name=$sim ]
       GROUP AS Variable [ Name=#5 ]
       (
-        sim:=Variable [ Name=$sim ]
-        tokensCSX:=Variable [ Name=$tokensCSX ]
-        lenCSX:=Variable [ Name=$lenCSX ]
-        tokensUnrankedCSX:=Variable [ Name=$tokensUnrankedCSX ]
-        idCSX:=Variable [ Name=$idCSX ]
-        tokensDBLP:=Variable [ Name=$tokensDBLP ]
-        lenDBLP:=Variable [ Name=$lenDBLP ]
-        tokensUnrankedDBLP:=Variable [ Name=$tokensUnrankedDBLP ]
-        idDBLP:=Variable [ Name=$idDBLP ]
-        prefixTokenCSX:=Variable [ Name=$prefixTokenCSX ]
-        paperCSX:=Variable [ Name=$paperCSX ]
-        prefixTokenDBLP:=Variable [ Name=$prefixTokenDBLP ]
         paperDBLP:=Variable [ Name=$paperDBLP ]
+        prefixTokenDBLP:=Variable [ Name=$prefixTokenDBLP ]
+        paperCSX:=Variable [ Name=$paperCSX ]
+        prefixTokenCSX:=Variable [ Name=$prefixTokenCSX ]
       )
 
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_02/hdfs_02.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_02/hdfs_02.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_02/hdfs_02.3.ast
index 9d99609..f1ac649 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_02/hdfs_02.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_02/hdfs_02.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     LiteralExpr [STRING] [count]
     :
     FunctionCall test.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=token
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$token ]
     ]
   )
 ]
@@ -45,8 +35,8 @@ Groupby
   Variable [ Name=$token ]
   GROUP AS Variable [ Name=#1 ]
   (
-    token:=Variable [ Name=$token ]
     line:=Variable [ Name=$line ]
+    token:=Variable [ Name=$token ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_03/hdfs_03.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_03/hdfs_03.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_03/hdfs_03.3.ast
index 9d99609..f1ac649 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_03/hdfs_03.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_03/hdfs_03.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     LiteralExpr [STRING] [count]
     :
     FunctionCall test.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=token
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$token ]
     ]
   )
 ]
@@ -45,8 +35,8 @@ Groupby
   Variable [ Name=$token ]
   GROUP AS Variable [ Name=#1 ]
   (
-    token:=Variable [ Name=$token ]
     line:=Variable [ Name=$line ]
+    token:=Variable [ Name=$token ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_shortcircuit/hdfs_shortcircuit.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_shortcircuit/hdfs_shortcircuit.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_shortcircuit/hdfs_shortcircuit.3.ast
index 9d99609..f1ac649 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_shortcircuit/hdfs_shortcircuit.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hdfs/hdfs_shortcircuit/hdfs_shortcircuit.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     LiteralExpr [STRING] [count]
     :
     FunctionCall test.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=token
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$token ]
     ]
   )
 ]
@@ -45,8 +35,8 @@ Groupby
   Variable [ Name=$token ]
   GROUP AS Variable [ Name=#1 ]
   (
-    token:=Variable [ Name=$token ]
     line:=Variable [ Name=$line ]
+    token:=Variable [ Name=$token ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hints/issue_251_dataset_hint_6/issue_251_dataset_hint_6.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hints/issue_251_dataset_hint_6/issue_251_dataset_hint_6.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hints/issue_251_dataset_hint_6/issue_251_dataset_hint_6.3.ast
index 9d99609..f1ac649 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hints/issue_251_dataset_hint_6/issue_251_dataset_hint_6.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/hints/issue_251_dataset_hint_6/issue_251_dataset_hint_6.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     LiteralExpr [STRING] [count]
     :
     FunctionCall test.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=token
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$token ]
     ]
   )
 ]
@@ -45,8 +35,8 @@ Groupby
   Variable [ Name=$token ]
   GROUP AS Variable [ Name=#1 ]
   (
-    token:=Variable [ Name=$token ]
     line:=Variable [ Name=$line ]
+    token:=Variable [ Name=$token ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/groupby-orderby-count/groupby-orderby-count.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/groupby-orderby-count/groupby-orderby-count.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/groupby-orderby-count/groupby-orderby-count.3.ast
index b1d80ff..259f96d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/groupby-orderby-count/groupby-orderby-count.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/groupby-orderby-count/groupby-orderby-count.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     LiteralExpr [STRING] [count]
     :
     FunctionCall twitter.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#3 ]
-          Field=token
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS Variable [ Name=#3 ]
-        ]
-      )
+      Variable [ Name=$token ]
     ]
   )
 ]
@@ -45,23 +35,13 @@ Groupby
   Variable [ Name=$token ]
   GROUP AS Variable [ Name=#1 ]
   (
-    token:=Variable [ Name=$token ]
     t:=Variable [ Name=$t ]
+    token:=Variable [ Name=$token ]
   )
 
 Orderby
   FunctionCall twitter.count@1[
-    (
-      SELECT ELEMENT [
-      FieldAccessor [
-        Variable [ Name=#2 ]
-        Field=token
-      ]
-      ]
-      FROM [        Variable [ Name=#1 ]
-        AS Variable [ Name=#2 ]
-      ]
-    )
+    Variable [ Name=$token ]
   ]
   DESC
   Variable [ Name=$tok ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-issue456/query-issue456.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-issue456/query-issue456.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-issue456/query-issue456.3.ast
index df48810..1dc9f40 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-issue456/query-issue456.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-issue456/query-issue456.3.ast
@@ -6,9 +6,8 @@ OrderedListConstructor [
   FunctionCall test.sql-count@1[
     (
       SELECT ELEMENT [
-      FieldAccessor [
-        Variable [ Name=#2 ]
-        Field=id
+      FunctionCall Metadata.dataset@1[
+        LiteralExpr [STRING] [id]
       ]
       ]
       FROM [        Variable [ Name=#1 ]
@@ -38,7 +37,6 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    id:=Variable [ Name=$id ]
     x:=Variable [ Name=$x ]
   )
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-proposal02/query-proposal02.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-proposal02/query-proposal02.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-proposal02/query-proposal02.3.ast
index 94a37bf..806f0da 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-proposal02/query-proposal02.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/open-closed/query-proposal02/query-proposal02.3.ast
@@ -59,8 +59,8 @@ Groupby
   Variable [ Name=$reftopic ]
   GROUP AS Variable [ Name=#1 ]
   (
-    reftopic:=Variable [ Name=$reftopic ]
     tweet:=Variable [ Name=$tweet ]
+    reftopic:=Variable [ Name=$reftopic ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-no-complex-types/tiny-social-example-no-complex-types.9.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-no-complex-types/tiny-social-example-no-complex-types.9.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-no-complex-types/tiny-social-example-no-complex-types.9.ast
index 5e4e36a..19427c1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-no-complex-types/tiny-social-example-no-complex-types.9.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-no-complex-types/tiny-social-example-no-complex-types.9.ast
@@ -44,8 +44,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    f:=Variable [ Name=$f ]
     r:=Variable [ Name=$r ]
+    f:=Variable [ Name=$f ]
   )
 
 Let Variable [ Name=$count ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-lists/tiny-social-example-only-lists.9.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-lists/tiny-social-example-only-lists.9.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-lists/tiny-social-example-only-lists.9.ast
index 5e4e36a..19427c1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-lists/tiny-social-example-only-lists.9.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-lists/tiny-social-example-only-lists.9.ast
@@ -44,8 +44,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    f:=Variable [ Name=$f ]
     r:=Variable [ Name=$r ]
+    f:=Variable [ Name=$f ]
   )
 
 Let Variable [ Name=$count ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-records/tiny-social-example-only-records.9.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-records/tiny-social-example-only-records.9.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-records/tiny-social-example-only-records.9.ast
index 5e4e36a..19427c1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-records/tiny-social-example-only-records.9.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/records/get-record-fields/tiny-social-example-only-records/tiny-social-example-only-records.9.ast
@@ -44,8 +44,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    f:=Variable [ Name=$f ]
     r:=Variable [ Name=$r ]
+    f:=Variable [ Name=$f ]
   )
 
 Let Variable [ Name=$count ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/semistructured/count-nullable/count-nullable.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/semistructured/count-nullable/count-nullable.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/semistructured/count-nullable/count-nullable.3.ast
index cde6b6d..5d1a417 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/semistructured/count-nullable/count-nullable.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/semistructured/count-nullable/count-nullable.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     LiteralExpr [STRING] [count]
     :
     FunctionCall test.count@1[
-      (
-        SELECT ELEMENT [
-        FieldAccessor [
-          Variable [ Name=#2 ]
-          Field=c
-        ]
-        ]
-        FROM [          Variable [ Name=#1 ]
-          AS Variable [ Name=#2 ]
-        ]
-      )
+      Variable [ Name=$c ]
     ]
   )
 ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation-with-filtering/cell-aggregation-with-filtering.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation-with-filtering/cell-aggregation-with-filtering.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation-with-filtering/cell-aggregation-with-filtering.3.ast
index 657dce3..91e9410 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation-with-filtering/cell-aggregation-with-filtering.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation-with-filtering/cell-aggregation-with-filtering.3.ast
@@ -88,25 +88,13 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    region:=Variable [ Name=$region ]
-    keywords:=Variable [ Name=$keywords ]
     t:=Variable [ Name=$t ]
   )
 
 Let Variable [ Name=$num ]
   :=
   FunctionCall test.count@1[
-    (
-      SELECT ELEMENT [
-      FieldAccessor [
-        Variable [ Name=#2 ]
-        Field=t
-      ]
-      ]
-      FROM [        Variable [ Name=#1 ]
-        AS Variable [ Name=#2 ]
-      ]
-    )
+    Variable [ Name=$t ]
   ]
 Orderby
   Variable [ Name=$num ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation/cell-aggregation.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation/cell-aggregation.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation/cell-aggregation.3.ast
index 193a14b..6f827cf 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation/cell-aggregation.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/spatial/cell-aggregation/cell-aggregation.3.ast
@@ -45,17 +45,7 @@ Let Variable [ Name=$grid ]
     Let Variable [ Name=$num ]
       :=
       FunctionCall test.count@1[
-        (
-          SELECT ELEMENT [
-          FieldAccessor [
-            Variable [ Name=#2 ]
-            Field=o
-          ]
-          ]
-          FROM [            Variable [ Name=#1 ]
-            AS Variable [ Name=#2 ]
-          ]
-        )
+        Variable [ Name=$o ]
       ]
     Orderby
       Variable [ Name=$num ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temp-dataset/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temp-dataset/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temp-dataset/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
index ae8f04d..815615d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temp-dataset/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temp-dataset/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
@@ -167,17 +167,7 @@ RecordConstructor [
     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 ]
     ]
   )
 ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_0/overlap_bins_gby_0.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_0/overlap_bins_gby_0.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_0/overlap_bins_gby_0.3.ast
index bff5906..cf3af4c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_0/overlap_bins_gby_0.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_0/overlap_bins_gby_0.3.ast
@@ -88,8 +88,8 @@ FROM [  (
       Variable [ Name=$j ]
       GROUP AS Variable [ Name=#1 ]
       (
-        j:=Variable [ Name=$j ]
         i:=Variable [ Name=$i ]
+        j:=Variable [ Name=$j ]
       )
 
     Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_1/overlap_bins_gby_1.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_1/overlap_bins_gby_1.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_1/overlap_bins_gby_1.3.ast
index 19503b9..7d10b8d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_1/overlap_bins_gby_1.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_1/overlap_bins_gby_1.3.ast
@@ -104,8 +104,8 @@ Groupby
   Variable [ Name=$j ]
   GROUP AS Variable [ Name=#1 ]
   (
-    j:=Variable [ Name=$j ]
     i2:=Variable [ Name=$i2 ]
+    j:=Variable [ Name=$j ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_3/overlap_bins_gby_3.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_3/overlap_bins_gby_3.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_3/overlap_bins_gby_3.3.ast
index c43f1c7..e9435d1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_3/overlap_bins_gby_3.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/temporal/overlap_bins_gby_3/overlap_bins_gby_3.3.ast
@@ -68,7 +68,6 @@ RecordConstructor [
         GROUP AS Variable [ Name=#1 ]
         (
           i:=Variable [ Name=$i ]
-          bin:=Variable [ Name=$bin ]
         )
 
       Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.ast
index db9a752..16e5ee8 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.ast
@@ -113,7 +113,7 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    employment:=Variable [ Name=$employment ]
     fbu:=Variable [ Name=$fbu ]
+    employment:=Variable [ Name=$employment ]
   )
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1263.23.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1263.23.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1263.23.ast
index 586630d..73652a0 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1263.23.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1263.23.ast
@@ -51,9 +51,6 @@ count
     GROUP AS Variable [ Name=#2 ]
     (
       k:=Variable [ Name=$k ]
-      t:=Variable [ Name=$t ]
-      h:=Variable [ Name=$h ]
-      #1:=Variable [ Name=#1 ]
     )
 
   Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/query-ASTERIXDB-1263.23.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/query-ASTERIXDB-1263.23.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/query-ASTERIXDB-1263.23.ast
index 586630d..73652a0 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/query-ASTERIXDB-1263.23.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/query-ASTERIXDB-1263.23.ast
@@ -51,9 +51,6 @@ count
     GROUP AS Variable [ Name=#2 ]
     (
       k:=Variable [ Name=$k ]
-      t:=Variable [ Name=$t ]
-      h:=Variable [ Name=$h ]
-      #1:=Variable [ Name=#1 ]
     )
 
   Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
index 4b04e3a..47d5a97 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
@@ -117,9 +117,9 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    l:=Variable [ Name=$l ]
-    o:=Variable [ Name=$o ]
     c:=Variable [ Name=$c ]
+    o:=Variable [ Name=$o ]
+    l:=Variable [ Name=$l ]
   )
 
 Let Variable [ Name=$revenue ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
index e50b0b0..6d2ab55 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q04_order_priority/q04_order_priority.3.ast
@@ -43,17 +43,7 @@ RecordConstructor [
     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 ]
     ]
   )
 ]
@@ -108,8 +98,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    t:=Variable [ Name=$t ]
     o:=Variable [ Name=$o ]
+    t:=Variable [ Name=$t ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
index fefccd1..5ee4bfe 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
@@ -299,8 +299,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    o1:=Variable [ Name=$o1 ]
     c:=Variable [ Name=$c ]
+    o1:=Variable [ Name=$o1 ]
   )
 
 Let Variable [ Name=$revenue ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.ast
index f7aeb0f..cc99aab 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.ast
@@ -367,9 +367,8 @@ Groupby
   Variable [ Name=$l_year0 ]
   GROUP AS Variable [ Name=#1 ]
   (
-    l_year0:=Variable [ Name=$l_year0 ]
-    t:=Variable [ Name=$t ]
     locs:=Variable [ Name=$locs ]
+    t:=Variable [ Name=$t ]
   )
 
 Let Variable [ Name=$revenue ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.ast
index 14caa44..8de0c01 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q11_important_stock/q11_important_stock.3.ast
@@ -192,9 +192,8 @@ FROM [  (
       ]
       GROUP AS Variable [ Name=#1 ]
       (
-        sn:=Variable [ Name=$sn ]
         ps:=Variable [ Name=$ps ]
-        sum:=Variable [ Name=$sum ]
+        sn:=Variable [ Name=$sn ]
       )
 
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.ast
index 3da470a..edd1cd8 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q12_shipping/q12_shipping.3.ast
@@ -188,8 +188,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    o:=Variable [ Name=$o ]
     l:=Variable [ Name=$l ]
+    o:=Variable [ Name=$o ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.ast
index 1bd404d..ed68ae8 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.ast
@@ -146,10 +146,8 @@ Groupby
   Variable [ Name=$t ]
   :=
   LiteralExpr [LONG] [1]
-  GROUP AS Variable [ Name=#1 ]
+  GROUP AS Variable [ Name=$g ]
   (
     lp:=Variable [ Name=$lp ]
-    p:=Variable [ Name=$p ]
-    l:=Variable [ Name=$l ]
   )
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.ast
index 8f4559e..1e4ac7b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.ast
@@ -98,8 +98,6 @@ FROM [  FunctionCall Metadata.dataset@1[
       GROUP AS Variable [ Name=#1 ]
       (
         l:=Variable [ Name=$l ]
-        o:=Variable [ Name=$o ]
-        c:=Variable [ Name=$c ]
       )
 
   )
@@ -192,10 +190,10 @@ Groupby
   ]
   GROUP AS Variable [ Name=#2 ]
   (
-    l:=Variable [ Name=$l ]
-    t:=Variable [ Name=$t ]
-    o:=Variable [ Name=$o ]
     c:=Variable [ Name=$c ]
+    o:=Variable [ Name=$o ]
+    t:=Variable [ Name=$t ]
+    l:=Variable [ Name=$l ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/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
----------------------------------------------------------------------
diff --git a/asterixdb/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/asterixdb/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 6d09b11..0d5ca25 100644
--- a/asterixdb/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/asterixdb/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
@@ -442,17 +442,7 @@ Groupby
 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 ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
index f6eaeaf..cab2a8f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
@@ -132,7 +132,6 @@ Groupby
   GROUP AS Variable [ Name=#1 ]
   (
     ct:=Variable [ Name=$ct ]
-    avg:=Variable [ Name=$avg ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
index b0c1038..758fd5a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue601/query-issue601.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     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 ]
     ]
   )
 ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.ast
index 97006bf..991c38a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785-2/query-issue785-2.3.ast
@@ -122,10 +122,9 @@ Let Variable [ Name=$X ]
       ]
       GROUP AS Variable [ Name=#1 ]
       (
-        orders:=Variable [ Name=$orders ]
-        customer:=Variable [ Name=$customer ]
         n:=Variable [ Name=$n ]
-        t:=Variable [ Name=$t ]
+        customer:=Variable [ Name=$customer ]
+        orders:=Variable [ Name=$orders ]
       )
 
     Let Variable [ Name=$sum ]
@@ -204,7 +203,5 @@ Groupby
   GROUP AS Variable [ Name=#2 ]
   (
     x:=Variable [ Name=$x ]
-    X:=Variable [ Name=$X ]
-    t:=Variable [ Name=$t ]
   )
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.ast
index 602feb1..61e0ca4 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue785/query-issue785.3.ast
@@ -38,9 +38,6 @@ RecordConstructor [
         GROUP AS Variable [ Name=#3 ]
         (
           i:=Variable [ Name=$i ]
-          x:=Variable [ Name=$x ]
-          nation_key:=Variable [ Name=$nation_key ]
-          #2:=Variable [ Name=#2 ]
         )
 
       Let Variable [ Name=$sum ]
@@ -156,9 +153,9 @@ FROM [  (
       ]
       GROUP AS Variable [ Name=#1 ]
       (
-        orders:=Variable [ Name=$orders ]
-        customer:=Variable [ Name=$customer ]
         n:=Variable [ Name=$n ]
+        customer:=Variable [ Name=$customer ]
+        orders:=Variable [ Name=$orders ]
       )
 
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.ast
index 2c51fb4..5908531 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch-sql-like/query-issue786/query-issue786.3.ast
@@ -81,10 +81,8 @@ RecordConstructor [
         ]
         GROUP AS Variable [ Name=#1 ]
         (
-          customer:=Variable [ Name=$customer ]
           orders:=Variable [ Name=$orders ]
-          sn:=Variable [ Name=$sn ]
-          nation:=Variable [ Name=$nation ]
+          customer:=Variable [ Name=$customer ]
         )
 
       Let Variable [ Name=$sum ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/nest_aggregate/nest_aggregate.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/nest_aggregate/nest_aggregate.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/nest_aggregate/nest_aggregate.3.ast
index 2c323ea..0207a57 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/nest_aggregate/nest_aggregate.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/nest_aggregate/nest_aggregate.3.ast
@@ -81,10 +81,8 @@ RecordConstructor [
         ]
         GROUP AS Variable [ Name=#1 ]
         (
-          customer:=Variable [ Name=$customer ]
           orders:=Variable [ Name=$orders ]
-          sn:=Variable [ Name=$sn ]
-          nation:=Variable [ Name=$nation ]
+          customer:=Variable [ Name=$customer ]
         )
 
       Let Variable [ Name=$sum ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
index ae8f04d..815615d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.ast
@@ -167,17 +167,7 @@ RecordConstructor [
     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 ]
     ]
   )
 ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
index 4b04e3a..47d5a97 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q03_shipping_priority_nt/q03_shipping_priority_nt.3.ast
@@ -117,9 +117,9 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    l:=Variable [ Name=$l ]
-    o:=Variable [ Name=$o ]
     c:=Variable [ Name=$c ]
+    o:=Variable [ Name=$o ]
+    l:=Variable [ Name=$l ]
   )
 
 Let Variable [ Name=$revenue ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q04_order_priority/q04_order_priority.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q04_order_priority/q04_order_priority.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q04_order_priority/q04_order_priority.3.ast
index 30df063..14ee9fc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q04_order_priority/q04_order_priority.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q04_order_priority/q04_order_priority.3.ast
@@ -108,8 +108,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    t:=Variable [ Name=$t ]
     o:=Variable [ Name=$o ]
+    t:=Variable [ Name=$t ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q05_local_supplier_volume/q05_local_supplier_volume.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
index fefccd1..5ee4bfe 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q05_local_supplier_volume/q05_local_supplier_volume.3.ast
@@ -299,8 +299,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    o1:=Variable [ Name=$o1 ]
     c:=Variable [ Name=$c ]
+    o1:=Variable [ Name=$o1 ]
   )
 
 Let Variable [ Name=$revenue ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q07_volume_shipping/q07_volume_shipping.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q07_volume_shipping/q07_volume_shipping.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q07_volume_shipping/q07_volume_shipping.3.ast
index f7aeb0f..cc99aab 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q07_volume_shipping/q07_volume_shipping.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q07_volume_shipping/q07_volume_shipping.3.ast
@@ -367,9 +367,8 @@ Groupby
   Variable [ Name=$l_year0 ]
   GROUP AS Variable [ Name=#1 ]
   (
-    l_year0:=Variable [ Name=$l_year0 ]
-    t:=Variable [ Name=$t ]
     locs:=Variable [ Name=$locs ]
+    t:=Variable [ Name=$t ]
   )
 
 Let Variable [ Name=$revenue ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q11_important_stock/q11_important_stock.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q11_important_stock/q11_important_stock.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q11_important_stock/q11_important_stock.3.ast
index 14caa44..8de0c01 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q11_important_stock/q11_important_stock.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q11_important_stock/q11_important_stock.3.ast
@@ -192,9 +192,8 @@ FROM [  (
       ]
       GROUP AS Variable [ Name=#1 ]
       (
-        sn:=Variable [ Name=$sn ]
         ps:=Variable [ Name=$ps ]
-        sum:=Variable [ Name=$sum ]
+        sn:=Variable [ Name=$sn ]
       )
 
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q12_shipping/q12_shipping.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q12_shipping/q12_shipping.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q12_shipping/q12_shipping.3.ast
index 6ad3a5b..fa86271 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q12_shipping/q12_shipping.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q12_shipping/q12_shipping.3.ast
@@ -185,8 +185,8 @@ Groupby
   ]
   GROUP AS Variable [ Name=#1 ]
   (
-    o:=Variable [ Name=$o ]
     l:=Variable [ Name=$l ]
+    o:=Variable [ Name=$o ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q14_promotion_effect/q14_promotion_effect.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q14_promotion_effect/q14_promotion_effect.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q14_promotion_effect/q14_promotion_effect.3.ast
index f619293..e52e659 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q14_promotion_effect/q14_promotion_effect.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q14_promotion_effect/q14_promotion_effect.3.ast
@@ -143,10 +143,8 @@ Groupby
   Variable [ Name=$t ]
   :=
   LiteralExpr [LONG] [1]
-  GROUP AS Variable [ Name=#1 ]
+  GROUP AS Variable [ Name=$g ]
   (
     lp:=Variable [ Name=$lp ]
-    p:=Variable [ Name=$p ]
-    l:=Variable [ Name=$l ]
   )
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
index 4c84266..c5ed1ef 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q17_large_gby_variant/q17_large_gby_variant.3.ast
@@ -11,17 +11,7 @@ RecordConstructor [
     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 ]
     ]
   )
   (

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
index d220f48..a6eebfd 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q18_large_volume_customer/q18_large_volume_customer.3.ast
@@ -98,8 +98,6 @@ FROM [  FunctionCall Metadata.dataset@1[
       GROUP AS Variable [ Name=#1 ]
       (
         l:=Variable [ Name=$l ]
-        o:=Variable [ Name=$o ]
-        c:=Variable [ Name=$c ]
       )
 
   )
@@ -190,10 +188,10 @@ Groupby
   ]
   GROUP AS Variable [ Name=#2 ]
   (
-    l:=Variable [ Name=$l ]
-    t:=Variable [ Name=$t ]
-    o:=Variable [ Name=$o ]
     c:=Variable [ Name=$c ]
+    o:=Variable [ Name=$o ]
+    t:=Variable [ Name=$t ]
+    l:=Variable [ Name=$l ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
index 5032a49..b7ff109 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/q22_global_sales_opportunity/q22_global_sales_opportunity.3.ast
@@ -77,17 +77,7 @@ RecordConstructor [
     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 ]
     ]
   )
   (
@@ -132,7 +122,6 @@ Groupby
   GROUP AS Variable [ Name=#1 ]
   (
     ct:=Variable [ Name=$ct ]
-    avg:=Variable [ Name=$avg ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
index fd595c3..cac889b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue562/query-issue562.3.ast
@@ -255,7 +255,6 @@ Groupby
   GROUP AS Variable [ Name=#1 ]
   (
     ct:=Variable [ Name=$ct ]
-    avg:=Variable [ Name=$avg ]
   )
 
 Orderby

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
index 97006bf..991c38a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785-2/query-issue785-2.3.ast
@@ -122,10 +122,9 @@ Let Variable [ Name=$X ]
       ]
       GROUP AS Variable [ Name=#1 ]
       (
-        orders:=Variable [ Name=$orders ]
-        customer:=Variable [ Name=$customer ]
         n:=Variable [ Name=$n ]
-        t:=Variable [ Name=$t ]
+        customer:=Variable [ Name=$customer ]
+        orders:=Variable [ Name=$orders ]
       )
 
     Let Variable [ Name=$sum ]
@@ -204,7 +203,5 @@ Groupby
   GROUP AS Variable [ Name=#2 ]
   (
     x:=Variable [ Name=$x ]
-    X:=Variable [ Name=$X ]
-    t:=Variable [ Name=$t ]
   )
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
index 602feb1..61e0ca4 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue785/query-issue785.3.ast
@@ -38,9 +38,6 @@ RecordConstructor [
         GROUP AS Variable [ Name=#3 ]
         (
           i:=Variable [ Name=$i ]
-          x:=Variable [ Name=$x ]
-          nation_key:=Variable [ Name=$nation_key ]
-          #2:=Variable [ Name=#2 ]
         )
 
       Let Variable [ Name=$sum ]
@@ -156,9 +153,9 @@ FROM [  (
       ]
       GROUP AS Variable [ Name=#1 ]
       (
-        orders:=Variable [ Name=$orders ]
-        customer:=Variable [ Name=$customer ]
         n:=Variable [ Name=$n ]
+        customer:=Variable [ Name=$customer ]
+        orders:=Variable [ Name=$orders ]
       )
 
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
index 2c51fb4..5908531 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tpch/query-issue786/query-issue786.3.ast
@@ -81,10 +81,8 @@ RecordConstructor [
         ]
         GROUP AS Variable [ Name=#1 ]
         (
-          customer:=Variable [ Name=$customer ]
           orders:=Variable [ Name=$orders ]
-          sn:=Variable [ Name=$sn ]
-          nation:=Variable [ Name=$nation ]
+          customer:=Variable [ Name=$customer ]
         )
 
       Let Variable [ Name=$sum ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 862ca26..cf5bda3 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -3257,6 +3257,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="misc">
+      <compilation-unit name="query-ASTERIXDB-971">
+        <output-dir compare="Text">query-ASTERIXDB-971-aql</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="misc">
       <compilation-unit name="query-ASTERIXDB-1531">
         <output-dir compare="Text">query-ASTERIXDB-1531</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 7d2af51..e0e6e87 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1364,7 +1364,7 @@
     <test-case FilePath="custord">
       <compilation-unit name="join_q_09">
         <output-dir compare="Text">join_q_01</output-dir>
-        <expected-error>Cannot resolve ambiguous alias (variable) reference for identifier age</expected-error>
+        <expected-error>Cannot resolve ambiguous alias reference for undefined identifier age</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="custord">
@@ -1420,6 +1420,12 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="dapd">
+      <compilation-unit name="q2-2-negative">
+        <output-dir compare="Text">q2</output-dir>
+        <expected-error>Cannot find dataset e in dataverse test nor an alias with name e</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
       <compilation-unit name="q2-3">
         <output-dir compare="Text">q2</output-dir>
       </compilation-unit>
@@ -1439,6 +1445,36 @@
         <output-dir compare="Text">q2</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-7">
+        <output-dir compare="Text">q2-7</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-8">
+        <output-dir compare="Text">q2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-9">
+        <output-dir compare="Text">q2-9</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-10">
+        <output-dir compare="Text">q2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-11">
+        <output-dir compare="Text">q2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-12">
+        <output-dir compare="Text">q2-12</output-dir>
+      </compilation-unit>
+    </test-case>
     <!--
         <test-case FilePath="dapd">
           <compilation-unit name="q3">
@@ -2355,7 +2391,7 @@
     <test-case FilePath="global-aggregate">
       <compilation-unit name="q05_error">
         <output-dir compare="Text">q01</output-dir>
-        <expected-error>The first argument should be a RECORD, but it is [ FacebookUserType: open</expected-error>
+        <expected-error>The first argument of a field access should be a RECORD, but it is [ FacebookUserType: open</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="global-aggregate">
@@ -2375,6 +2411,16 @@
         <output-dir compare="Text">q08</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="global-aggregate">
+      <compilation-unit name="q09">
+        <output-dir compare="Text">q09</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="global-aggregate">
+      <compilation-unit name="q10">
+        <output-dir compare="Text">q09</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="group-by">
     <test-case FilePath="group-by">
@@ -2408,6 +2454,12 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="group-by">
+      <compilation-unit name="sugar-01-negative">
+        <output-dir compare="Text">core-01</output-dir>
+        <expected-error>The first argument of a field access should be a RECORD, but it is [ EmpType</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="group-by">
       <compilation-unit name="sugar-01-2">
         <output-dir compare="Text">core-01</output-dir>
       </compilation-unit>
@@ -2983,6 +3035,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="misc">
+      <compilation-unit name="query-ASTERIXDB-971">
+        <output-dir compare="Text">query-ASTERIXDB-971-sqlpp</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="misc">
       <compilation-unit name="query-ASTERIXDB-1531">
         <output-dir compare="Text">query-ASTERIXDB-1531</output-dir>
       </compilation-unit>
@@ -7650,7 +7707,7 @@
     <test-case FilePath="union">
       <compilation-unit name="union_negative_2">
         <output-dir compare="Text">union</output-dir>
-        <expected-error>Undefined alias (variable) reference for identifier t</expected-error>
+        <expected-error>Cannot find dataset t in dataverse TinySocial nor an alias with name t</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="union">

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
index 2af2816..0525f80 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
@@ -406,7 +406,7 @@ public class AQLToSQLPPPrintVisitor extends FormatPrintVisitor implements IAQLVi
         for (GbyVariableExpressionPair keyPair : gbyClause.getDecorPairList()) {
             producedVars.add(keyPair.getVar());
         }
-        producedVars.addAll(gbyClause.getWithVarList());
+        producedVars.addAll(gbyClause.getWithVarMap().values());
         return producedVars;
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj b/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
index b690f03..9cffda0 100644
--- a/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
+++ b/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
@@ -2409,7 +2409,7 @@ Clause GroupClause()throws ParseException :
     // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
     List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
     List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
-    List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
+    Map<Expression, VariableExpr> withVarMap = new HashMap<Expression, VariableExpr>();
     VariableExpr var = null;
     VariableExpr withVar = null;
     Expression expr = null;
@@ -2465,20 +2465,20 @@ Clause GroupClause()throws ParseException :
     {
       if(withVar.getIsNewVar()==true)
           throw new ParseException("can't find variable " + withVar.getVar());
-      withVarList.add(withVar);
+      withVarMap.put(withVar, withVar);
       newScope.addNewVarSymbolToScope(withVar.getVar());
     }
     (<COMMA> withVar = VariableRef()
     {
       if(withVar.getIsNewVar()==true)
           throw new ParseException("can't find variable " + withVar.getVar());
-      withVarList.add(withVar);
+      withVarMap.put(withVar, withVar);
       newScope.addNewVarSymbolToScope(withVar.getVar());
     })*
     {
       gbc.setGbyPairList(vePairList);
       gbc.setDecorPairList(decorPairList);
-      gbc.setWithVarList(withVarList);
+      gbc.setWithVarMap(withVarMap);
       replaceCurrentScope(newScope);
       return gbc;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
index 3565c5a..0f75839 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
@@ -20,6 +20,7 @@ package org.apache.asterix.lang.common.clause;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.lang.common.base.Clause;
@@ -35,7 +36,7 @@ public class GroupbyClause implements Clause {
 
     private List<GbyVariableExpressionPair> gbyPairList;
     private List<GbyVariableExpressionPair> decorPairList;
-    private List<VariableExpr> withVarList;
+    private Map<Expression, VariableExpr> withVarMap;
     private VariableExpr groupVar;
     private List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<>();
     private boolean hashGroupByHint;
@@ -46,17 +47,17 @@ public class GroupbyClause implements Clause {
     }
 
     public GroupbyClause(List<GbyVariableExpressionPair> gbyPairList, List<GbyVariableExpressionPair> decorPairList,
-            List<VariableExpr> withVarList, VariableExpr groupVarExpr,
+            Map<Expression, 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,
+            Map<Expression, VariableExpr> withVarList, VariableExpr groupVarExpr,
             List<Pair<Expression, Identifier>> groupFieldList, boolean hashGroupByHint, boolean groupAll) {
         this.gbyPairList = gbyPairList;
         this.decorPairList = decorPairList;
-        this.withVarList = withVarList;
+        this.withVarMap = withVarList;
         this.groupVar = groupVarExpr;
         if (groupFieldList != null) {
             this.groupFieldList = groupFieldList;
@@ -73,12 +74,12 @@ public class GroupbyClause implements Clause {
         this.gbyPairList = vePairList;
     }
 
-    public List<VariableExpr> getWithVarList() {
-        return withVarList;
+    public Map<Expression, VariableExpr> getWithVarMap() {
+        return withVarMap;
     }
 
-    public void setWithVarList(List<VariableExpr> withVarList) {
-        this.withVarList = withVarList;
+    public void setWithVarMap(Map<Expression, VariableExpr> withVarList) {
+        this.withVarMap = withVarList;
     }
 
     public VariableExpr getGroupVar() {
@@ -127,8 +128,8 @@ public class GroupbyClause implements Clause {
         return decorPairList != null && !decorPairList.isEmpty();
     }
 
-    public boolean hasWithList() {
-        return withVarList != null && !withVarList.isEmpty();
+    public boolean hasWithMap() {
+        return withVarMap != null && !withVarMap.isEmpty();
     }
 
     public boolean hasGroupVar() {
@@ -146,7 +147,7 @@ public class GroupbyClause implements Clause {
     @Override
     public int hashCode() {
         return ObjectUtils.hashCodeMulti(decorPairList, gbyPairList, groupAll, groupFieldList, groupVar,
-                hashGroupByHint, withVarList);
+                hashGroupByHint, withVarMap);
     }
 
     @Override
@@ -162,6 +163,6 @@ public class GroupbyClause implements Clause {
                 && ObjectUtils.equals(gbyPairList, target.gbyPairList) && groupAll == target.groupAll
                 && ObjectUtils.equals(groupFieldList, target.groupFieldList);
         return equals && ObjectUtils.equals(groupVar, target.groupVar) && hashGroupByHint == target.hashGroupByHint
-                && ObjectUtils.equals(withVarList, target.withVarList);
+                && ObjectUtils.equals(withVarMap, target.withVarMap);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/context/Scope.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/context/Scope.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/context/Scope.java
index 595fb11..97cad5e 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/context/Scope.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/context/Scope.java
@@ -224,4 +224,8 @@ public final class Scope {
         }
         return vars;
     }
+
+    public Scope getParentScope(){
+        return parent;
+    }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java
index 534c74f..dbaea37 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java
@@ -27,7 +27,6 @@ import org.apache.commons.lang3.ObjectUtils;
 public class VariableExpr implements Expression {
     private VarIdentifier var;
     private boolean isNewVar;
-    private boolean namedValueAccess = false;
 
     public VariableExpr() {
         super();
@@ -66,14 +65,6 @@ public class VariableExpr implements Expression {
         return visitor.visit(this, arg);
     }
 
-    public void setNamedValueAccess(boolean namedValueAccess) {
-        this.namedValueAccess = namedValueAccess;
-    }
-
-    public boolean namedValueAccess() {
-        return namedValueAccess;
-    }
-
     @Override
     public int hashCode() {
         return ObjectUtils.hashCode(var);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/rewrites/ExpressionSubstitutionEnvironment.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/rewrites/ExpressionSubstitutionEnvironment.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/rewrites/ExpressionSubstitutionEnvironment.java
deleted file mode 100644
index 8f5597f..0000000
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/rewrites/ExpressionSubstitutionEnvironment.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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.common.rewrites;
-
-import java.util.ArrayDeque;
-import java.util.Collection;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.base.ILangExpression;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Multiset;
-
-/**
- * This class is in charge of substitute expressions by a given mapping while
- * traversing a given AST. The traversal and expression substitution should
- * be based on the correct variable scoping. In order to support scoping at the
- * caller, this class provides methods like mark, reset and pop.
- */
-public class ExpressionSubstitutionEnvironment {
-
-    @FunctionalInterface
-    public static interface FreeVariableCollector {
-        public Collection<VariableExpr> getFreeVariable(ILangExpression expr) throws AsterixException;
-    }
-
-    @FunctionalInterface
-    public static interface DeepCopier {
-        public ILangExpression deepCopy(ILangExpression expr) throws AsterixException;
-    }
-
-    private Map<Expression, Expression> exprMap = new HashMap<>();
-    private Map<VariableExpr, Expression> freeVarToExprMap = new HashMap<>();
-
-    // We use multiset here because variables can be defined multiple times
-    // in the scope stack.
-    private Multiset<Expression> disabledExpr = HashMultiset.create();
-
-    // Snapshots of variables that should be disabled for replacement,
-    // e.g., if a variable is redefined in a closer scope.
-    private Deque<Multiset<Expression>> disabledExprBackup = new ArrayDeque<>();
-
-    public ExpressionSubstitutionEnvironment() {
-        // Default constructor.
-    }
-
-    public ExpressionSubstitutionEnvironment(Map<Expression, Expression> map, FreeVariableCollector freeVarCollector)
-            throws AsterixException {
-        addMapping(map, freeVarCollector);
-    }
-
-    /**
-     * Finds a substitution expression.
-     *
-     * @param expr
-     *            the original expression.
-     * @return the new, replaced expression.
-     */
-    public Expression findSubstitution(Expression expr, DeepCopier deepCopier) throws AsterixException {
-        Expression replacementExpr = exprMap.get(expr);
-        if (replacementExpr != null && !disabledExpr.contains(replacementExpr)) {
-            return (Expression) deepCopier.deepCopy(replacementExpr);
-        }
-        return expr;
-    }
-
-    /**
-     * Disable a substitution when a free variable in the expression is re-defined.
-     *
-     * @param var
-     *            a re-defined variable.
-     */
-    public void disableVariable(VariableExpr var) {
-        Expression expr = freeVarToExprMap.get(var);
-        if (expr != null) {
-            disabledExpr.add(expr);
-        }
-    }
-
-    /**
-     * Re-enable a substitution when a re-defined variable exits its scope.
-     *
-     * @param var
-     *            a re-defined variable.
-     */
-    public void enableVariable(VariableExpr var) {
-        Expression expr = freeVarToExprMap.get(var);
-        if (expr != null) {
-            disabledExpr.remove(expr);
-        }
-    }
-
-    /**
-     * Tasks a snapshot of the current states.
-     *
-     * @return the snapshot id that can be reset to in the future.
-     */
-    public int mark() {
-        Multiset<Expression> copyOfDisabledExprs = HashMultiset.create();
-        copyOfDisabledExprs.addAll(disabledExpr);
-        disabledExprBackup.push(copyOfDisabledExprs);
-        return disabledExprBackup.size() - 1;
-    }
-
-    /**
-     * Resets the internal states to a snapshot.
-     *
-     * @param depth,
-     *            the snapshot id that the caller wants to recover to.
-     */
-    public void reset(int depth) {
-        while (disabledExprBackup.size() > depth) {
-            disabledExpr = disabledExprBackup.pop();
-        }
-    }
-
-    /**
-     * Restores to the most-recent snapshot.
-     */
-    public void pop() {
-        if (!disabledExprBackup.isEmpty()) {
-            disabledExpr = disabledExprBackup.pop();
-        }
-    }
-
-    @Override
-    public String toString() {
-        return exprMap.toString();
-    }
-
-    private void addMapping(Map<Expression, Expression> map, FreeVariableCollector freeVarCollector)
-            throws AsterixException {
-        exprMap.putAll(map);
-        // Put free variable to target expression map.
-        for (Entry<Expression, Expression> entry : map.entrySet()) {
-            Expression targetExpr = entry.getKey();
-            for (VariableExpr freeVar : freeVarCollector.getFreeVariable(targetExpr)) {
-                freeVarToExprMap.put(freeVar, targetExpr);
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8671ddf8/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/VarIdentifier.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/VarIdentifier.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/VarIdentifier.java
index a217bea..c2a6f38 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/VarIdentifier.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/VarIdentifier.java
@@ -22,22 +22,32 @@ import org.apache.commons.lang3.ObjectUtils;
 
 public final class VarIdentifier extends Identifier {
     private int id = 0;
+    private boolean namedValueAccess = false;
 
     public VarIdentifier() {
         super();
     }
 
+    public VarIdentifier(VarIdentifier v){
+        this(v.getValue(), v.getId(), v.namedValueAccess());
+    }
+
     public VarIdentifier(String value) {
-        super();
-        this.value = value;
+        this(value, 0);
     }
 
     public VarIdentifier(String value, int id) {
+        this(value, id, false);
+    }
+
+    private VarIdentifier(String value, int id, boolean namedValueAccess) {
         super();
         this.value = value;
         this.id = id;
+        this.namedValueAccess = namedValueAccess;
     }
 
+
     public void setId(int id) {
         this.id = id;
     }
@@ -53,6 +63,14 @@ public final class VarIdentifier extends Identifier {
         return vi;
     }
 
+    public void setNamedValueAccess(boolean namedValueAccess) {
+        this.namedValueAccess = namedValueAccess;
+    }
+
+    public boolean namedValueAccess() {
+        return namedValueAccess;
+    }
+
     @Override
     public int hashCode() {
         return ObjectUtils.hashCodeMulti(value);