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/07/01 19:41:12 UTC

[04/11] asterixdb git commit: Support implicit variable name and column name.

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.adm
new file mode 100644
index 0000000..453d5e2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.adm
@@ -0,0 +1,100 @@
+{ "c_name": "Customer#000000070", "c_custkey": 70, "o_orderkey": 2567, "o_orderdate": "1998-02-27", "o_totalprice": 263411.29d, "sum_quantity": 266 }
+{ "c_name": "Customer#000000010", "c_custkey": 10, "o_orderkey": 4421, "o_orderdate": "1997-04-04", "o_totalprice": 258779.02d, "sum_quantity": 255 }
+{ "c_name": "Customer#000000052", "c_custkey": 52, "o_orderkey": 5765, "o_orderdate": "1994-12-15", "o_totalprice": 249900.42d, "sum_quantity": 247 }
+{ "c_name": "Customer#000000082", "c_custkey": 82, "o_orderkey": 3460, "o_orderdate": "1995-10-03", "o_totalprice": 245976.74d, "sum_quantity": 254 }
+{ "c_name": "Customer#000000068", "c_custkey": 68, "o_orderkey": 2208, "o_orderdate": "1995-05-01", "o_totalprice": 245388.06d, "sum_quantity": 256 }
+{ "c_name": "Customer#000000028", "c_custkey": 28, "o_orderkey": 2306, "o_orderdate": "1995-07-26", "o_totalprice": 244704.23d, "sum_quantity": 235 }
+{ "c_name": "Customer#000000146", "c_custkey": 146, "o_orderkey": 5925, "o_orderdate": "1995-11-13", "o_totalprice": 242588.87d, "sum_quantity": 242 }
+{ "c_name": "Customer#000000029", "c_custkey": 29, "o_orderkey": 1121, "o_orderdate": "1997-01-13", "o_totalprice": 241837.88d, "sum_quantity": 242 }
+{ "c_name": "Customer#000000067", "c_custkey": 67, "o_orderkey": 3907, "o_orderdate": "1992-08-19", "o_totalprice": 240457.56d, "sum_quantity": 239 }
+{ "c_name": "Customer#000000076", "c_custkey": 76, "o_orderkey": 5158, "o_orderdate": "1997-01-21", "o_totalprice": 240284.95d, "sum_quantity": 248 }
+{ "c_name": "Customer#000000131", "c_custkey": 131, "o_orderkey": 4484, "o_orderdate": "1996-12-24", "o_totalprice": 237947.61d, "sum_quantity": 243 }
+{ "c_name": "Customer#000000115", "c_custkey": 115, "o_orderkey": 645, "o_orderdate": "1994-12-03", "o_totalprice": 234763.73d, "sum_quantity": 245 }
+{ "c_name": "Customer#000000049", "c_custkey": 49, "o_orderkey": 4294, "o_orderdate": "1992-08-15", "o_totalprice": 232194.74d, "sum_quantity": 225 }
+{ "c_name": "Customer#000000076", "c_custkey": 76, "o_orderkey": 1477, "o_orderdate": "1997-08-24", "o_totalprice": 231831.35d, "sum_quantity": 236 }
+{ "c_name": "Customer#000000044", "c_custkey": 44, "o_orderkey": 4645, "o_orderdate": "1994-09-20", "o_totalprice": 231012.22d, "sum_quantity": 248 }
+{ "c_name": "Customer#000000089", "c_custkey": 89, "o_orderkey": 5957, "o_orderdate": "1993-12-27", "o_totalprice": 230949.45d, "sum_quantity": 242 }
+{ "c_name": "Customer#000000076", "c_custkey": 76, "o_orderkey": 326, "o_orderdate": "1995-06-04", "o_totalprice": 229165.17d, "sum_quantity": 228 }
+{ "c_name": "Customer#000000067", "c_custkey": 67, "o_orderkey": 928, "o_orderdate": "1995-03-02", "o_totalprice": 228136.49d, "sum_quantity": 241 }
+{ "c_name": "Customer#000000079", "c_custkey": 79, "o_orderkey": 3808, "o_orderdate": "1994-04-24", "o_totalprice": 228054.01d, "sum_quantity": 227 }
+{ "c_name": "Customer#000000037", "c_custkey": 37, "o_orderkey": 5317, "o_orderdate": "1994-09-09", "o_totalprice": 228002.51d, "sum_quantity": 231 }
+{ "c_name": "Customer#000000004", "c_custkey": 4, "o_orderkey": 358, "o_orderdate": "1993-09-20", "o_totalprice": 226806.66d, "sum_quantity": 223 }
+{ "c_name": "Customer#000000142", "c_custkey": 142, "o_orderkey": 5699, "o_orderdate": "1992-07-30", "o_totalprice": 226314.91d, "sum_quantity": 240 }
+{ "c_name": "Customer#000000121", "c_custkey": 121, "o_orderkey": 1888, "o_orderdate": "1993-10-31", "o_totalprice": 224724.11d, "sum_quantity": 225 }
+{ "c_name": "Customer#000000094", "c_custkey": 94, "o_orderkey": 2690, "o_orderdate": "1996-03-31", "o_totalprice": 224674.27d, "sum_quantity": 219 }
+{ "c_name": "Customer#000000094", "c_custkey": 94, "o_orderkey": 5413, "o_orderdate": "1997-10-17", "o_totalprice": 224382.57d, "sum_quantity": 212 }
+{ "c_name": "Customer#000000032", "c_custkey": 32, "o_orderkey": 5381, "o_orderdate": "1993-01-29", "o_totalprice": 223995.46d, "sum_quantity": 228 }
+{ "c_name": "Customer#000000145", "c_custkey": 145, "o_orderkey": 518, "o_orderdate": "1998-02-08", "o_totalprice": 223537.09d, "sum_quantity": 214 }
+{ "c_name": "Customer#000000029", "c_custkey": 29, "o_orderkey": 2945, "o_orderdate": "1996-01-03", "o_totalprice": 223507.72d, "sum_quantity": 231 }
+{ "c_name": "Customer#000000007", "c_custkey": 7, "o_orderkey": 3654, "o_orderdate": "1992-06-03", "o_totalprice": 222653.54d, "sum_quantity": 222 }
+{ "c_name": "Customer#000000145", "c_custkey": 145, "o_orderkey": 807, "o_orderdate": "1993-11-24", "o_totalprice": 222392.53d, "sum_quantity": 216 }
+{ "c_name": "Customer#000000149", "c_custkey": 149, "o_orderkey": 3619, "o_orderdate": "1996-11-20", "o_totalprice": 222274.54d, "sum_quantity": 221 }
+{ "c_name": "Customer#000000070", "c_custkey": 70, "o_orderkey": 5472, "o_orderdate": "1993-04-11", "o_totalprice": 221636.83d, "sum_quantity": 217 }
+{ "c_name": "Customer#000000137", "c_custkey": 137, "o_orderkey": 4900, "o_orderdate": "1992-06-30", "o_totalprice": 221320.76d, "sum_quantity": 227 }
+{ "c_name": "Customer#000000106", "c_custkey": 106, "o_orderkey": 3778, "o_orderdate": "1993-05-26", "o_totalprice": 221036.31d, "sum_quantity": 225 }
+{ "c_name": "Customer#000000121", "c_custkey": 121, "o_orderkey": 1153, "o_orderdate": "1996-04-18", "o_totalprice": 220727.97d, "sum_quantity": 209 }
+{ "c_name": "Customer#000000070", "c_custkey": 70, "o_orderkey": 4004, "o_orderdate": "1993-05-07", "o_totalprice": 220715.14d, "sum_quantity": 228 }
+{ "c_name": "Customer#000000098", "c_custkey": 98, "o_orderkey": 768, "o_orderdate": "1996-08-20", "o_totalprice": 220636.82d, "sum_quantity": 231 }
+{ "c_name": "Customer#000000149", "c_custkey": 149, "o_orderkey": 5606, "o_orderdate": "1996-11-12", "o_totalprice": 219959.08d, "sum_quantity": 231 }
+{ "c_name": "Customer#000000055", "c_custkey": 55, "o_orderkey": 484, "o_orderdate": "1997-01-03", "o_totalprice": 219920.62d, "sum_quantity": 224 }
+{ "c_name": "Customer#000000140", "c_custkey": 140, "o_orderkey": 4230, "o_orderdate": "1992-03-04", "o_totalprice": 219709.6d, "sum_quantity": 217 }
+{ "c_name": "Customer#000000082", "c_custkey": 82, "o_orderkey": 39, "o_orderdate": "1996-09-20", "o_totalprice": 219707.84d, "sum_quantity": 231 }
+{ "c_name": "Customer#000000037", "c_custkey": 37, "o_orderkey": 2789, "o_orderdate": "1998-03-14", "o_totalprice": 219123.27d, "sum_quantity": 218 }
+{ "c_name": "Customer#000000017", "c_custkey": 17, "o_orderkey": 3269, "o_orderdate": "1996-03-01", "o_totalprice": 218697.85d, "sum_quantity": 220 }
+{ "c_name": "Customer#000000149", "c_custkey": 149, "o_orderkey": 3590, "o_orderdate": "1995-05-13", "o_totalprice": 218482.7d, "sum_quantity": 210 }
+{ "c_name": "Customer#000000134", "c_custkey": 134, "o_orderkey": 614, "o_orderdate": "1992-12-01", "o_totalprice": 218116.21d, "sum_quantity": 204 }
+{ "c_name": "Customer#000000092", "c_custkey": 92, "o_orderkey": 4197, "o_orderdate": "1996-08-13", "o_totalprice": 217709.03d, "sum_quantity": 225 }
+{ "c_name": "Customer#000000133", "c_custkey": 133, "o_orderkey": 1156, "o_orderdate": "1996-10-19", "o_totalprice": 217682.81d, "sum_quantity": 218 }
+{ "c_name": "Customer#000000046", "c_custkey": 46, "o_orderkey": 453, "o_orderdate": "1997-05-26", "o_totalprice": 216826.73d, "sum_quantity": 226 }
+{ "c_name": "Customer#000000124", "c_custkey": 124, "o_orderkey": 3109, "o_orderdate": "1993-07-24", "o_totalprice": 216104.85d, "sum_quantity": 210 }
+{ "c_name": "Customer#000000043", "c_custkey": 43, "o_orderkey": 4994, "o_orderdate": "1996-06-29", "o_totalprice": 216071.76d, "sum_quantity": 213 }
+{ "c_name": "Customer#000000149", "c_custkey": 149, "o_orderkey": 3713, "o_orderdate": "1998-05-07", "o_totalprice": 215342.63d, "sum_quantity": 213 }
+{ "c_name": "Customer#000000029", "c_custkey": 29, "o_orderkey": 68, "o_orderdate": "1998-04-18", "o_totalprice": 215135.72d, "sum_quantity": 213 }
+{ "c_name": "Customer#000000013", "c_custkey": 13, "o_orderkey": 2438, "o_orderdate": "1993-07-15", "o_totalprice": 214494.39d, "sum_quantity": 210 }
+{ "c_name": "Customer#000000133", "c_custkey": 133, "o_orderkey": 4613, "o_orderdate": "1998-03-05", "o_totalprice": 212339.55d, "sum_quantity": 214 }
+{ "c_name": "Customer#000000106", "c_custkey": 106, "o_orderkey": 1761, "o_orderdate": "1993-12-24", "o_totalprice": 211925.95d, "sum_quantity": 218 }
+{ "c_name": "Customer#000000049", "c_custkey": 49, "o_orderkey": 1248, "o_orderdate": "1992-01-02", "o_totalprice": 210713.88d, "sum_quantity": 207 }
+{ "c_name": "Customer#000000005", "c_custkey": 5, "o_orderkey": 5859, "o_orderdate": "1997-04-23", "o_totalprice": 210643.96d, "sum_quantity": 211 }
+{ "c_name": "Customer#000000106", "c_custkey": 106, "o_orderkey": 1827, "o_orderdate": "1996-06-22", "o_totalprice": 210113.88d, "sum_quantity": 205 }
+{ "c_name": "Customer#000000085", "c_custkey": 85, "o_orderkey": 5184, "o_orderdate": "1998-07-20", "o_totalprice": 209155.48d, "sum_quantity": 213 }
+{ "c_name": "Customer#000000133", "c_custkey": 133, "o_orderkey": 710, "o_orderdate": "1993-01-02", "o_totalprice": 208974.42d, "sum_quantity": 196 }
+{ "c_name": "Customer#000000052", "c_custkey": 52, "o_orderkey": 5186, "o_orderdate": "1996-08-03", "o_totalprice": 208892.63d, "sum_quantity": 210 }
+{ "c_name": "Customer#000000028", "c_custkey": 28, "o_orderkey": 2050, "o_orderdate": "1994-06-02", "o_totalprice": 208517.98d, "sum_quantity": 217 }
+{ "c_name": "Customer#000000076", "c_custkey": 76, "o_orderkey": 2180, "o_orderdate": "1996-09-14", "o_totalprice": 208481.57d, "sum_quantity": 212 }
+{ "c_name": "Customer#000000119", "c_custkey": 119, "o_orderkey": 3588, "o_orderdate": "1995-03-19", "o_totalprice": 207925.83d, "sum_quantity": 212 }
+{ "c_name": "Customer#000000134", "c_custkey": 134, "o_orderkey": 1444, "o_orderdate": "1994-12-06", "o_totalprice": 207907.6d, "sum_quantity": 205 }
+{ "c_name": "Customer#000000103", "c_custkey": 103, "o_orderkey": 742, "o_orderdate": "1994-12-23", "o_totalprice": 207632.55d, "sum_quantity": 198 }
+{ "c_name": "Customer#000000017", "c_custkey": 17, "o_orderkey": 4099, "o_orderdate": "1992-08-21", "o_totalprice": 207364.8d, "sum_quantity": 208 }
+{ "c_name": "Customer#000000109", "c_custkey": 109, "o_orderkey": 1286, "o_orderdate": "1993-05-14", "o_totalprice": 207291.83d, "sum_quantity": 200 }
+{ "c_name": "Customer#000000079", "c_custkey": 79, "o_orderkey": 5633, "o_orderdate": "1998-05-31", "o_totalprice": 207119.83d, "sum_quantity": 203 }
+{ "c_name": "Customer#000000062", "c_custkey": 62, "o_orderkey": 2022, "o_orderdate": "1992-03-15", "o_totalprice": 206742.11d, "sum_quantity": 209 }
+{ "c_name": "Customer#000000022", "c_custkey": 22, "o_orderkey": 4583, "o_orderdate": "1994-09-25", "o_totalprice": 206495.43d, "sum_quantity": 197 }
+{ "c_name": "Customer#000000148", "c_custkey": 148, "o_orderkey": 5185, "o_orderdate": "1997-07-25", "o_totalprice": 206179.68d, "sum_quantity": 198 }
+{ "c_name": "Customer#000000044", "c_custkey": 44, "o_orderkey": 3175, "o_orderdate": "1994-07-15", "o_totalprice": 205282.63d, "sum_quantity": 215 }
+{ "c_name": "Customer#000000056", "c_custkey": 56, "o_orderkey": 2565, "o_orderdate": "1998-02-28", "o_totalprice": 204438.57d, "sum_quantity": 201 }
+{ "c_name": "Customer#000000149", "c_custkey": 149, "o_orderkey": 3747, "o_orderdate": "1996-08-20", "o_totalprice": 204355.65d, "sum_quantity": 195 }
+{ "c_name": "Customer#000000101", "c_custkey": 101, "o_orderkey": 4964, "o_orderdate": "1997-07-28", "o_totalprice": 204163.1d, "sum_quantity": 197 }
+{ "c_name": "Customer#000000062", "c_custkey": 62, "o_orderkey": 4992, "o_orderdate": "1992-05-10", "o_totalprice": 203904.8d, "sum_quantity": 198 }
+{ "c_name": "Customer#000000010", "c_custkey": 10, "o_orderkey": 3751, "o_orderdate": "1994-04-27", "o_totalprice": 202917.72d, "sum_quantity": 204 }
+{ "c_name": "Customer#000000076", "c_custkey": 76, "o_orderkey": 2534, "o_orderdate": "1996-07-17", "o_totalprice": 202784.54d, "sum_quantity": 214 }
+{ "c_name": "Customer#000000001", "c_custkey": 1, "o_orderkey": 164, "o_orderdate": "1992-10-21", "o_totalprice": 202660.52d, "sum_quantity": 213 }
+{ "c_name": "Customer#000000118", "c_custkey": 118, "o_orderkey": 1283, "o_orderdate": "1996-08-30", "o_totalprice": 202623.92d, "sum_quantity": 200 }
+{ "c_name": "Customer#000000010", "c_custkey": 10, "o_orderkey": 1890, "o_orderdate": "1996-12-18", "o_totalprice": 202364.58d, "sum_quantity": 207 }
+{ "c_name": "Customer#000000077", "c_custkey": 77, "o_orderkey": 1762, "o_orderdate": "1994-08-20", "o_totalprice": 202227.17d, "sum_quantity": 216 }
+{ "c_name": "Customer#000000106", "c_custkey": 106, "o_orderkey": 4196, "o_orderdate": "1998-05-15", "o_totalprice": 201455.98d, "sum_quantity": 198 }
+{ "c_name": "Customer#000000064", "c_custkey": 64, "o_orderkey": 5895, "o_orderdate": "1997-01-01", "o_totalprice": 201419.83d, "sum_quantity": 200 }
+{ "c_name": "Customer#000000008", "c_custkey": 8, "o_orderkey": 644, "o_orderdate": "1992-05-01", "o_totalprice": 201268.06d, "sum_quantity": 202 }
+{ "c_name": "Customer#000000047", "c_custkey": 47, "o_orderkey": 261, "o_orderdate": "1993-06-29", "o_totalprice": 201003.12d, "sum_quantity": 200 }
+{ "c_name": "Customer#000000079", "c_custkey": 79, "o_orderkey": 4672, "o_orderdate": "1995-11-07", "o_totalprice": 199593.71d, "sum_quantity": 203 }
+{ "c_name": "Customer#000000131", "c_custkey": 131, "o_orderkey": 930, "o_orderdate": "1994-12-17", "o_totalprice": 199102.23d, "sum_quantity": 204 }
+{ "c_name": "Customer#000000118", "c_custkey": 118, "o_orderkey": 4161, "o_orderdate": "1993-08-21", "o_totalprice": 198995.21d, "sum_quantity": 211 }
+{ "c_name": "Customer#000000073", "c_custkey": 73, "o_orderkey": 4069, "o_orderdate": "1992-05-13", "o_totalprice": 198816.13d, "sum_quantity": 199 }
+{ "c_name": "Customer#000000142", "c_custkey": 142, "o_orderkey": 5696, "o_orderdate": "1995-05-04", "o_totalprice": 198723.3d, "sum_quantity": 198 }
+{ "c_name": "Customer#000000134", "c_custkey": 134, "o_orderkey": 3872, "o_orderdate": "1996-09-06", "o_totalprice": 198538.68d, "sum_quantity": 207 }
+{ "c_name": "Customer#000000127", "c_custkey": 127, "o_orderkey": 1059, "o_orderdate": "1994-02-27", "o_totalprice": 198360.22d, "sum_quantity": 194 }
+{ "c_name": "Customer#000000103", "c_custkey": 103, "o_orderkey": 4293, "o_orderdate": "1996-08-20", "o_totalprice": 198322.91d, "sum_quantity": 202 }
+{ "c_name": "Customer#000000080", "c_custkey": 80, "o_orderkey": 993, "o_orderdate": "1995-09-10", "o_totalprice": 198238.65d, "sum_quantity": 194 }
+{ "c_name": "Customer#000000091", "c_custkey": 91, "o_orderkey": 420, "o_orderdate": "1995-10-31", "o_totalprice": 198039.23d, "sum_quantity": 200 }
+{ "c_name": "Customer#000000092", "c_custkey": 92, "o_orderkey": 3333, "o_orderdate": "1992-09-16", "o_totalprice": 197973.22d, "sum_quantity": 195 }
+{ "c_name": "Customer#000000146", "c_custkey": 146, "o_orderkey": 4192, "o_orderdate": "1998-04-19", "o_totalprice": 197192.95d, "sum_quantity": 209 }
+{ "c_name": "Customer#000000145", "c_custkey": 145, "o_orderkey": 1575, "o_orderdate": "1995-09-13", "o_totalprice": 197031.52d, "sum_quantity": 204 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.adm
new file mode 100644
index 0000000..aea671f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.adm
@@ -0,0 +1 @@
+51515.7344d

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.adm
new file mode 100644
index 0000000..424ab59
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.adm
@@ -0,0 +1,10 @@
+{ "s_name": "Supplier#000000001", "s_address": " N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ" }
+{ "s_name": "Supplier#000000002", "s_address": "89eJ5ksX3ImxJQBvxObC," }
+{ "s_name": "Supplier#000000003", "s_address": "q1,G3Pj6OjIuUYfUoH18BFTKP5aU9bEV3" }
+{ "s_name": "Supplier#000000004", "s_address": "Bk7ah4CK8SYQTepEmvMkkgMwg" }
+{ "s_name": "Supplier#000000005", "s_address": "Gcdm2rJRzl5qlTVzc" }
+{ "s_name": "Supplier#000000006", "s_address": "tQxuVm7s7CnK" }
+{ "s_name": "Supplier#000000007", "s_address": "s,4TicNGB4uO6PaSqNBUq" }
+{ "s_name": "Supplier#000000008", "s_address": "9Sq4bBH2FQEmaFOocY45sRTxo6yuoG" }
+{ "s_name": "Supplier#000000009", "s_address": "1KhUgZegwM3ua7dsYmekYBsK" }
+{ "s_name": "Supplier#000000010", "s_address": "Saygah3gYWMp72i PY" }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.adm
new file mode 100644
index 0000000..2ae0988
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.adm
@@ -0,0 +1,10 @@
+{ "s_name": "Supplier#000000007", "numwait": 431 }
+{ "s_name": "Supplier#000000005", "numwait": 417 }
+{ "s_name": "Supplier#000000001", "numwait": 403 }
+{ "s_name": "Supplier#000000009", "numwait": 373 }
+{ "s_name": "Supplier#000000004", "numwait": 367 }
+{ "s_name": "Supplier#000000002", "numwait": 364 }
+{ "s_name": "Supplier#000000010", "numwait": 358 }
+{ "s_name": "Supplier#000000003", "numwait": 349 }
+{ "s_name": "Supplier#000000008", "numwait": 347 }
+{ "s_name": "Supplier#000000006", "numwait": 343 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.adm
new file mode 100644
index 0000000..4f3cd97
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.adm
@@ -0,0 +1,23 @@
+{ "cntrycode": "10", "numcust": 3, "totacctbal": 20747.13d }
+{ "cntrycode": "11", "numcust": 5, "totacctbal": 35208.88d }
+{ "cntrycode": "12", "numcust": 2, "totacctbal": 13735.27d }
+{ "cntrycode": "13", "numcust": 2, "totacctbal": 13545.3d }
+{ "cntrycode": "14", "numcust": 1, "totacctbal": 9963.15d }
+{ "cntrycode": "15", "numcust": 2, "totacctbal": 14624.84d }
+{ "cntrycode": "16", "numcust": 2, "totacctbal": 11239.02d }
+{ "cntrycode": "17", "numcust": 1, "totacctbal": 9127.27d }
+{ "cntrycode": "18", "numcust": 3, "totacctbal": 22156.91d }
+{ "cntrycode": "19", "numcust": 6, "totacctbal": 43758.41d }
+{ "cntrycode": "20", "numcust": 3, "totacctbal": 23085.67d }
+{ "cntrycode": "21", "numcust": 3, "totacctbal": 19400.52d }
+{ "cntrycode": "22", "numcust": 3, "totacctbal": 20332.18d }
+{ "cntrycode": "23", "numcust": 3, "totacctbal": 25483.06d }
+{ "cntrycode": "25", "numcust": 3, "totacctbal": 19038.36d }
+{ "cntrycode": "26", "numcust": 5, "totacctbal": 38943.9d }
+{ "cntrycode": "27", "numcust": 2, "totacctbal": 13248.06d }
+{ "cntrycode": "28", "numcust": 5, "totacctbal": 42700.5d }
+{ "cntrycode": "29", "numcust": 4, "totacctbal": 36059.01d }
+{ "cntrycode": "30", "numcust": 2, "totacctbal": 17528.46d }
+{ "cntrycode": "31", "numcust": 3, "totacctbal": 23599.109999999997d }
+{ "cntrycode": "32", "numcust": 4, "totacctbal": 25754.22d }
+{ "cntrycode": "33", "numcust": 3, "totacctbal": 20359.59d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue562/query-issue562.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue562/query-issue562.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue562/query-issue562.1.adm
new file mode 100644
index 0000000..aa7bb6b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue562/query-issue562.1.adm
@@ -0,0 +1,7 @@
+{ "cntrycode": "13", "numcust": 1, "totacctbal": 5679.84d }
+{ "cntrycode": "17", "numcust": 2, "totacctbal": 11309.79d }
+{ "cntrycode": "18", "numcust": 3, "totacctbal": 16076.24d }
+{ "cntrycode": "23", "numcust": 2, "totacctbal": 12652.16d }
+{ "cntrycode": "29", "numcust": 2, "totacctbal": 17195.08d }
+{ "cntrycode": "30", "numcust": 2, "totacctbal": 9662.279999999999d }
+{ "cntrycode": "31", "numcust": 3, "totacctbal": 18470.33d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue601/query-issue601.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue601/query-issue601.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue601/query-issue601.1.adm
new file mode 100644
index 0000000..7d83268
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue601/query-issue601.1.adm
@@ -0,0 +1,7 @@
+{ "l_linenumber": 6, "count_order": 432 }
+{ "l_linenumber": 1, "count_order": 1500 }
+{ "l_linenumber": 2, "count_order": 1291 }
+{ "l_linenumber": 4, "count_order": 862 }
+{ "l_linenumber": 3, "count_order": 1077 }
+{ "l_linenumber": 5, "count_order": 632 }
+{ "l_linenumber": 7, "count_order": 211 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue638/query-issue638.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue638/query-issue638.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue638/query-issue638.1.adm
new file mode 100644
index 0000000..e9f3f47
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue638/query-issue638.1.adm
@@ -0,0 +1,59 @@
+{ "nation": "ARGENTINA", "o_year": 1997, "sum_profit": 18247.873399999993d }
+{ "nation": "ARGENTINA", "o_year": 1996, "sum_profit": 7731.089399999995d }
+{ "nation": "ARGENTINA", "o_year": 1995, "sum_profit": 134490.5697d }
+{ "nation": "ARGENTINA", "o_year": 1994, "sum_profit": 36767.101500000004d }
+{ "nation": "ARGENTINA", "o_year": 1993, "sum_profit": 35857.08d }
+{ "nation": "ARGENTINA", "o_year": 1992, "sum_profit": 35740.0d }
+{ "nation": "ETHIOPIA", "o_year": 1998, "sum_profit": 2758.7801999999992d }
+{ "nation": "ETHIOPIA", "o_year": 1997, "sum_profit": 19419.294599999994d }
+{ "nation": "ETHIOPIA", "o_year": 1995, "sum_profit": 51231.87439999999d }
+{ "nation": "ETHIOPIA", "o_year": 1994, "sum_profit": 3578.9478999999974d }
+{ "nation": "ETHIOPIA", "o_year": 1992, "sum_profit": 1525.8234999999986d }
+{ "nation": "IRAN", "o_year": 1998, "sum_profit": 37817.229600000006d }
+{ "nation": "IRAN", "o_year": 1997, "sum_profit": 52643.77359999999d }
+{ "nation": "IRAN", "o_year": 1996, "sum_profit": 70143.77609999999d }
+{ "nation": "IRAN", "o_year": 1995, "sum_profit": 84094.58260000001d }
+{ "nation": "IRAN", "o_year": 1994, "sum_profit": 18140.925599999995d }
+{ "nation": "IRAN", "o_year": 1993, "sum_profit": 78655.1676d }
+{ "nation": "IRAN", "o_year": 1992, "sum_profit": 87142.2396d }
+{ "nation": "IRAQ", "o_year": 1998, "sum_profit": 22860.8082d }
+{ "nation": "IRAQ", "o_year": 1997, "sum_profit": 93676.24359999999d }
+{ "nation": "IRAQ", "o_year": 1996, "sum_profit": 45103.3242d }
+{ "nation": "IRAQ", "o_year": 1994, "sum_profit": 36010.728599999995d }
+{ "nation": "IRAQ", "o_year": 1993, "sum_profit": 33221.9399d }
+{ "nation": "IRAQ", "o_year": 1992, "sum_profit": 47755.05900000001d }
+{ "nation": "KENYA", "o_year": 1998, "sum_profit": 44194.831999999995d }
+{ "nation": "KENYA", "o_year": 1997, "sum_profit": 57578.3626d }
+{ "nation": "KENYA", "o_year": 1996, "sum_profit": 59195.9021d }
+{ "nation": "KENYA", "o_year": 1995, "sum_profit": 79262.6278d }
+{ "nation": "KENYA", "o_year": 1994, "sum_profit": 102360.66609999999d }
+{ "nation": "KENYA", "o_year": 1993, "sum_profit": 128422.01959999999d }
+{ "nation": "KENYA", "o_year": 1992, "sum_profit": 181517.20890000003d }
+{ "nation": "MOROCCO", "o_year": 1998, "sum_profit": 41797.823199999984d }
+{ "nation": "MOROCCO", "o_year": 1997, "sum_profit": 23685.801799999997d }
+{ "nation": "MOROCCO", "o_year": 1996, "sum_profit": 62115.19579999999d }
+{ "nation": "MOROCCO", "o_year": 1995, "sum_profit": 42442.64300000001d }
+{ "nation": "MOROCCO", "o_year": 1994, "sum_profit": 48655.87800000001d }
+{ "nation": "MOROCCO", "o_year": 1993, "sum_profit": 22926.744400000003d }
+{ "nation": "MOROCCO", "o_year": 1992, "sum_profit": 32239.8088d }
+{ "nation": "PERU", "o_year": 1998, "sum_profit": 86999.36459999997d }
+{ "nation": "PERU", "o_year": 1997, "sum_profit": 121110.41070000001d }
+{ "nation": "PERU", "o_year": 1996, "sum_profit": 177040.40759999998d }
+{ "nation": "PERU", "o_year": 1995, "sum_profit": 122247.94519999999d }
+{ "nation": "PERU", "o_year": 1994, "sum_profit": 88046.2533d }
+{ "nation": "PERU", "o_year": 1993, "sum_profit": 49379.813799999996d }
+{ "nation": "PERU", "o_year": 1992, "sum_profit": 80646.86050000001d }
+{ "nation": "UNITED KINGDOM", "o_year": 1998, "sum_profit": 50577.25560000001d }
+{ "nation": "UNITED KINGDOM", "o_year": 1997, "sum_profit": 114288.86049999998d }
+{ "nation": "UNITED KINGDOM", "o_year": 1996, "sum_profit": 147684.46480000002d }
+{ "nation": "UNITED KINGDOM", "o_year": 1995, "sum_profit": 225267.6576d }
+{ "nation": "UNITED KINGDOM", "o_year": 1994, "sum_profit": 140595.58639999997d }
+{ "nation": "UNITED KINGDOM", "o_year": 1993, "sum_profit": 322548.49210000003d }
+{ "nation": "UNITED KINGDOM", "o_year": 1992, "sum_profit": 67747.88279999999d }
+{ "nation": "UNITED STATES", "o_year": 1998, "sum_profit": 3957.0431999999996d }
+{ "nation": "UNITED STATES", "o_year": 1997, "sum_profit": 94729.5704d }
+{ "nation": "UNITED STATES", "o_year": 1996, "sum_profit": 79297.8567d }
+{ "nation": "UNITED STATES", "o_year": 1995, "sum_profit": 62201.23360000001d }
+{ "nation": "UNITED STATES", "o_year": 1994, "sum_profit": 43075.62989999999d }
+{ "nation": "UNITED STATES", "o_year": 1993, "sum_profit": 27168.486199999996d }
+{ "nation": "UNITED STATES", "o_year": 1992, "sum_profit": 34092.366d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.adm
new file mode 100644
index 0000000..c6a683d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.adm
@@ -0,0 +1,10 @@
+{ "nation_key": 21, "sum_price": [ { "orderdate": "1994-02-27", "sum_price": 198360.22d }, { "orderdate": "1992-07-07", "sum_price": 180692.9d }, { "orderdate": "1996-06-28", "sum_price": 139915.23d } ] }
+{ "nation_key": 23, "sum_price": [ { "orderdate": "1993-06-08", "sum_price": 161307.05d }, { "orderdate": "1995-12-07", "sum_price": 153048.74d }, { "orderdate": "1994-08-22", "sum_price": 147071.86d } ] }
+{ "nation_key": 1, "sum_price": [ { "orderdate": "1993-05-26", "sum_price": 221036.31d }, { "orderdate": "1992-03-20", "sum_price": 216230.27000000002d }, { "orderdate": "1993-12-24", "sum_price": 211925.95d } ] }
+{ "nation_key": 2, "sum_price": [ { "orderdate": "1996-03-01", "sum_price": 218697.85d }, { "orderdate": "1996-08-13", "sum_price": 217709.03d }, { "orderdate": "1992-08-21", "sum_price": 207364.8d } ] }
+{ "nation_key": 4, "sum_price": [ { "orderdate": "1993-09-20", "sum_price": 226806.66d }, { "orderdate": "1992-03-04", "sum_price": 219709.6d }, { "orderdate": "1996-01-06", "sum_price": 190490.78d } ] }
+{ "nation_key": 19, "sum_price": [ { "orderdate": "1993-12-29", "sum_price": 328959.87d }, { "orderdate": "1997-08-04", "sum_price": 244636.7d }, { "orderdate": "1996-11-20", "sum_price": 222274.54d } ] }
+{ "nation_key": 20, "sum_price": [ { "orderdate": "1993-01-31", "sum_price": 190960.69d }, { "orderdate": "1998-07-17", "sum_price": 187156.38d }, { "orderdate": "1993-03-25", "sum_price": 167017.39d } ] }
+{ "nation_key": 22, "sum_price": [ { "orderdate": "1998-02-27", "sum_price": 263411.29d }, { "orderdate": "1993-04-11", "sum_price": 221636.83d }, { "orderdate": "1993-05-07", "sum_price": 220715.14d } ] }
+{ "nation_key": 0, "sum_price": [ { "orderdate": "1997-01-13", "sum_price": 241837.88d }, { "orderdate": "1997-01-21", "sum_price": 240284.95d }, { "orderdate": "1997-08-24", "sum_price": 231831.35d } ] }
+{ "nation_key": 3, "sum_price": [ { "orderdate": "1997-04-23", "sum_price": 351762.82999999996d }, { "orderdate": "1995-11-13", "sum_price": 242588.87d }, { "orderdate": "1993-07-15", "sum_price": 214494.39d } ] }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785/query-issue785.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785/query-issue785.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785/query-issue785.1.adm
new file mode 100644
index 0000000..216a8f6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue785/query-issue785.1.adm
@@ -0,0 +1,24 @@
+{ "nation_key": 6, "sum_price": [ { "orderdate": "1992-05-28", "sum_price": 335178.33d }, { "orderdate": "1997-05-26", "sum_price": 216826.73d }, { "orderdate": "1996-04-30", "sum_price": 180054.29d } ] }
+{ "nation_key": 11, "sum_price": [ { "orderdate": "1994-12-15", "sum_price": 249900.42d }, { "orderdate": "1996-12-24", "sum_price": 237947.61d }, { "orderdate": "1992-12-01", "sum_price": 218116.21d } ] }
+{ "nation_key": 12, "sum_price": [ { "orderdate": "1995-05-01", "sum_price": 245388.06d }, { "orderdate": "1997-02-17", "sum_price": 225518.72d }, { "orderdate": "1996-08-20", "sum_price": 220636.82d } ] }
+{ "nation_key": 14, "sum_price": [ { "orderdate": "1993-12-27", "sum_price": 230949.45d }, { "orderdate": "1992-04-26", "sum_price": 134333.33d }, { "orderdate": "1997-03-09", "sum_price": 132838.49d } ] }
+{ "nation_key": 21, "sum_price": [ { "orderdate": "1994-02-27", "sum_price": 198360.22d }, { "orderdate": "1992-07-07", "sum_price": 180692.9d }, { "orderdate": "1996-06-28", "sum_price": 139915.23d } ] }
+{ "nation_key": 23, "sum_price": [ { "orderdate": "1993-06-08", "sum_price": 161307.05d }, { "orderdate": "1995-12-07", "sum_price": 153048.74d }, { "orderdate": "1994-08-22", "sum_price": 147071.86d } ] }
+{ "nation_key": 1, "sum_price": [ { "orderdate": "1993-05-26", "sum_price": 221036.31d }, { "orderdate": "1992-03-20", "sum_price": 216230.27000000002d }, { "orderdate": "1993-12-24", "sum_price": 211925.95d } ] }
+{ "nation_key": 2, "sum_price": [ { "orderdate": "1996-03-01", "sum_price": 218697.85d }, { "orderdate": "1996-08-13", "sum_price": 217709.03d }, { "orderdate": "1992-08-21", "sum_price": 207364.8d } ] }
+{ "nation_key": 4, "sum_price": [ { "orderdate": "1993-09-20", "sum_price": 226806.66d }, { "orderdate": "1992-03-04", "sum_price": 219709.6d }, { "orderdate": "1996-01-06", "sum_price": 190490.78d } ] }
+{ "nation_key": 13, "sum_price": [ { "orderdate": "1998-02-08", "sum_price": 223537.09d }, { "orderdate": "1993-11-24", "sum_price": 222392.53d }, { "orderdate": "1995-09-13", "sum_price": 197031.52d } ] }
+{ "nation_key": 15, "sum_price": [ { "orderdate": "1998-05-31", "sum_price": 366291.52d }, { "orderdate": "1994-04-24", "sum_price": 228054.01d }, { "orderdate": "1993-01-29", "sum_price": 223995.46d } ] }
+{ "nation_key": 16, "sum_price": [ { "orderdate": "1994-09-20", "sum_price": 231012.22d }, { "orderdate": "1992-06-30", "sum_price": 221320.76d }, { "orderdate": "1993-05-14", "sum_price": 207291.83d } ] }
+{ "nation_key": 19, "sum_price": [ { "orderdate": "1993-12-29", "sum_price": 328959.87d }, { "orderdate": "1997-08-04", "sum_price": 244636.7d }, { "orderdate": "1996-11-20", "sum_price": 222274.54d } ] }
+{ "nation_key": 20, "sum_price": [ { "orderdate": "1993-01-31", "sum_price": 190960.69d }, { "orderdate": "1998-07-17", "sum_price": 187156.38d }, { "orderdate": "1993-03-25", "sum_price": 167017.39d } ] }
+{ "nation_key": 22, "sum_price": [ { "orderdate": "1998-02-27", "sum_price": 263411.29d }, { "orderdate": "1993-04-11", "sum_price": 221636.83d }, { "orderdate": "1993-05-07", "sum_price": 220715.14d } ] }
+{ "nation_key": 0, "sum_price": [ { "orderdate": "1997-01-13", "sum_price": 241837.88d }, { "orderdate": "1997-01-21", "sum_price": 240284.95d }, { "orderdate": "1997-08-24", "sum_price": 231831.35d } ] }
+{ "nation_key": 8, "sum_price": [ { "orderdate": "1995-07-26", "sum_price": 244704.23d }, { "orderdate": "1994-12-03", "sum_price": 234763.73d }, { "orderdate": "1994-09-09", "sum_price": 228002.51d } ] }
+{ "nation_key": 9, "sum_price": [ { "orderdate": "1992-08-19", "sum_price": 240457.56d }, { "orderdate": "1995-03-02", "sum_price": 228136.49d }, { "orderdate": "1992-07-30", "sum_price": 226314.91d } ] }
+{ "nation_key": 10, "sum_price": [ { "orderdate": "1992-08-15", "sum_price": 232194.74d }, { "orderdate": "1997-01-03", "sum_price": 219920.62d }, { "orderdate": "1992-01-02", "sum_price": 210713.88d } ] }
+{ "nation_key": 3, "sum_price": [ { "orderdate": "1997-04-23", "sum_price": 351762.82999999996d }, { "orderdate": "1995-11-13", "sum_price": 242588.87d }, { "orderdate": "1993-07-15", "sum_price": 214494.39d } ] }
+{ "nation_key": 5, "sum_price": [ { "orderdate": "1997-04-04", "sum_price": 258779.02d }, { "orderdate": "1998-07-20", "sum_price": 209155.48d }, { "orderdate": "1994-04-27", "sum_price": 202917.72d } ] }
+{ "nation_key": 7, "sum_price": [ { "orderdate": "1995-03-19", "sum_price": 207925.83d }, { "orderdate": "1992-03-15", "sum_price": 206742.11d }, { "orderdate": "1992-05-10", "sum_price": 203904.8d } ] }
+{ "nation_key": 17, "sum_price": [ { "orderdate": "1997-07-05", "sum_price": 233874.09d }, { "orderdate": "1993-10-31", "sum_price": 224724.11d }, { "orderdate": "1996-04-18", "sum_price": 220727.97d } ] }
+{ "nation_key": 18, "sum_price": [ { "orderdate": "1995-10-03", "sum_price": 245976.74d }, { "orderdate": "1992-06-03", "sum_price": 233161.66d }, { "orderdate": "1996-09-20", "sum_price": 219707.84d } ] }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue786/query-issue786.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue786/query-issue786.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue786/query-issue786.1.adm
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.adm
new file mode 100644
index 0000000..d392ecf
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.adm
@@ -0,0 +1,4 @@
+{ "l_returnflag": "A", "l_linestatus": "F", "count_cheaps": 680, "total_charges": 3.7101416222424E7d }
+{ "l_returnflag": "N", "l_linestatus": "F", "count_cheaps": 12, "total_charges": 1036450.80228d }
+{ "l_returnflag": "N", "l_linestatus": "O", "count_cheaps": 1345, "total_charges": 7.4498798133073E7d }
+{ "l_returnflag": "R", "l_linestatus": "F", "count_cheaps": 679, "total_charges": 3.616906011219301E7d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.adm
new file mode 100644
index 0000000..d6dd75d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.adm
@@ -0,0 +1,4 @@
+{ "l_returnflag": "A", "l_linestatus": "F", "count_cheaps": 680, "avg_expensive_discounts": 0.025714285714285662d, "sum_disc_prices": 3.5676192097E7d, "total_charges": 3.7101416222424E7d }
+{ "l_returnflag": "N", "l_linestatus": "F", "count_cheaps": 12, "avg_expensive_discounts": 0.024615384615384615d, "sum_disc_prices": 999060.898d, "total_charges": 1036450.80228d }
+{ "l_returnflag": "N", "l_linestatus": "O", "count_cheaps": 1345, "avg_expensive_discounts": 0.024699248120300644d, "sum_disc_prices": 7.165316630340001E7d, "total_charges": 7.4498798133073E7d }
+{ "l_returnflag": "R", "l_linestatus": "F", "count_cheaps": 679, "avg_expensive_discounts": 0.0244601542416452d, "sum_disc_prices": 3.473847287579999E7d, "total_charges": 3.616906011219301E7d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810/query-issue810.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810/query-issue810.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810/query-issue810.1.adm
new file mode 100644
index 0000000..a74e76f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue810/query-issue810.1.adm
@@ -0,0 +1,4 @@
+{ "l_returnflag": "A", "l_linestatus": "F", "count_cheaps": 680, "count_expensives": 798 }
+{ "l_returnflag": "N", "l_linestatus": "F", "count_cheaps": 12, "count_expensives": 26 }
+{ "l_returnflag": "N", "l_linestatus": "O", "count_cheaps": 1345, "count_expensives": 1596 }
+{ "l_returnflag": "R", "l_linestatus": "F", "count_cheaps": 679, "count_expensives": 778 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827-2/query-issue827-2.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827-2/query-issue827-2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827-2/query-issue827-2.1.adm
new file mode 100644
index 0000000..1b693a2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827-2/query-issue827-2.1.adm
@@ -0,0 +1 @@
+{ "sum_qty_partial": 150194.0d, "sum_base_price": 1.5277439838000005E8d, "sum_disc_price": 1.4517182996390012E8d, "sum_charge": 1.51008955587289E8d, "ave_qty": 25.39634764964491d, "ave_price": 25441.198731057462d, "ave_disc": 0.05003164029975036d, "count_order": 6005 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827/query-issue827.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827/query-issue827.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827/query-issue827.1.adm
new file mode 100644
index 0000000..0a3b71c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/query-issue827/query-issue827.1.adm
@@ -0,0 +1 @@
+{ "count_cheaps": 6005, "count_expensives": 1.5277439838000005E8d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827-2/query-issue827-2.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827-2/query-issue827-2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827-2/query-issue827-2.1.adm
deleted file mode 100644
index 1b693a2..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827-2/query-issue827-2.1.adm
+++ /dev/null
@@ -1 +0,0 @@
-{ "sum_qty_partial": 150194.0d, "sum_base_price": 1.5277439838000005E8d, "sum_disc_price": 1.4517182996390012E8d, "sum_charge": 1.51008955587289E8d, "ave_qty": 25.39634764964491d, "ave_price": 25441.198731057462d, "ave_disc": 0.05003164029975036d, "count_order": 6005 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827/query-issue827.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827/query-issue827.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827/query-issue827.1.adm
deleted file mode 100644
index 0a3b71c..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql/query-issue827/query-issue827.1.adm
+++ /dev/null
@@ -1 +0,0 @@
-{ "count_cheaps": 6005, "count_expensives": 1.5277439838000005E8d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/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 7db84bd..b1d80ff 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
@@ -14,12 +14,12 @@ RecordConstructor [
       (
         SELECT ELEMENT [
         FieldAccessor [
-          Variable [ Name=#2 ]
+          Variable [ Name=#3 ]
           Field=token
         ]
         ]
         FROM [          Variable [ Name=#1 ]
-          AS Variable [ Name=#2 ]
+          AS Variable [ Name=#3 ]
         ]
       )
     ]
@@ -54,12 +54,12 @@ Orderby
     (
       SELECT ELEMENT [
       FieldAccessor [
-        Variable [ Name=#3 ]
+        Variable [ Name=#2 ]
         Field=token
       ]
       ]
       FROM [        Variable [ Name=#1 ]
-        AS Variable [ Name=#3 ]
+        AS Variable [ Name=#2 ]
       ]
     )
   ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/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 0d3c61e..c43f1c7 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
@@ -25,12 +25,12 @@ RecordConstructor [
             (
               SELECT ELEMENT [
               FieldAccessor [
-                Variable [ Name=#2 ]
+                Variable [ Name=#3 ]
                 Field=i
               ]
               ]
               FROM [                Variable [ Name=#1 ]
-                AS Variable [ Name=#2 ]
+                AS Variable [ Name=#3 ]
               ]
             )
           ]
@@ -78,12 +78,12 @@ RecordConstructor [
           (
             SELECT ELEMENT [
             FieldAccessor [
-              Variable [ Name=#3 ]
+              Variable [ Name=#2 ]
               Field=i
             ]
             ]
             FROM [              Variable [ Name=#1 ]
-              AS Variable [ Name=#3 ]
+              AS Variable [ Name=#2 ]
             ]
           )
         ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/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 803e76b..586630d 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
@@ -7,12 +7,12 @@ FunctionCall TinySocial.sql-count@1[
   (
     SELECT ELEMENT [
     FieldAccessor [
-      Variable [ Name=#2 ]
+      Variable [ Name=#4 ]
       Field=t
     ]
     ]
     FROM [      Variable [ Name=#1 ]
-      AS Variable [ Name=#2 ]
+      AS Variable [ Name=#4 ]
     ]
   )
 ]
@@ -25,12 +25,12 @@ count
     (
       SELECT ELEMENT [
       FieldAccessor [
-        Variable [ Name=#4 ]
+        Variable [ Name=#3 ]
         Field=k
       ]
       ]
-      FROM [        Variable [ Name=#3 ]
-        AS Variable [ Name=#4 ]
+      FROM [        Variable [ Name=#2 ]
+        AS Variable [ Name=#3 ]
       ]
     )
   ]
@@ -48,7 +48,7 @@ count
         Field=send-time
       ]
     ]
-    GROUP AS Variable [ Name=#3 ]
+    GROUP AS Variable [ Name=#2 ]
     (
       k:=Variable [ Name=$k ]
       t:=Variable [ Name=$t ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/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 803e76b..586630d 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
@@ -7,12 +7,12 @@ FunctionCall TinySocial.sql-count@1[
   (
     SELECT ELEMENT [
     FieldAccessor [
-      Variable [ Name=#2 ]
+      Variable [ Name=#4 ]
       Field=t
     ]
     ]
     FROM [      Variable [ Name=#1 ]
-      AS Variable [ Name=#2 ]
+      AS Variable [ Name=#4 ]
     ]
   )
 ]
@@ -25,12 +25,12 @@ count
     (
       SELECT ELEMENT [
       FieldAccessor [
-        Variable [ Name=#4 ]
+        Variable [ Name=#3 ]
         Field=k
       ]
       ]
-      FROM [        Variable [ Name=#3 ]
-        AS Variable [ Name=#4 ]
+      FROM [        Variable [ Name=#2 ]
+        AS Variable [ Name=#3 ]
       ]
     )
   ]
@@ -48,7 +48,7 @@ count
         Field=send-time
       ]
     ]
-    GROUP AS Variable [ Name=#3 ]
+    GROUP AS Variable [ Name=#2 ]
     (
       k:=Variable [ Name=$k ]
       t:=Variable [ Name=$t ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/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 358d74b..a34689e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1350,7 +1350,7 @@
     <test-case FilePath="custord">
       <compilation-unit name="join_q_07">
         <output-dir compare="Text">join_q_06</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Could not find dataset c in dataverse test</expected-error>
+        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Undefined alias (variable) reference for identifier c</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="custord">
@@ -1400,6 +1400,26 @@
         <output-dir compare="Text">q2</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-2">
+        <output-dir compare="Text">q2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-3">
+        <output-dir compare="Text">q2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-4">
+        <output-dir compare="Text">q2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dapd">
+      <compilation-unit name="q2-5">
+        <output-dir compare="Text">q2</output-dir>
+      </compilation-unit>
+    </test-case>
     <!--
         <test-case FilePath="dapd">
           <compilation-unit name="q3">
@@ -2786,7 +2806,7 @@
         <output-dir compare="Text">partition-by-nonexistent-field</output-dir>
         <expected-error>java.lang.NullPointerException</expected-error>
         <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Cannot find dataset</expected-error>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Could not find dataset</expected-error>
+        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Undefined alias (variable) reference for identifier testds</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="misc">
@@ -5679,6 +5699,193 @@
       </compilation-unit>
     </test-case>
   </test-group>
+  <test-group name="tpch-sql-sugar">
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="distinct_by">
+        <output-dir compare="Text">distinct_by</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="group_no_agg">
+        <output-dir compare="Text">group_no_agg</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="nest_aggregate">
+        <output-dir compare="Text">nest_aggregate</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="nest_aggregate2">
+        <output-dir compare="Text">nest_aggregate2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue638">
+        <output-dir compare="Text">query-issue638</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue785">
+        <output-dir compare="Text">query-issue785</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue785-2">
+        <output-dir compare="Text">query-issue785-2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue786">
+        <output-dir compare="Text">query-issue786</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue601">
+        <output-dir compare="Text">query-issue601</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q10_returned_item">
+        <output-dir compare="Text">q10_returned_item</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q10_returned_item_int64">
+        <output-dir compare="Text">q10_returned_item_int64</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q11_important_stock">
+        <output-dir compare="Text">q11_important_stock</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q12_shipping">
+        <output-dir compare="Text">q12_shipping</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q13_customer_distribution">
+        <output-dir compare="Text">q13_customer_distribution</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q14_promotion_effect">
+        <output-dir compare="Text">q14_promotion_effect</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q15_top_supplier">
+        <output-dir compare="Text">q15_top_supplier</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q16_parts_supplier_relationship">
+        <output-dir compare="Text">q16_parts_supplier_relationship</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q17_small_quantity_order_revenue">
+        <output-dir compare="Text">q17_small_quantity_order_revenue</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q17_large_gby_variant">
+        <output-dir compare="Text">q17_large_gby_variant</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q18_large_volume_customer">
+        <output-dir compare="Text">q18_large_volume_customer</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q19_discounted_revenue">
+        <output-dir compare="Text">q19_discounted_revenue</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q01_pricing_summary_report_nt">
+        <output-dir compare="Text">q01_pricing_summary_report_nt</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q20_potential_part_promotion">
+        <output-dir compare="Text">q20_potential_part_promotion</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q21_suppliers_who_kept_orders_waiting">
+        <output-dir compare="Text">q21_suppliers_who_kept_orders_waiting</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q22_global_sales_opportunity">
+        <output-dir compare="Text">q22_global_sales_opportunity</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q02_minimum_cost_supplier">
+        <output-dir compare="Text">q02_minimum_cost_supplier</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q03_shipping_priority_nt">
+        <output-dir compare="Text">q03_shipping_priority_nt</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q04_order_priority">
+        <output-dir compare="Text">q04_order_priority</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q05_local_supplier_volume">
+        <output-dir compare="Text">q05_local_supplier_volume</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q06_forecast_revenue_change">
+        <output-dir compare="Text">q06_forecast_revenue_change</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q07_volume_shipping">
+        <output-dir compare="Text">q07_volume_shipping</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q08_national_market_share">
+        <output-dir compare="Text">q08_national_market_share</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q09_product_type_profit_nt">
+        <output-dir compare="Text">q09_product_type_profit_nt</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue562">
+        <output-dir compare="Text">query-issue562</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue810">
+        <output-dir compare="Text">query-issue810</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue810-2">
+        <output-dir compare="Text">query-issue810-2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="query-issue810-3">
+        <output-dir compare="Text">query-issue810-3</output-dir>
+      </compilation-unit>
+    </test-case>
+  </test-group>
   <test-group name="tpch-with-index">
     <test-case FilePath="tpch-with-index">
       <compilation-unit name="distinct_by">

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
index c5c8b78..6b77fc7 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
@@ -26,7 +26,6 @@ public interface Expression extends ILangExpression {
         FLWOGR_EXPRESSION,
         IF_EXPRESSION,
         QUANTIFIED_EXPRESSION,
-        // PARENTHESIZED_EXPRESSION,
         LIST_CONSTRUCTOR_EXPRESSION,
         RECORD_CONSTRUCTOR_EXPRESSION,
         VARIABLE_EXPRESSION,
@@ -39,7 +38,8 @@ public interface Expression extends ILangExpression {
         UNION_EXPRESSION,
         SELECT_EXPRESSION,
         PRIMARY_EXPRESSION,
-        VALUE_EXPRESSION
+        VALUE_EXPRESSION,
+        INDEPENDENT_SUBQUERY
     }
 
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
index 8a756c7..82e1f02 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
@@ -40,8 +40,7 @@ public class FromTerm implements Clause {
         this.leftExpr = leftExpr;
         this.leftVar = leftVar;
         this.posVar = posVar;
-        this.correlateClauses = correlateClauses == null ? new ArrayList<AbstractBinaryCorrelateClause>()
-                : correlateClauses;
+        this.correlateClauses = correlateClauses == null ? new ArrayList<>() : correlateClauses;
     }
 
     @Override
@@ -71,7 +70,7 @@ public class FromTerm implements Clause {
     }
 
     public boolean hasCorrelateClauses() {
-        return correlateClauses != null && correlateClauses.size() > 0;
+        return correlateClauses != null && !correlateClauses.isEmpty();
     }
 
     public List<AbstractBinaryCorrelateClause> getCorrelateClauses() {
@@ -84,6 +83,6 @@ public class FromTerm implements Clause {
 
     @Override
     public String toString() {
-        return String.valueOf(leftExpr) + " AS " + String.valueOf(leftVar);
+        return String.valueOf(leftExpr) + " AS " + leftVar;
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java
new file mode 100644
index 0000000..3825092
--- /dev/null
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.lang.sqlpp.expression;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
+import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
+
+public class IndependentSubquery implements Expression {
+
+    private Expression expr;
+
+    public IndependentSubquery(Expression enclosedExpr) {
+        this.expr = enclosedExpr;
+    }
+
+    @Override
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+        return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
+    }
+
+    @Override
+    public Kind getKind() {
+        return Kind.INDEPENDENT_SUBQUERY;
+    }
+
+    public void setExpr(Expression expr) {
+        this.expr = expr;
+    }
+
+    public Expression getExpr() {
+        return this.expr;
+    }
+
+    @Override
+    public String toString() {
+        return String.valueOf(expr);
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java
index 1d49d21..7f9daf8 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java
@@ -81,7 +81,7 @@ public class SelectExpression implements Expression {
     }
 
     public boolean hasLetClauses() {
-        return letList != null && letList.size() > 0;
+        return letList != null && !letList.isEmpty();
     }
 
     public boolean isSubquery() {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java
index 01b9b54..8f41015 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java
@@ -37,6 +37,9 @@ class SqlppFunctionBodyRewriter extends SqlppQueryRewriter {
         // Inlines column aliases.
         inlineColumnAlias();
 
+        // Inlines WITH expressions.
+        inlineWithExpressions();
+
         // Rewrites SQL-92 global aggregations.
         rewriteGlobalAggregations();
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
index 3532c9d..fab5c07 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
@@ -45,10 +45,12 @@ import org.apache.asterix.lang.sqlpp.clause.SelectElement;
 import org.apache.asterix.lang.sqlpp.clause.SelectRegular;
 import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
 import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
+import org.apache.asterix.lang.sqlpp.expression.IndependentSubquery;
 import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
 import org.apache.asterix.lang.sqlpp.parser.FunctionParser;
 import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.InlineColumnAliasVisitor;
+import org.apache.asterix.lang.sqlpp.rewrites.visitor.InlineWithExpressionVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppBuiltinFunctionRewriteVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppGlobalAggregationSugarVisitor;
 import org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppGroupByVisitor;
@@ -64,6 +66,8 @@ import org.apache.asterix.metadata.entities.Function;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 
 class SqlppQueryRewriter implements IQueryRewriter {
+    private static final String INLINE_WITH = "inline_with";
+    private static final String NOT_INLINE_WITH = "false";
     private final FunctionParser functionRepository = new FunctionParser(new SqlppParserFactory());
     private Query topExpr;
     private List<FunctionDecl> declaredFunctions;
@@ -89,6 +93,9 @@ class SqlppQueryRewriter implements IQueryRewriter {
         // Inlines column aliases.
         inlineColumnAlias();
 
+        // Inlines WITH expressions.
+        inlineWithExpressions();
+
         // Rewrites SQL-92 global aggregations.
         rewriteGlobalAggregations();
 
@@ -129,12 +136,25 @@ class SqlppQueryRewriter implements IQueryRewriter {
         functionNameMapVisitor.visit(topExpr, null);
     }
 
+    protected void inlineWithExpressions() throws AsterixException {
+        if (topExpr == null) {
+            return;
+        }
+        String inlineWith = metadataProvider.getConfig().get(INLINE_WITH);
+        if (inlineWith != null && inlineWith.equalsIgnoreCase(NOT_INLINE_WITH)) {
+            return;
+        }
+        // Inlines with expressions.
+        InlineWithExpressionVisitor inlineWithExpressionVisitor = new InlineWithExpressionVisitor(context);
+        inlineWithExpressionVisitor.visit(topExpr, null);
+    }
+
     protected void inlineColumnAlias() throws AsterixException {
         if (topExpr == null) {
             return;
         }
         // Inline column aliases.
-        InlineColumnAliasVisitor inlineColumnAliasVisitor = new InlineColumnAliasVisitor(context);
+        InlineColumnAliasVisitor inlineColumnAliasVisitor = new InlineColumnAliasVisitor();
         inlineColumnAliasVisitor.visit(topExpr, false);
     }
 
@@ -213,9 +233,9 @@ class SqlppQueryRewriter implements IQueryRewriter {
                 FunctionDecl functionDecl = functionRepository.getFunctionDecl(function);
                 if (functionDecl != null) {
                     if (functionDecls.contains(functionDecl)) {
-                        throw new AsterixException("Recursive invocation "
-                                + functionDecls.get(functionDecls.size() - 1).getSignature() + " <==> "
-                                + functionDecl.getSignature());
+                        throw new AsterixException(
+                                "Recursive invocation " + functionDecls.get(functionDecls.size() - 1).getSignature()
+                                        + " <==> " + functionDecl.getSignature());
                     }
                     functionDecls.add(functionDecl);
                     buildOtherUdfs(functionDecl.getFuncBody(), functionDecls, declaredFunctions);
@@ -365,5 +385,11 @@ class SqlppQueryRewriter implements IQueryRewriter {
             return null;
         }
 
+        @Override
+        public Void visit(IndependentSubquery independentSubquery, Void arg) throws AsterixException {
+            independentSubquery.getExpr().accept(this, arg);
+            return null;
+        }
+
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java
index ea78c9b..2918a90 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java
@@ -47,7 +47,6 @@ import org.apache.asterix.lang.common.expression.RecordConstructor;
 import org.apache.asterix.lang.common.expression.UnaryExpr;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.parser.ScopeChecker;
-import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
 import org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment;
 import org.apache.asterix.lang.common.statement.FunctionDecl;
 import org.apache.asterix.lang.common.statement.Query;
@@ -65,6 +64,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectElement;
 import org.apache.asterix.lang.sqlpp.clause.SelectRegular;
 import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
 import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
+import org.apache.asterix.lang.sqlpp.expression.IndependentSubquery;
 import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
 import org.apache.asterix.lang.sqlpp.util.SqlppRewriteUtil;
@@ -75,11 +75,6 @@ import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppQueryExpressionVi
 public class InlineColumnAliasVisitor extends AbstractSqlppQueryExpressionVisitor<Void, Boolean> {
 
     private final ScopeChecker scopeChecker = new ScopeChecker();
-    private final LangRewritingContext context;
-
-    public InlineColumnAliasVisitor(LangRewritingContext context) {
-        this.context = context;
-    }
 
     @Override
     public Void visit(WhereClause whereClause, Boolean overwriteWithGbyKeyVarRefs) throws AsterixException {
@@ -311,7 +306,7 @@ public class InlineColumnAliasVisitor extends AbstractSqlppQueryExpressionVisito
     @Override
     public Void visit(OrderbyClause oc, Boolean overwriteWithGbyKeyVarRefs) throws AsterixException {
         VariableSubstitutionEnvironment env = scopeChecker.getCurrentScope().getVarSubstitutionEnvironment();
-        List<Expression> orderExprs = new ArrayList<Expression>();
+        List<Expression> orderExprs = new ArrayList<>();
         for (Expression orderExpr : oc.getOrderbyList()) {
             orderExprs.add((Expression) SqlppVariableSubstitutionUtil.substituteVariableWithoutContext(orderExpr, env));
             orderExpr.accept(this, overwriteWithGbyKeyVarRefs);
@@ -330,9 +325,6 @@ public class InlineColumnAliasVisitor extends AbstractSqlppQueryExpressionVisito
                     env);
             newExpr.accept(this, overwriteWithGbyKeyVarRefs);
             gbyVarExpr.setExpr(newExpr);
-            if (gbyVarExpr.getVar() == null) {
-                gbyVarExpr.setVar(new VariableExpr(context.newVariable()));
-            }
             if (oldGbyExpr.getKind() == Kind.VARIABLE_EXPRESSION) {
                 VariableExpr oldGbyVarExpr = (VariableExpr) oldGbyExpr;
                 if (env.findSubstitution(oldGbyVarExpr) != null) {
@@ -461,6 +453,13 @@ public class InlineColumnAliasVisitor extends AbstractSqlppQueryExpressionVisito
         return null;
     }
 
+    @Override
+    public Void visit(IndependentSubquery independentSubquery, Boolean overwriteWithGbyKeyVarRefs)
+            throws AsterixException {
+        independentSubquery.getExpr().accept(this, overwriteWithGbyKeyVarRefs);
+        return null;
+    }
+
     private void removeSubsutitions(AbstractBinaryCorrelateClause unnestClause) {
         scopeChecker.getCurrentScope().removeSymbolExpressionMapping(unnestClause.getRightVariable());
         if (unnestClause.hasPositionalVariable()) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java
new file mode 100644
index 0000000..bec1523
--- /dev/null
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.asterix.lang.sqlpp.rewrites.visitor;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.clause.LetClause;
+import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
+import org.apache.asterix.lang.sqlpp.expression.IndependentSubquery;
+import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.util.SqlppVariableSubstitutionUtil;
+import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppExpressionScopingVisitor;
+
+public class InlineWithExpressionVisitor extends AbstractSqlppExpressionScopingVisitor {
+
+    public InlineWithExpressionVisitor(LangRewritingContext context) {
+        super(context);
+    }
+
+    @Override
+    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws AsterixException {
+        if (selectExpression.hasLetClauses()) {
+            // Inlines the leading WITH list.
+            Map<VariableExpr, Expression> varExprMap = new HashMap<>();
+            List<LetClause> withs = selectExpression.getLetList();
+            Iterator<LetClause> with = withs.iterator();
+            while (with.hasNext()) {
+                LetClause letClause = with.next();
+                // Replaces the let binding Expr.
+                Expression expr = letClause.getBindingExpr();
+                letClause.setBindingExpr(
+                        (Expression) SqlppVariableSubstitutionUtil.substituteVariableWithoutContext(expr, varExprMap));
+                with.remove();
+                Expression bindingExpr = letClause.getBindingExpr();
+                // Wraps the binding expression with IndependentSubquery, so that free identifier references
+                // in the binding expression will not be resolved use outer-scope variables.
+                varExprMap.put(letClause.getVarExpr(), new IndependentSubquery(bindingExpr));
+            }
+
+            // Inlines WITH expressions into the select expression.
+            SelectExpression newSelectExpression = (SelectExpression) SqlppVariableSubstitutionUtil
+                    .substituteVariableWithoutContext(selectExpression, varExprMap);
+
+            // Continues to visit the rewritten select expression.
+            return super.visit(newSelectExpression, arg);
+        }
+        return selectExpression;
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java
index c7c7d11..e046ccf 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java
@@ -24,6 +24,7 @@ import java.util.List;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
 import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppSimpleExpressionVisitor;
@@ -31,11 +32,11 @@ import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppSimpleExpressionV
 public class SqlppBuiltinFunctionRewriteVisitor extends AbstractSqlppSimpleExpressionVisitor {
 
     @Override
-    public Expression visit(CallExpr callExpr, Expression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
         //TODO(buyingyi): rewrite SQL temporal functions
         FunctionSignature functionSignature = callExpr.getFunctionSignature();
         callExpr.setFunctionSignature(FunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature, true));
-        List<Expression> newExprList = new ArrayList<Expression>();
+        List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : callExpr.getExprList()) {
             newExprList.add(expr.accept(this, arg));
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java
index ae629af..98d18c2 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java
@@ -37,10 +37,10 @@ import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppSimpleExpressionV
 public class SqlppGlobalAggregationSugarVisitor extends AbstractSqlppSimpleExpressionVisitor {
 
     @Override
-    public Expression visit(SelectBlock selectBlock, Expression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
         SelectClause selectClause = selectBlock.getSelectClause();
         if (!selectBlock.hasGroupbyClause() && selectBlock.hasFromClause()) {
-            boolean addImplicitGby = false;
+            boolean addImplicitGby;
             if (selectClause.selectRegular()) {
                 addImplicitGby = isSql92Aggregate(selectClause.getSelectRegular(), selectBlock);
             } else {