Add 'group by ... keeping ...' as a synonym of 'group by ... with ...'.

Change-Id: I9aa7354092e13d7a95a3ab0ee4b02a468dbf3baf
Reviewed-on: http://fulliautomatix.ics.uci.edu:8443/187
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <westmann@gmail.com>
diff --git a/asterix-app/src/test/resources/AQLTS/queries-sql-like/2.aql b/asterix-app/src/test/resources/AQLTS/queries-sql-like/2.aql
index d094e7e..c5199e6 100644
--- a/asterix-app/src/test/resources/AQLTS/queries-sql-like/2.aql
+++ b/asterix-app/src/test/resources/AQLTS/queries-sql-like/2.aql
@@ -1,11 +1,11 @@
 from $event in dataset('Event')
 from $sponsor in $event.sponsoring_sigs
 with $es := { "event": $event, "sponsor": $sponsor }
-group by $sig_name := $sponsor.sig_name with $es
+group by $sig_name := $sponsor.sig_name keeping $es
 with $sig_sponsorship_count := count($es)
 with $by_chapter :=
    from $e in $es
-   group by $chapter_name := $e.sponsor.chapter_name with $es
+   group by $chapter_name := $e.sponsor.chapter_name keeping $es
    select { "chapter_name": $chapter_name, "escount" : count($es) }
 order by $sig_sponsorship_count desc
 limit 5
diff --git a/asterix-app/src/test/resources/AQLTS/queries-sql-like/functionDecl1.aql b/asterix-app/src/test/resources/AQLTS/queries-sql-like/functionDecl1.aql
index 9a77c84..c9e9231 100644
--- a/asterix-app/src/test/resources/AQLTS/queries-sql-like/functionDecl1.aql
+++ b/asterix-app/src/test/resources/AQLTS/queries-sql-like/functionDecl1.aql
@@ -2,11 +2,11 @@
 from $event in $events
 from $sponsor in $event.sponsoring_sigs
 with $es := { "event": $event, "sponsor": $sponsor }
-group by $sig_name := $sponsor.sig_name with $es
+group by $sig_name := $sponsor.sig_name keeping $es
 with $sig_sponsorship_count := count($es)
 with $by_chapter :=
    from $e in $es
-   group by $chapter_name := $e.sponsor.chapter_name with $es
+   group by $chapter_name := $e.sponsor.chapter_name keeping $es
    select { "chapter_name": $chapter_name, "escount" : count($es) }
 order by $sig_sponsorship_count desc
 limit 5
diff --git a/asterix-app/src/test/resources/AQLTS/queries-sql-like/nestedFLWOGR3.aql b/asterix-app/src/test/resources/AQLTS/queries-sql-like/nestedFLWOGR3.aql
index 0f5fa5f..2cb9b22 100644
--- a/asterix-app/src/test/resources/AQLTS/queries-sql-like/nestedFLWOGR3.aql
+++ b/asterix-app/src/test/resources/AQLTS/queries-sql-like/nestedFLWOGR3.aql
@@ -1,11 +1,11 @@
 from $event in dataset('Event')
 from $sponsor in $event.sponsoring_sigs
 with $es := { "event": $event, "sponsor": $sponsor }
-group by $sig_name := $sponsor.sig_name with $es
+group by $sig_name := $sponsor.sig_name keeping $es
 with $sig_sponsorship_count := count($es)
 with $by_chapter :=
    from $e in $es
-   group by $chapter_name := $e.sponsor.chapter_name with $es
+   group by $chapter_name := $e.sponsor.chapter_name keeping $es
    select { "chapter_name": $chapter_name, "escount" : count($es) }
 order by $sig_sponsorship_count desc
 limit 5 offset 2
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.aql
index 77ce59b..e02b1f8 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.aql
@@ -6,7 +6,7 @@
 /*+ hash*/
 group by $l_returnflag := $l.l_returnflag,
          $l_linestatus := $l.l_linestatus
-  with $l
+  keeping $l
 order by $l_returnflag, $l_linestatus
 select {
   "l_returnflag": $l_returnflag,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.aql
index 27bce43..85754b4 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.aql
@@ -92,7 +92,7 @@
   )
   where $p.p_partkey = $pssrn.p_partkey and like($p.p_type, '%BRASS')
   /*+ hash*/
-  group by $p_partkey := $pssrn.p_partkey with $pssrn
+  group by $p_partkey := $pssrn.p_partkey keeping $pssrn
   select {
     "p_partkey": $p_partkey,
     "ps_min_supplycost": min(from $i in $pssrn select $i.ps_supplycost)
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.aql
index 4ccd1c7..ffd38ee 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.aql
@@ -10,7 +10,7 @@
   $o.o_orderdate < '1995-03-15' and $l.l_shipdate > '1995-03-15'
 /*+ hash*/
 group by $l_orderkey := $l.l_orderkey, $o_orderdate := $o.o_orderdate, $o_shippriority := $o.o_shippriority
-  with $l
+  keeping $l
 with $revenue := sum (
   from $i in $l
   select
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.aql
index b75936b..b0fc555 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q04_order_priority/q04_order_priority.3.query.aql
@@ -12,7 +12,7 @@
 from $t in tmp()
 where $o.o_orderkey = $t.o_orderkey and
   $o.o_orderdate >= '1993-07-01' and $o.o_orderdate < '1993-10-01'
-group by $o_orderpriority := $o.o_orderpriority with $o
+group by $o_orderpriority := $o.o_orderpriority keeping $o
 order by $o_orderpriority
 select {
   "order_priority": $o_orderpriority,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.aql
index 7d2a7d9..c939f6c 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q05_local_supplier_volume/q05_local_supplier_volume.3.query.aql
@@ -43,7 +43,7 @@
 )
 where $c.c_nationkey = $o1.s_nationkey and $c.c_custkey = $o1.o_custkey
 /*+ hash*/
-group by $n_name := $o1.n_name with $o1
+group by $n_name := $o1.n_name keeping $o1
 with $revenue := sum (
   from $i in $o1
   select
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.aql
index 7240456..af8bbf3 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q07_volume_shipping/q07_volume_shipping.3.query.aql
@@ -52,7 +52,7 @@
   and $locs.s_nationkey = $t.s_nationkey
 with $l_year0 := get-year($locs.l_shipdate)
 group by $supp_nation := $t.supp_nation, $cust_nation := $t.cust_nation, $l_year := $l_year0
-with $locs
+keeping $locs
 with $revenue := sum(from $i in $locs select $i.l_extendedprice * (1 - $i.l_discount))
 order by $supp_nation, $cust_nation, $l_year
 select {
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.aql
index 962b6a0..aacf426 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q08_national_market_share/q08_national_market_share.3.query.aql
@@ -63,7 +63,7 @@
     "s_name": $n2.n_name
   }
 )
-group by $year := $t.year with $t
+group by $year := $t.year keeping $t
 order by $year
 select {
   "year": $year,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.aql
index 5f9d13f..f6327aa 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.aql
@@ -58,7 +58,7 @@
     "amount": $amount
   }
 )
-group by $nation := $profit.nation, $o_year := $profit.o_year with $profit
+group by $nation := $profit.nation, $o_year := $profit.o_year keeping $profit
 order by $nation, $o_year desc
 select {
   "nation": $nation,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.aql
index 61a7f77..b484cfa 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item/q10_returned_item.3.query.aql
@@ -37,7 +37,7 @@
     $c_name:=$locn.c_name,
     $c_acctbal:=$locn.c_acctbal, $c_phone:=$locn.c_phone,
     $n_name:=$locn.n_name, $c_address:=$locn.c_address, $c_comment:=$locn.c_comment
-    with $locn
+    keeping $locn
 with $revenue := sum(from $i in $locn select $i.l_extendedprice * (1 - $i.l_discount))
 order by $revenue desc
 limit 20
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.aql
index 61a7f77..b484cfa 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q10_returned_item_int64/q10_returned_item_int64.3.query.aql
@@ -37,7 +37,7 @@
     $c_name:=$locn.c_name,
     $c_acctbal:=$locn.c_acctbal, $c_phone:=$locn.c_phone,
     $n_name:=$locn.n_name, $c_address:=$locn.c_address, $c_comment:=$locn.c_comment
-    with $locn
+    keeping $locn
 with $revenue := sum(from $i in $locn select $i.l_extendedprice * (1 - $i.l_discount))
 order by $revenue desc
 limit 20
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.aql
index ce7ce39..bc816d3 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q13_customer_distribution/q13_customer_distribution.3.query.aql
@@ -19,7 +19,7 @@
     "c_count": sum(from $i in $co select $i.o_orderkey_count)
   }
 )
-group by $c_count := $gco.c_count with $gco
+group by $c_count := $gco.c_count keeping $gco
 with $custdist := count($gco)
 order by $custdist desc, $c_count desc
 select {
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.aql
index 5c480db..e06b207 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q14_promotion_effect/q14_promotion_effect.3.query.aql
@@ -5,7 +5,7 @@
 where $l.l_partkey = $p.p_partkey
   and $l.l_shipdate >= '1995-09-01'
   and $l.l_shipdate < '1995-10-01'
-group by $t:=1 with $l, $p
+group by $t:=1 keeping $l, $p
 select 100.00 * sum(
   from $i in $l
   select switch-case(like($i.p_type, 'PROMO%'),
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.aql
index 5abc5a4..051ac58 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.aql
@@ -29,7 +29,7 @@
     or $t.p_size = 45 or $t.p_size = 19 or $t.p_size = 3
     or $t.p_size = 36 or $t.p_size = 9
   group by $p_brand1:= $t.p_brand, $p_type1 := $t.p_type,
-    $p_size1:= $t.p_size, $ps_suppkey1:=$t.ps_suppkey with $t
+    $p_size1:= $t.p_size, $ps_suppkey1:=$t.ps_suppkey keeping $t
   select {
     "p_brand": $p_brand1,
     "p_type": $p_type1,
@@ -37,7 +37,7 @@
     "ps_suppkey": $ps_suppkey1
   }
 )
-group by $p_brand := $t2.p_brand, $p_type := $t2.p_type, $p_size := $t2.p_size with $t2
+group by $p_brand := $t2.p_brand, $p_type := $t2.p_type, $p_size := $t2.p_size keeping $t2
 with $supplier_cnt := count(from $i in $t2 select $i.ps_suppkey)
 order by $supplier_cnt desc, $p_brand, $p_type, $p_size
 select {
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.aql
index e2fed0c..4c88633 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_large_gby_variant/q17_large_gby_variant.3.query.aql
@@ -1,7 +1,7 @@
 use dataverse tpch;
 
 from $l in dataset('LineItem')
-group by $l_partkey := $l.l_partkey with $l
+group by $l_partkey := $l.l_partkey keeping $l
 order by $l_partkey
 select {
     "t_partkey": $l_partkey,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.aql
index 0b811aa..e82b0be 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.aql
@@ -2,7 +2,7 @@
 
 declare function tmp(){
   from $l in dataset('LineItem')
-  group by $l_partkey := $l.l_partkey with $l
+  group by $l_partkey := $l.l_partkey keeping $l
   select {
     "t_partkey": $l_partkey,
     "t_avg_quantity": 0.2 * avg(from $i in $l select $i.l_quantity)
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.aql
index 69366f5..5e2b80a 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q18_large_volume_customer/q18_large_volume_customer.3.query.aql
@@ -5,7 +5,7 @@
 where $c.c_custkey = $o.o_custkey
 from $t in (
   from $l in dataset('LineItem')
-  group by $l_orderkey := $l.l_orderkey with $l
+  group by $l_orderkey := $l.l_orderkey keeping $l
   select {
     "l_orderkey": $l_orderkey,
     "t_sum_quantity": sum(from $i in $l select $i.l_quantity)
@@ -15,7 +15,7 @@
 from $l in dataset('LineItem')
 where $l.l_orderkey = $o.o_orderkey
 group by $c_name := $c.c_name, $c_custkey := $c.c_custkey, $o_orderkey := $o.o_orderkey,
-         $o_orderdate := $o.o_orderdate, $o_totalprice := $o.o_totalprice with $l
+         $o_orderdate := $o.o_orderdate, $o_totalprice := $o.o_totalprice keeping $l
 order by $o_totalprice desc, $o_orderdate
 limit 100
 select {
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.aql
index ec7d889..c75c314 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q20_potential_part_promotion/q20_potential_part_promotion.3.query.aql
@@ -3,7 +3,7 @@
 from $t3 in (
   from $t2 in (
     from $l in dataset('LineItem')
-    group by $l_partkey:=$l.l_partkey, $l_suppkey:=$l.l_suppkey with $l
+    group by $l_partkey:=$l.l_partkey, $l_suppkey:=$l.l_suppkey keeping $l
     select {
       "l_partkey": $l_partkey,
       "l_suppkey": $l_suppkey,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.aql
index e23fcc4..ff3f59a 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.aql
@@ -3,13 +3,13 @@
 declare function tmp1() {
   from $l2 in (
     from $l in dataset('LineItem')
-    group by $l_orderkey1 := $l.l_orderkey, $l_suppkey1 := $l.l_suppkey with $l
+    group by $l_orderkey1 := $l.l_orderkey, $l_suppkey1 := $l.l_suppkey keeping $l
     select {
       "l_orderkey": $l_orderkey1,
       "l_suppkey": $l_suppkey1
     }
   )
-  group by $l_orderkey := $l2.l_orderkey with $l2
+  group by $l_orderkey := $l2.l_orderkey keeping $l2
   select {
     "l_orderkey": $l_orderkey,
     "count_suppkey": count(from $i in $l2 select $i.l_suppkey),
@@ -67,7 +67,7 @@
     "max_suppkey": $t2.max_suppkey
   }
 )
-group by $s_name := $t4.s_name with $t4
+group by $s_name := $t4.s_name keeping $t4
 with $numwait := count($t4)
 order by $numwait desc, $s_name
 select {
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.aql
index ca7714b..71cf1da 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.aql
@@ -14,9 +14,10 @@
   where $c.c_acctbal > 0.00
   select $c.c_acctbal
 )
+
 from $ct in q22_customer_tmp()
 where $ct.c_acctbal > $avg
-group by $cntrycode := $ct.cntrycode with $ct
+group by $cntrycode := $ct.cntrycode keeping $ct
 order by $cntrycode
 select {
   "cntrycode": $cntrycode,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue601/query-issue601.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue601/query-issue601.3.query.aql
index 51695fc..e0792a7 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue601/query-issue601.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue601/query-issue601.3.query.aql
@@ -8,7 +8,7 @@
 use dataverse tpch;
 
 from $l in dataset('LineItem')
-group by $l_linenumber := $l.l_linenumber with $l
+group by $l_linenumber := $l.l_linenumber keeping $l
 select {
   "l_linenumber": $l_linenumber,
   "count_order": count($l)
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue638/query-issue638.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue638/query-issue638.3.query.aql
index 6482dc6..396e919 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue638/query-issue638.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue638/query-issue638.3.query.aql
@@ -65,7 +65,7 @@
     "amount": $amount
   }
 )
-group by $nation := $profit.nation, $o_year := $profit.o_year with $profit
+group by $nation := $profit.nation, $o_year := $profit.o_year keeping $profit
 order by $nation, $o_year desc
 select {
   "nation": $nation,
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.aql
index f45545f..435d6cd 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785-2/query-issue785-2.3.query.aql
@@ -21,7 +21,7 @@
 from $order in dataset Orders
 where $order.o_custkey = $customer.c_custkey
 and  $customer.c_nationkey = $n.n_nationkey
-group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey with $order
+group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey keeping $order
 with $sum := sum(from $o in $order select $o.o_totalprice)
 select {
     "nation_key": $nation_key,
@@ -30,7 +30,7 @@
 })
 
 from $x in $X
-group by $nation_key := $x.nation_key with $x
+group by $nation_key := $x.nation_key keeping $x
 select {
     "nation_key": $nation_key,
     "sum_price": from $y in $x
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785/query-issue785.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785/query-issue785.3.query.aql
index baf3e73..8961b6a 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785/query-issue785.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue785/query-issue785.3.query.aql
@@ -13,18 +13,18 @@
   from $order in dataset Orders
   where $order.o_custkey = $customer.c_custkey
   and  $customer.c_nationkey = $n.n_nationkey
-  group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey with $order
+  group by $orderdate := $order.o_orderdate, $nation_key := $n.n_nationkey keeping $order
   select {
     "nation_key": $nation_key,
     "order_date": $orderdate,
     "sum_price": sum(from $o in $order select $o.o_totalprice)
   }
 )
-group by $nation_key := $x.nation_key with $x
+group by $nation_key := $x.nation_key keeping $x
 select {
      "nation_key": $nation_key,
      "sum_price": from $i in $x
-                  group by $od := $i.order_date with $i
+                  group by $od := $i.order_date keeping $i
                   with $sum := sum(from $s in $i select $s.sum_price)
                   order by $sum desc
                   limit 3
diff --git a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue786/query-issue786.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue786/query-issue786.3.query.aql
index cea218b..3773272 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue786/query-issue786.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tpch-sql-like/query-issue786/query-issue786.3.query.aql
@@ -17,7 +17,7 @@
                 from $customer in dataset Customer
                 where $order.o_custkey = $customer.c_custkey
                 and  $customer.c_nationkey = $nation.n_nationkey
-                group by $orderdate := $order.o_orderdate with $order
+                group by $orderdate := $order.o_orderdate keeping $order
                 with $sum := sum(from $o in $order select $o.o_totalprice)
                 order by $sum desc
                 limit 3