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:09 UTC

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

Repository: asterixdb
Updated Branches:
  refs/heads/master 5a12edffc -> 9e3f9befa


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/IPartitioningProperty.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/IPartitioningProperty.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/IPartitioningProperty.java
index 89ac374..0b7cb3e 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/IPartitioningProperty.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/IPartitioningProperty.java
@@ -27,7 +27,11 @@ import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
 
 public interface IPartitioningProperty extends IStructuralProperty {
     enum PartitioningType {
-        UNPARTITIONED, RANDOM, BROADCAST, UNORDERED_PARTITIONED, ORDERED_PARTITIONED
+        UNPARTITIONED,
+        RANDOM,
+        BROADCAST,
+        UNORDERED_PARTITIONED,
+        ORDERED_PARTITIONED
     }
 
     INodeDomain DOMAIN_FOR_UNPARTITIONED_DATA = new INodeDomain() {
@@ -50,8 +54,9 @@ public interface IPartitioningProperty extends IStructuralProperty {
         }
 
         @Override
-        public void normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses, List<FunctionalDependency> fds) {
-            // do nothing
+        public IPartitioningProperty normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses,
+                List<FunctionalDependency> fds) {
+            return UNPARTITIONED;
         }
 
         @Override
@@ -80,7 +85,7 @@ public interface IPartitioningProperty extends IStructuralProperty {
 
     PartitioningType getPartitioningType();
 
-    void normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses,
+    IPartitioningProperty normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses,
             List<FunctionalDependency> fds);
 
     INodeDomain getNodeDomain();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/OrderedPartitionedProperty.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/OrderedPartitionedProperty.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/OrderedPartitionedProperty.java
index 44df740..23c8273 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/OrderedPartitionedProperty.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/OrderedPartitionedProperty.java
@@ -28,20 +28,20 @@ import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
 
 public class OrderedPartitionedProperty implements IPartitioningProperty {
 
-    private ArrayList<OrderColumn> orderColumns;
+    private List<OrderColumn> orderColumns;
     private INodeDomain domain;
 
-    public OrderedPartitionedProperty(ArrayList<OrderColumn> orderColumns, INodeDomain domain) {
+    public OrderedPartitionedProperty(List<OrderColumn> orderColumns, INodeDomain domain) {
         this.domain = domain;
         this.orderColumns = orderColumns;
     }
 
-    public ArrayList<OrderColumn> getOrderColumns() {
+    public List<OrderColumn> getOrderColumns() {
         return orderColumns;
     }
 
-    public ArrayList<LogicalVariable> getColumns() {
-        ArrayList<LogicalVariable> cols = new ArrayList<LogicalVariable>(orderColumns.size());
+    public List<LogicalVariable> getColumns() {
+        ArrayList<LogicalVariable> cols = new ArrayList<>(orderColumns.size());
         for (OrderColumn oc : orderColumns) {
             cols.add(oc.getColumn());
         }
@@ -59,9 +59,11 @@ public class OrderedPartitionedProperty implements IPartitioningProperty {
     }
 
     @Override
-    public void normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses, List<FunctionalDependency> fds) {
-        orderColumns = PropertiesUtil.replaceOrderColumnsByEqClasses(orderColumns, equivalenceClasses);
-        orderColumns = PropertiesUtil.applyFDsToOrderColumns(orderColumns, fds);
+    public IPartitioningProperty normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses,
+            List<FunctionalDependency> fds) {
+        List<OrderColumn> columns = PropertiesUtil.replaceOrderColumnsByEqClasses(orderColumns, equivalenceClasses);
+        columns = PropertiesUtil.applyFDsToOrderColumns(columns, fds);
+        return new OrderedPartitionedProperty(columns, domain);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/PropertiesUtil.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/PropertiesUtil.java
index 0b8d759..f2e4bde 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/PropertiesUtil.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/PropertiesUtil.java
@@ -208,7 +208,7 @@ public class PropertiesUtil {
         return true;
     }
 
-    public static ArrayList<OrderColumn> applyFDsToOrderColumns(ArrayList<OrderColumn> orderColumns,
+    public static List<OrderColumn> applyFDsToOrderColumns(List<OrderColumn> orderColumns,
             List<FunctionalDependency> fds) {
         // the set of vars. is ordered
         // so we try the variables in order from last to first
@@ -226,7 +226,7 @@ public class PropertiesUtil {
                 }
             }
         }
-        ArrayList<OrderColumn> norm = new ArrayList<OrderColumn>(orderColumns.size() - deleted);
+        List<OrderColumn> norm = new ArrayList<>(orderColumns.size() - deleted);
         for (OrderColumn oc : orderColumns) {
             if (oc != null) {
                 norm.add(oc);
@@ -235,12 +235,12 @@ public class PropertiesUtil {
         return norm;
     }
 
-    public static ArrayList<OrderColumn> replaceOrderColumnsByEqClasses(ArrayList<OrderColumn> orderColumns,
+    public static List<OrderColumn> replaceOrderColumnsByEqClasses(List<OrderColumn> orderColumns,
             Map<LogicalVariable, EquivalenceClass> equivalenceClasses) {
         if (equivalenceClasses == null || equivalenceClasses.isEmpty()) {
             return orderColumns;
         }
-        ArrayList<OrderColumn> norm = new ArrayList<OrderColumn>();
+        List<OrderColumn> norm = new ArrayList<>();
         for (OrderColumn v : orderColumns) {
             EquivalenceClass ec = equivalenceClasses.get(v.getColumn());
             if (ec == null) {
@@ -256,7 +256,7 @@ public class PropertiesUtil {
         return norm;
     }
 
-    private static boolean impliedByPrefix(ArrayList<OrderColumn> vars, int i, FunctionalDependency fdep) {
+    private static boolean impliedByPrefix(List<OrderColumn> vars, int i, FunctionalDependency fdep) {
         if (!fdep.getTail().contains(vars.get(i).getColumn())) {
             return false;
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/RandomPartitioningProperty.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/RandomPartitioningProperty.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/RandomPartitioningProperty.java
index fb3f044..bbd835c 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/RandomPartitioningProperty.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/RandomPartitioningProperty.java
@@ -44,8 +44,9 @@ public class RandomPartitioningProperty implements IPartitioningProperty {
     }
 
     @Override
-    public void normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses, List<FunctionalDependency> fds) {
-        // do nothing
+    public IPartitioningProperty normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses,
+            List<FunctionalDependency> fds) {
+        return this;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/StructuralPropertiesVector.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/StructuralPropertiesVector.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/StructuralPropertiesVector.java
index 2cad1cb..233c4a6 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/StructuralPropertiesVector.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/StructuralPropertiesVector.java
@@ -83,14 +83,12 @@ public class StructuralPropertiesVector implements IPhysicalPropertiesVector {
 
         IPartitioningProperty diffPart = null;
         IPartitioningProperty reqdPart = reqd.getPartitioningProperty();
+
         if (reqdPart != null) {
-            if (mayExpandProperties) {
-                reqdPart.normalize(equivalenceClasses, fds);
-            } else {
-                reqdPart.normalize(equivalenceClasses, null);
-            }
-            propPartitioning.normalize(equivalenceClasses, fds);
-            if (!PropertiesUtil.matchPartitioningProps(reqdPart, propPartitioning, mayExpandProperties)) {
+            IPartitioningProperty normalizedReqPart = reqdPart.normalize(equivalenceClasses,
+                    mayExpandProperties ? fds : null);
+            IPartitioningProperty normalizedPropPart = propPartitioning.normalize(equivalenceClasses, fds);
+            if (!PropertiesUtil.matchPartitioningProps(normalizedReqPart, normalizedPropPart, mayExpandProperties)) {
                 diffPart = reqdPart;
             }
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/UnorderedPartitionedProperty.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/UnorderedPartitionedProperty.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/UnorderedPartitionedProperty.java
index d6a364a..7d0d4cf 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/UnorderedPartitionedProperty.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/UnorderedPartitionedProperty.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.hyracks.algebricks.common.utils.ListSet;
 import org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass;
 import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
 
@@ -41,8 +42,12 @@ public final class UnorderedPartitionedProperty extends AbstractGroupingProperty
     }
 
     @Override
-    public void normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses, List<FunctionalDependency> fds) {
-        normalizeGroupingColumns(equivalenceClasses, fds);
+    public IPartitioningProperty normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses,
+            List<FunctionalDependency> fds) {
+        UnorderedPartitionedProperty partitioningProperty = new UnorderedPartitionedProperty(new ListSet<>(columnSet),
+                domain);
+        partitioningProperty.normalizeGroupingColumns(equivalenceClasses, fds);
+        return partitioningProperty;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IntSerDeUtils.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IntSerDeUtils.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IntSerDeUtils.java
index b5cb8b1..05e694c 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IntSerDeUtils.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/IntSerDeUtils.java
@@ -28,9 +28,13 @@ public class IntSerDeUtils {
 
     /**
      * put integer value into the array bytes at the offset offset
-     * @param bytes byte array to put data in
-     * @param offset offset from the beginning of the array to write the {@code value} in
-     * @param value value to write to {@code bytes[offset]}
+     *
+     * @param bytes
+     *            byte array to put data in
+     * @param offset
+     *            offset from the beginning of the array to write the {@code value} in
+     * @param value
+     *            value to write to {@code bytes[offset]}
      */
     public static void putInt(byte[] bytes, int offset, int value) {
 


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

Posted by bu...@apache.org.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.adm
new file mode 100644
index 0000000..a109ef1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.adm
@@ -0,0 +1,200 @@
+{ "t_partkey": 1, "t_count": 35, "t_avg_quantity": 5.28d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 23786.4d, "t_avg_discount": 0.044000000000000004d, "t_avg_tax": 0.049142857142857155d, "t_max_shipdate": "1997-08-08", "t_min_commitdate": "1992-04-02", "t_min_receiptdate": "1992-02-28", "t_max_comment": "y ironic requests. bold, final ideas a" }
+{ "t_partkey": 2, "t_count": 34, "t_avg_quantity": 4.347058823529411d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 19605.235294117647d, "t_avg_discount": 0.049705882352941176d, "t_avg_tax": 0.04d, "t_max_shipdate": "1998-05-31", "t_min_commitdate": "1992-07-12", "t_min_receiptdate": "1992-07-08", "t_max_comment": "yly final dolphins? quickly ironic frets" }
+{ "t_partkey": 3, "t_count": 27, "t_avg_quantity": 4.896296296296296d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 22106.777777777777d, "t_avg_discount": 0.05481481481481482d, "t_avg_tax": 0.04185185185185186d, "t_max_shipdate": "1998-05-22", "t_min_commitdate": "1992-03-20", "t_min_receiptdate": "1992-05-04", "t_max_comment": "yly blithely pending packages" }
+{ "t_partkey": 4, "t_count": 26, "t_avg_quantity": 4.2615384615384615d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 19262.153846153848d, "t_avg_discount": 0.056538461538461544d, "t_avg_tax": 0.04d, "t_max_shipdate": "1998-08-26", "t_min_commitdate": "1992-03-21", "t_min_receiptdate": "1992-05-27", "t_max_comment": "y regular packages haggle furiously alongs" }
+{ "t_partkey": 5, "t_count": 32, "t_avg_quantity": 5.4750000000000005d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 24774.375d, "t_avg_discount": 0.04125d, "t_avg_tax": 0.0390625d, "t_max_shipdate": "1998-07-19", "t_min_commitdate": "1992-05-12", "t_min_receiptdate": "1992-05-10", "t_max_comment": "y. careful" }
+{ "t_partkey": 6, "t_count": 34, "t_avg_quantity": 5.2058823529411775d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23582.647058823528d, "t_avg_discount": 0.05676470588235293d, "t_avg_tax": 0.04176470588235294d, "t_max_shipdate": "1998-09-05", "t_min_commitdate": "1992-04-24", "t_min_receiptdate": "1992-04-08", "t_max_comment": "yly express " }
+{ "t_partkey": 7, "t_count": 22, "t_avg_quantity": 4.7d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 21314.5d, "t_avg_discount": 0.05772727272727273d, "t_avg_tax": 0.041818181818181824d, "t_max_shipdate": "1998-07-27", "t_min_commitdate": "1992-05-31", "t_min_receiptdate": "1992-04-21", "t_max_comment": "ss the ironic, regular asymptotes cajole " }
+{ "t_partkey": 8, "t_count": 24, "t_avg_quantity": 4.783333333333334d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 21716.333333333332d, "t_avg_discount": 0.055d, "t_avg_tax": 0.04958333333333333d, "t_max_shipdate": "1998-07-04", "t_min_commitdate": "1992-10-24", "t_min_receiptdate": "1992-10-11", "t_max_comment": "uctions. furiously regular ins" }
+{ "t_partkey": 9, "t_count": 29, "t_avg_quantity": 5.331034482758621d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 24229.55172413793d, "t_avg_discount": 0.04206896551724139d, "t_avg_tax": 0.03896551724137932d, "t_max_shipdate": "1998-06-12", "t_min_commitdate": "1992-03-30", "t_min_receiptdate": "1992-05-23", "t_max_comment": "yly ironic" }
+{ "t_partkey": 10, "t_count": 31, "t_avg_quantity": 5.509677419354839d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 25069.307741935485d, "t_avg_discount": 0.052903225806451626d, "t_avg_tax": 0.04548387096774194d, "t_max_shipdate": "1998-10-02", "t_min_commitdate": "1992-07-21", "t_min_receiptdate": "1992-05-18", "t_max_comment": "y quickly ironic accounts." }
+{ "t_partkey": 11, "t_count": 28, "t_avg_quantity": 5.521428571428572d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 25150.383214285714d, "t_avg_discount": 0.05d, "t_avg_tax": 0.046071428571428576d, "t_max_shipdate": "1998-07-12", "t_min_commitdate": "1992-03-15", "t_min_receiptdate": "1992-02-26", "t_max_comment": "ven dependencies x-ray. quic" }
+{ "t_partkey": 12, "t_count": 24, "t_avg_quantity": 4.966666666666667d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 22648.248333333333d, "t_avg_discount": 0.04791666666666667d, "t_avg_tax": 0.05083333333333334d, "t_max_shipdate": "1998-04-14", "t_min_commitdate": "1992-05-03", "t_min_receiptdate": "1992-07-29", "t_max_comment": "xpress grouc" }
+{ "t_partkey": 13, "t_count": 26, "t_avg_quantity": 5.038461538461539d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 23000.828846153847d, "t_avg_discount": 0.04153846153846154d, "t_avg_tax": 0.04d, "t_max_shipdate": "1998-10-04", "t_min_commitdate": "1992-03-31", "t_min_receiptdate": "1992-04-21", "t_max_comment": "wake at the carefully speci" }
+{ "t_partkey": 14, "t_count": 25, "t_avg_quantity": 4.5840000000000005d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 20949.1092d, "t_avg_discount": 0.055600000000000004d, "t_avg_tax": 0.0436d, "t_max_shipdate": "1998-10-17", "t_min_commitdate": "1992-07-16", "t_min_receiptdate": "1992-08-05", "t_max_comment": "thely. furio" }
+{ "t_partkey": 15, "t_count": 21, "t_avg_quantity": 5.133333333333334d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23485.256666666664d, "t_avg_discount": 0.051428571428571435d, "t_avg_tax": 0.03142857142857143d, "t_max_shipdate": "1998-02-14", "t_min_commitdate": "1992-04-01", "t_min_receiptdate": "1992-05-26", "t_max_comment": "ymptotes nag furiously slyly even inst" }
+{ "t_partkey": 16, "t_count": 29, "t_avg_quantity": 4.731034482758621d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 21668.37448275862d, "t_avg_discount": 0.049310344827586214d, "t_avg_tax": 0.034482758620689655d, "t_max_shipdate": "1998-11-02", "t_min_commitdate": "1992-08-06", "t_min_receiptdate": "1992-09-12", "t_max_comment": "yly blithely stealthy deposits. carefu" }
+{ "t_partkey": 17, "t_count": 31, "t_avg_quantity": 5.270967741935484d, "t_max_suppkey": 8, "t_max_linenumber": 6, "t_avg_extendedprice": 24167.650645161288d, "t_avg_discount": 0.05387096774193549d, "t_avg_tax": 0.04709677419354839d, "t_max_shipdate": "1998-10-04", "t_min_commitdate": "1992-08-07", "t_min_receiptdate": "1992-08-13", "t_max_comment": "uriously thin pinto beans " }
+{ "t_partkey": 18, "t_count": 32, "t_avg_quantity": 5.4437500000000005d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 24987.0846875d, "t_avg_discount": 0.05500000000000001d, "t_avg_tax": 0.039375d, "t_max_shipdate": "1998-11-13", "t_min_commitdate": "1992-04-14", "t_min_receiptdate": "1992-04-13", "t_max_comment": "y special packages. carefully ironic instru" }
+{ "t_partkey": 19, "t_count": 29, "t_avg_quantity": 5.151724137931034d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 23672.43d, "t_avg_discount": 0.05275862068965517d, "t_avg_tax": 0.03896551724137932d, "t_max_shipdate": "1998-08-04", "t_min_commitdate": "1992-07-07", "t_min_receiptdate": "1992-08-15", "t_max_comment": "y along the excuses." }
+{ "t_partkey": 20, "t_count": 27, "t_avg_quantity": 4.955555555555556d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 22796.05111111111d, "t_avg_discount": 0.042222222222222223d, "t_avg_tax": 0.035555555555555556d, "t_max_shipdate": "1998-06-11", "t_min_commitdate": "1992-07-13", "t_min_receiptdate": "1992-06-21", "t_max_comment": "y. blithely r" }
+{ "t_partkey": 21, "t_count": 26, "t_avg_quantity": 4.730769230769231d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 21785.665384615386d, "t_avg_discount": 0.054615384615384614d, "t_avg_tax": 0.04076923076923077d, "t_max_shipdate": "1998-02-27", "t_min_commitdate": "1992-09-11", "t_min_receiptdate": "1992-08-08", "t_max_comment": "ymptotes haggle across the ca" }
+{ "t_partkey": 22, "t_count": 28, "t_avg_quantity": 5.300000000000001d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 24433.53d, "t_avg_discount": 0.057857142857142864d, "t_avg_tax": 0.045d, "t_max_shipdate": "1998-09-03", "t_min_commitdate": "1992-05-23", "t_min_receiptdate": "1992-07-12", "t_max_comment": "y final gifts are. carefully pe" }
+{ "t_partkey": 23, "t_count": 23, "t_avg_quantity": 5.22608695652174d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 24118.913913043478d, "t_avg_discount": 0.051304347826086956d, "t_avg_tax": 0.03173913043478261d, "t_max_shipdate": "1998-09-25", "t_min_commitdate": "1992-04-05", "t_min_receiptdate": "1992-05-02", "t_max_comment": "y unusual foxe" }
+{ "t_partkey": 24, "t_count": 35, "t_avg_quantity": 5.154285714285715d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23813.31542857143d, "t_avg_discount": 0.046d, "t_avg_tax": 0.04d, "t_max_shipdate": "1998-06-23", "t_min_commitdate": "1992-05-07", "t_min_receiptdate": "1992-04-21", "t_max_comment": "the slyly ironic pinto beans. fi" }
+{ "t_partkey": 25, "t_count": 26, "t_avg_quantity": 5.061538461538461d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 23410.121538461535d, "t_avg_discount": 0.054615384615384614d, "t_avg_tax": 0.034999999999999996d, "t_max_shipdate": "1998-06-26", "t_min_commitdate": "1992-03-18", "t_min_receiptdate": "1992-02-24", "t_max_comment": "y alongside of the special requests." }
+{ "t_partkey": 26, "t_count": 23, "t_avg_quantity": 4.6521739130434785d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 21540.030434782606d, "t_avg_discount": 0.03956521739130436d, "t_avg_tax": 0.043043478260869565d, "t_max_shipdate": "1998-10-09", "t_min_commitdate": "1992-03-16", "t_min_receiptdate": "1992-03-20", "t_max_comment": "y special pinto beans cajole " }
+{ "t_partkey": 27, "t_count": 18, "t_avg_quantity": 5.9222222222222225d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 27450.092222222225d, "t_avg_discount": 0.061111111111111116d, "t_avg_tax": 0.045000000000000005d, "t_max_shipdate": "1998-09-19", "t_min_commitdate": "1992-06-12", "t_min_receiptdate": "1992-07-31", "t_max_comment": "y regular foxes. slyly ironic deposits " }
+{ "t_partkey": 28, "t_count": 21, "t_avg_quantity": 5.476190476190476d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 25410.071428571428d, "t_avg_discount": 0.04285714285714286d, "t_avg_tax": 0.032857142857142856d, "t_max_shipdate": "1998-01-02", "t_min_commitdate": "1992-05-31", "t_min_receiptdate": "1992-04-05", "t_max_comment": "ular accounts about" }
+{ "t_partkey": 29, "t_count": 35, "t_avg_quantity": 5.171428571428572d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 24021.802857142855d, "t_avg_discount": 0.05657142857142857d, "t_avg_tax": 0.03942857142857143d, "t_max_shipdate": "1998-11-17", "t_min_commitdate": "1992-05-19", "t_min_receiptdate": "1992-06-06", "t_max_comment": "xcuses? quickly stealthy dependenci" }
+{ "t_partkey": 30, "t_count": 22, "t_avg_quantity": 4.754545454545455d, "t_max_suppkey": 9, "t_max_linenumber": 5, "t_avg_extendedprice": 22109.349545454545d, "t_avg_discount": 0.04727272727272727d, "t_avg_tax": 0.03318181818181818d, "t_max_shipdate": "1998-07-18", "t_min_commitdate": "1992-04-06", "t_min_receiptdate": "1992-05-01", "t_max_comment": "y. fluffily pending d" }
+{ "t_partkey": 31, "t_count": 31, "t_avg_quantity": 5.858064516129033d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 27270.16903225807d, "t_avg_discount": 0.050645161290322586d, "t_avg_tax": 0.035483870967741936d, "t_max_shipdate": "1998-08-08", "t_min_commitdate": "1992-05-23", "t_min_receiptdate": "1992-07-25", "t_max_comment": "xpress ideas detect b" }
+{ "t_partkey": 32, "t_count": 28, "t_avg_quantity": 5.050000000000001d, "t_max_suppkey": 8, "t_max_linenumber": 5, "t_avg_extendedprice": 23533.7575d, "t_avg_discount": 0.05249999999999999d, "t_avg_tax": 0.03321428571428571d, "t_max_shipdate": "1998-03-22", "t_min_commitdate": "1992-07-21", "t_min_receiptdate": "1992-09-27", "t_max_comment": "yers. accounts affix somet" }
+{ "t_partkey": 33, "t_count": 25, "t_avg_quantity": 5.04d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 23512.356d, "t_avg_discount": 0.044000000000000004d, "t_avg_tax": 0.03440000000000001d, "t_max_shipdate": "1998-08-01", "t_min_commitdate": "1992-04-26", "t_min_receiptdate": "1992-04-16", "t_max_comment": "yly enticing requ" }
+{ "t_partkey": 34, "t_count": 33, "t_avg_quantity": 4.575757575757576d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 21369.474242424243d, "t_avg_discount": 0.04666666666666667d, "t_avg_tax": 0.04363636363636364d, "t_max_shipdate": "1998-10-22", "t_min_commitdate": "1992-05-10", "t_min_receiptdate": "1992-07-24", "t_max_comment": "warthogs wake carefully acro" }
+{ "t_partkey": 35, "t_count": 26, "t_avg_quantity": 4.753846153846154d, "t_max_suppkey": 6, "t_max_linenumber": 6, "t_avg_extendedprice": 22224.94384615385d, "t_avg_discount": 0.05615384615384615d, "t_avg_tax": 0.04307692307692308d, "t_max_shipdate": "1998-08-13", "t_min_commitdate": "1992-04-12", "t_min_receiptdate": "1992-03-30", "t_max_comment": "y pending packages sleep blithely regular r" }
+{ "t_partkey": 36, "t_count": 25, "t_avg_quantity": 4.192d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 19619.188800000004d, "t_avg_discount": 0.054000000000000006d, "t_avg_tax": 0.034d, "t_max_shipdate": "1998-05-07", "t_min_commitdate": "1992-03-24", "t_min_receiptdate": "1992-03-20", "t_max_comment": "y slyly express deposits. final i" }
+{ "t_partkey": 37, "t_count": 17, "t_avg_quantity": 4.564705882352942d, "t_max_suppkey": 8, "t_max_linenumber": 6, "t_avg_extendedprice": 21386.331764705883d, "t_avg_discount": 0.06058823529411765d, "t_avg_tax": 0.05d, "t_max_shipdate": "1998-08-30", "t_min_commitdate": "1992-07-25", "t_min_receiptdate": "1992-09-10", "t_max_comment": "unts promise across the requests. blith" }
+{ "t_partkey": 38, "t_count": 26, "t_avg_quantity": 6.0076923076923086d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 28176.978076923075d, "t_avg_discount": 0.05653846153846154d, "t_avg_tax": 0.030384615384615385d, "t_max_shipdate": "1998-06-07", "t_min_commitdate": "1992-02-24", "t_min_receiptdate": "1992-04-26", "t_max_comment": "yly. blithely bold theodolites wa" }
+{ "t_partkey": 39, "t_count": 22, "t_avg_quantity": 4.454545454545455d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 20914.75909090909d, "t_avg_discount": 0.05318181818181819d, "t_avg_tax": 0.034999999999999996d, "t_max_shipdate": "1998-08-31", "t_min_commitdate": "1992-05-25", "t_min_receiptdate": "1992-06-03", "t_max_comment": "y. furiously ironic ideas gr" }
+{ "t_partkey": 40, "t_count": 34, "t_avg_quantity": 4.61764705882353d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 21703.864705882355d, "t_avg_discount": 0.0511764705882353d, "t_avg_tax": 0.03735294117647059d, "t_max_shipdate": "1998-06-12", "t_min_commitdate": "1992-03-04", "t_min_receiptdate": "1992-02-10", "t_max_comment": "y special a" }
+{ "t_partkey": 41, "t_count": 25, "t_avg_quantity": 5.936d, "t_max_suppkey": 10, "t_max_linenumber": 5, "t_avg_extendedprice": 27930.0672d, "t_avg_discount": 0.0484d, "t_avg_tax": 0.0444d, "t_max_shipdate": "1998-09-18", "t_min_commitdate": "1992-11-13", "t_min_receiptdate": "1993-01-09", "t_max_comment": "uffily even accounts. packages sleep blithe" }
+{ "t_partkey": 42, "t_count": 31, "t_avg_quantity": 3.7806451612903227d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 17807.594838709676d, "t_avg_discount": 0.05193548387096774d, "t_avg_tax": 0.0364516129032258d, "t_max_shipdate": "1998-08-12", "t_min_commitdate": "1992-10-29", "t_min_receiptdate": "1992-11-02", "t_max_comment": "y final platelets sublate among the " }
+{ "t_partkey": 43, "t_count": 32, "t_avg_quantity": 6.03125d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 28438.550000000003d, "t_avg_discount": 0.045000000000000005d, "t_avg_tax": 0.047812499999999994d, "t_max_shipdate": "1998-11-01", "t_min_commitdate": "1992-07-09", "t_min_receiptdate": "1992-07-07", "t_max_comment": "y regular packages. b" }
+{ "t_partkey": 44, "t_count": 23, "t_avg_quantity": 5.852173913043479d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 27623.43130434783d, "t_avg_discount": 0.05565217391304349d, "t_avg_tax": 0.04391304347826087d, "t_max_shipdate": "1998-08-12", "t_min_commitdate": "1992-02-16", "t_min_receiptdate": "1992-03-01", "t_max_comment": "unts. furiously silent" }
+{ "t_partkey": 45, "t_count": 34, "t_avg_quantity": 5.305882352941177d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 25071.35529411765d, "t_avg_discount": 0.05147058823529413d, "t_avg_tax": 0.039411764705882354d, "t_max_shipdate": "1998-09-09", "t_min_commitdate": "1992-05-07", "t_min_receiptdate": "1992-07-23", "t_max_comment": "y. bold pinto beans use " }
+{ "t_partkey": 46, "t_count": 34, "t_avg_quantity": 4.405882352941177d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 20840.704705882352d, "t_avg_discount": 0.05823529411764706d, "t_avg_tax": 0.0411764705882353d, "t_max_shipdate": "1998-10-25", "t_min_commitdate": "1992-04-21", "t_min_receiptdate": "1992-05-18", "t_max_comment": "xpress pinto beans. accounts a" }
+{ "t_partkey": 47, "t_count": 31, "t_avg_quantity": 5.129032258064516d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 24286.993548387094d, "t_avg_discount": 0.05064516129032258d, "t_avg_tax": 0.03967741935483871d, "t_max_shipdate": "1998-07-31", "t_min_commitdate": "1992-04-09", "t_min_receiptdate": "1992-04-05", "t_max_comment": "y ironic requests above the fluffily d" }
+{ "t_partkey": 48, "t_count": 37, "t_avg_quantity": 4.8756756756756765d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23111.67783783784d, "t_avg_discount": 0.04054054054054054d, "t_avg_tax": 0.03918918918918919d, "t_max_shipdate": "1998-08-17", "t_min_commitdate": "1992-05-30", "t_min_receiptdate": "1992-05-11", "t_max_comment": "y according to " }
+{ "t_partkey": 49, "t_count": 28, "t_avg_quantity": 5.4071428571428575d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 25657.97428571429d, "t_avg_discount": 0.0475d, "t_avg_tax": 0.04107142857142857d, "t_max_shipdate": "1998-09-03", "t_min_commitdate": "1992-02-27", "t_min_receiptdate": "1992-05-26", "t_max_comment": "unts alongs" }
+{ "t_partkey": 50, "t_count": 39, "t_avg_quantity": 4.4974358974358974d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 21363.944871794873d, "t_avg_discount": 0.04820512820512821d, "t_avg_tax": 0.04025641025641026d, "t_max_shipdate": "1998-09-12", "t_min_commitdate": "1992-05-13", "t_min_receiptdate": "1992-04-29", "t_max_comment": "yly pending theodolites." }
+{ "t_partkey": 51, "t_count": 35, "t_avg_quantity": 4.908571428571429d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23341.484285714283d, "t_avg_discount": 0.04914285714285715d, "t_avg_tax": 0.039428571428571424d, "t_max_shipdate": "1998-08-01", "t_min_commitdate": "1992-03-30", "t_min_receiptdate": "1992-03-31", "t_max_comment": "y ironic pin" }
+{ "t_partkey": 52, "t_count": 32, "t_avg_quantity": 5.91875d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 28174.7296875d, "t_avg_discount": 0.051250000000000004d, "t_avg_tax": 0.049375d, "t_max_shipdate": "1998-09-09", "t_min_commitdate": "1992-05-09", "t_min_receiptdate": "1992-06-02", "t_max_comment": "y pending orbits boost after the slyly" }
+{ "t_partkey": 53, "t_count": 24, "t_avg_quantity": 5.175000000000001d, "t_max_suppkey": 8, "t_max_linenumber": 6, "t_avg_extendedprice": 24660.16875d, "t_avg_discount": 0.04875000000000001d, "t_avg_tax": 0.04583333333333333d, "t_max_shipdate": "1998-11-10", "t_min_commitdate": "1992-02-23", "t_min_receiptdate": "1992-01-25", "t_max_comment": "y orbits. final depos" }
+{ "t_partkey": 54, "t_count": 34, "t_avg_quantity": 5.01764705882353d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 23935.430882352943d, "t_avg_discount": 0.05205882352941177d, "t_avg_tax": 0.04147058823529412d, "t_max_shipdate": "1998-05-26", "t_min_commitdate": "1992-03-28", "t_min_receiptdate": "1992-04-09", "t_max_comment": "y pending notornis ab" }
+{ "t_partkey": 55, "t_count": 30, "t_avg_quantity": 6.553333333333334d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 31293.805d, "t_avg_discount": 0.050666666666666665d, "t_avg_tax": 0.03933333333333334d, "t_max_shipdate": "1998-06-06", "t_min_commitdate": "1992-03-12", "t_min_receiptdate": "1992-02-06", "t_max_comment": "yly regular i" }
+{ "t_partkey": 56, "t_count": 24, "t_avg_quantity": 4.825d, "t_max_suppkey": 8, "t_max_linenumber": 6, "t_avg_extendedprice": 23064.70625d, "t_avg_discount": 0.05583333333333334d, "t_avg_tax": 0.037916666666666675d, "t_max_shipdate": "1998-07-22", "t_min_commitdate": "1992-03-01", "t_min_receiptdate": "1992-02-06", "t_max_comment": "ts. ironic, fina" }
+{ "t_partkey": 57, "t_count": 37, "t_avg_quantity": 5.5297297297297305d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 26461.139189189194d, "t_avg_discount": 0.05297297297297297d, "t_avg_tax": 0.03945945945945946d, "t_max_shipdate": "1998-08-16", "t_min_commitdate": "1992-03-20", "t_min_receiptdate": "1992-01-17", "t_max_comment": "y. doggedly pend" }
+{ "t_partkey": 58, "t_count": 28, "t_avg_quantity": 4.764285714285715d, "t_max_suppkey": 10, "t_max_linenumber": 5, "t_avg_extendedprice": 22822.119642857146d, "t_avg_discount": 0.05571428571428571d, "t_avg_tax": 0.04535714285714286d, "t_max_shipdate": "1998-11-27", "t_min_commitdate": "1992-02-23", "t_min_receiptdate": "1992-05-17", "t_max_comment": "xpress, bo" }
+{ "t_partkey": 59, "t_count": 37, "t_avg_quantity": 5.567567567567568d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 26697.87837837838d, "t_avg_discount": 0.042702702702702704d, "t_avg_tax": 0.049459459459459454d, "t_max_shipdate": "1998-07-12", "t_min_commitdate": "1992-02-26", "t_min_receiptdate": "1992-02-11", "t_max_comment": "y. ironic deposits haggle sl" }
+{ "t_partkey": 60, "t_count": 28, "t_avg_quantity": 5.0d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 24001.5d, "t_avg_discount": 0.05428571428571429d, "t_avg_tax": 0.042499999999999996d, "t_max_shipdate": "1998-07-08", "t_min_commitdate": "1992-03-02", "t_min_receiptdate": "1992-03-02", "t_max_comment": "y across the express accounts. fluff" }
+{ "t_partkey": 61, "t_count": 29, "t_avg_quantity": 5.593103448275862d, "t_max_suppkey": 10, "t_max_linenumber": 5, "t_avg_extendedprice": 26876.539999999997d, "t_avg_discount": 0.04931034482758621d, "t_avg_tax": 0.04103448275862069d, "t_max_shipdate": "1998-08-06", "t_min_commitdate": "1993-06-25", "t_min_receiptdate": "1993-08-03", "t_max_comment": "y even asymptotes. courts are unusual pa" }
+{ "t_partkey": 62, "t_count": 24, "t_avg_quantity": 5.175000000000001d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 24893.3025d, "t_avg_discount": 0.048749999999999995d, "t_avg_tax": 0.04d, "t_max_shipdate": "1998-05-27", "t_min_commitdate": "1992-02-17", "t_min_receiptdate": "1992-02-08", "t_max_comment": "yly final accounts hag" }
+{ "t_partkey": 63, "t_count": 26, "t_avg_quantity": 4.992307692307692d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 24039.45923076923d, "t_avg_discount": 0.052307692307692305d, "t_avg_tax": 0.04884615384615386d, "t_max_shipdate": "1998-05-08", "t_min_commitdate": "1992-03-07", "t_min_receiptdate": "1992-02-19", "t_max_comment": "y special packages wak" }
+{ "t_partkey": 64, "t_count": 31, "t_avg_quantity": 4.838709677419356d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23324.032258064515d, "t_avg_discount": 0.050645161290322586d, "t_avg_tax": 0.03709677419354839d, "t_max_shipdate": "1998-10-10", "t_min_commitdate": "1992-02-05", "t_min_receiptdate": "1992-02-29", "t_max_comment": "uietly regular foxes wake quick" }
+{ "t_partkey": 65, "t_count": 36, "t_avg_quantity": 5.033333333333334d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 24287.343333333338d, "t_avg_discount": 0.049166666666666664d, "t_avg_tax": 0.04083333333333334d, "t_max_shipdate": "1998-06-17", "t_min_commitdate": "1992-04-14", "t_min_receiptdate": "1992-03-13", "t_max_comment": "y unusual packages. packages" }
+{ "t_partkey": 66, "t_count": 29, "t_avg_quantity": 4.23448275862069d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 20453.82206896552d, "t_avg_discount": 0.05068965517241379d, "t_avg_tax": 0.051034482758620686d, "t_max_shipdate": "1998-05-23", "t_min_commitdate": "1992-06-18", "t_min_receiptdate": "1992-05-10", "t_max_comment": "y. pinto beans haggle after the" }
+{ "t_partkey": 67, "t_count": 21, "t_avg_quantity": 4.523809523809525d, "t_max_suppkey": 8, "t_max_linenumber": 5, "t_avg_extendedprice": 21873.976190476194d, "t_avg_discount": 0.05428571428571429d, "t_avg_tax": 0.04476190476190477d, "t_max_shipdate": "1998-08-27", "t_min_commitdate": "1992-06-07", "t_min_receiptdate": "1992-05-26", "t_max_comment": "theodolite" }
+{ "t_partkey": 68, "t_count": 36, "t_avg_quantity": 4.388888888888888d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 21243.53888888889d, "t_avg_discount": 0.059444444444444446d, "t_avg_tax": 0.04305555555555555d, "t_max_shipdate": "1998-09-10", "t_min_commitdate": "1992-06-03", "t_min_receiptdate": "1992-05-11", "t_max_comment": "y final ac" }
+{ "t_partkey": 69, "t_count": 24, "t_avg_quantity": 4.708333333333334d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 22813.287499999995d, "t_avg_discount": 0.059166666666666666d, "t_avg_tax": 0.03958333333333333d, "t_max_shipdate": "1998-09-02", "t_min_commitdate": "1992-06-04", "t_min_receiptdate": "1992-06-03", "t_max_comment": "yly furiously even id" }
+{ "t_partkey": 70, "t_count": 34, "t_avg_quantity": 5.029411764705883d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 24394.407352941176d, "t_avg_discount": 0.04558823529411765d, "t_avg_tax": 0.04352941176470588d, "t_max_shipdate": "1998-07-19", "t_min_commitdate": "1992-04-10", "t_min_receiptdate": "1992-04-29", "t_max_comment": "ts affix slyly accordi" }
+{ "t_partkey": 71, "t_count": 33, "t_avg_quantity": 5.024242424242424d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 24394.455454545456d, "t_avg_discount": 0.04515151515151515d, "t_avg_tax": 0.03818181818181819d, "t_max_shipdate": "1998-10-03", "t_min_commitdate": "1992-10-19", "t_min_receiptdate": "1992-12-05", "t_max_comment": "y regular foxes wake among the final" }
+{ "t_partkey": 72, "t_count": 36, "t_avg_quantity": 4.833333333333334d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 23491.691666666666d, "t_avg_discount": 0.053888888888888896d, "t_avg_tax": 0.038055555555555565d, "t_max_shipdate": "1998-07-21", "t_min_commitdate": "1992-09-04", "t_min_receiptdate": "1992-10-14", "t_max_comment": "yly along the ironic, fi" }
+{ "t_partkey": 73, "t_count": 27, "t_avg_quantity": 4.5851851851851855d, "t_max_suppkey": 4, "t_max_linenumber": 7, "t_avg_extendedprice": 22308.530740740738d, "t_avg_discount": 0.04481481481481482d, "t_avg_tax": 0.03333333333333333d, "t_max_shipdate": "1998-10-12", "t_min_commitdate": "1992-03-01", "t_min_receiptdate": "1992-01-09", "t_max_comment": "y even packages promise" }
+{ "t_partkey": 74, "t_count": 25, "t_avg_quantity": 6.016d, "t_max_suppkey": 5, "t_max_linenumber": 7, "t_avg_extendedprice": 29300.025600000004d, "t_avg_discount": 0.0528d, "t_avg_tax": 0.0388d, "t_max_shipdate": "1998-03-23", "t_min_commitdate": "1992-03-22", "t_min_receiptdate": "1992-03-25", "t_max_comment": "uests. blithely unus" }
+{ "t_partkey": 75, "t_count": 29, "t_avg_quantity": 5.131034482758621d, "t_max_suppkey": 6, "t_max_linenumber": 6, "t_avg_extendedprice": 25015.58896551724d, "t_avg_discount": 0.06310344827586208d, "t_avg_tax": 0.02896551724137931d, "t_max_shipdate": "1998-10-19", "t_min_commitdate": "1992-02-18", "t_min_receiptdate": "1992-03-31", "t_max_comment": "usly across the slyly busy accounts! fin" }
+{ "t_partkey": 76, "t_count": 21, "t_avg_quantity": 4.9714285714285715d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 24262.31142857143d, "t_avg_discount": 0.04d, "t_avg_tax": 0.041428571428571426d, "t_max_shipdate": "1998-05-31", "t_min_commitdate": "1992-08-25", "t_min_receiptdate": "1992-11-16", "t_max_comment": "y even accounts thrash care" }
+{ "t_partkey": 77, "t_count": 20, "t_avg_quantity": 6.08d, "t_max_suppkey": 8, "t_max_linenumber": 6, "t_avg_extendedprice": 29702.927999999996d, "t_avg_discount": 0.053500000000000006d, "t_avg_tax": 0.037d, "t_max_shipdate": "1998-06-16", "t_min_commitdate": "1992-09-20", "t_min_receiptdate": "1992-08-19", "t_max_comment": "usly at the blithely pending pl" }
+{ "t_partkey": 78, "t_count": 35, "t_avg_quantity": 4.485714285714286d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 21936.71285714286d, "t_avg_discount": 0.05942857142857143d, "t_avg_tax": 0.042285714285714295d, "t_max_shipdate": "1998-08-03", "t_min_commitdate": "1992-03-24", "t_min_receiptdate": "1992-03-21", "t_max_comment": "yly after the fluffily regul" }
+{ "t_partkey": 79, "t_count": 37, "t_avg_quantity": 5.65945945945946d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 27705.03486486486d, "t_avg_discount": 0.04810810810810811d, "t_avg_tax": 0.042432432432432436d, "t_max_shipdate": "1998-10-09", "t_min_commitdate": "1992-05-23", "t_min_receiptdate": "1992-08-24", "t_max_comment": "y slyly final" }
+{ "t_partkey": 80, "t_count": 29, "t_avg_quantity": 6.172413793103448d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 30247.296551724135d, "t_avg_discount": 0.04655172413793104d, "t_avg_tax": 0.03413793103448276d, "t_max_shipdate": "1998-10-08", "t_min_commitdate": "1992-07-01", "t_min_receiptdate": "1992-06-07", "t_max_comment": "yly ironic frets. pending foxes after " }
+{ "t_partkey": 81, "t_count": 21, "t_avg_quantity": 5.371428571428572d, "t_max_suppkey": 2, "t_max_linenumber": 7, "t_avg_extendedprice": 26349.005714285708d, "t_avg_discount": 0.044285714285714296d, "t_avg_tax": 0.04095238095238095d, "t_max_shipdate": "1998-06-02", "t_min_commitdate": "1992-04-18", "t_min_receiptdate": "1992-04-22", "t_max_comment": "yly even accounts. spe" }
+{ "t_partkey": 82, "t_count": 23, "t_avg_quantity": 4.3130434782608695d, "t_max_suppkey": 3, "t_max_linenumber": 7, "t_avg_extendedprice": 21178.768695652176d, "t_avg_discount": 0.05260869565217391d, "t_avg_tax": 0.043043478260869565d, "t_max_shipdate": "1998-04-09", "t_min_commitdate": "1992-08-17", "t_min_receiptdate": "1992-07-22", "t_max_comment": "ut the carefully special foxes. idle," }
+{ "t_partkey": 83, "t_count": 33, "t_avg_quantity": 5.115151515151515d, "t_max_suppkey": 4, "t_max_linenumber": 7, "t_avg_extendedprice": 25143.01575757576d, "t_avg_discount": 0.05303030303030303d, "t_avg_tax": 0.043030303030303044d, "t_max_shipdate": "1998-10-12", "t_min_commitdate": "1992-07-05", "t_min_receiptdate": "1992-06-25", "t_max_comment": "yly. slyly regular courts use silentl" }
+{ "t_partkey": 84, "t_count": 28, "t_avg_quantity": 5.585714285714285d, "t_max_suppkey": 5, "t_max_linenumber": 7, "t_avg_extendedprice": 27483.948571428573d, "t_avg_discount": 0.05464285714285715d, "t_avg_tax": 0.039999999999999994d, "t_max_shipdate": "1998-10-03", "t_min_commitdate": "1992-08-25", "t_min_receiptdate": "1992-09-16", "t_max_comment": "yly brave theod" }
+{ "t_partkey": 85, "t_count": 28, "t_avg_quantity": 4.121428571428572d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 20299.684285714284d, "t_avg_discount": 0.041785714285714294d, "t_avg_tax": 0.041785714285714294d, "t_max_shipdate": "1998-07-23", "t_min_commitdate": "1992-04-24", "t_min_receiptdate": "1992-03-10", "t_max_comment": "y. enticingly final depos" }
+{ "t_partkey": 86, "t_count": 36, "t_avg_quantity": 5.427777777777778d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 26761.115555555552d, "t_avg_discount": 0.049999999999999996d, "t_avg_tax": 0.04555555555555556d, "t_max_shipdate": "1998-07-10", "t_min_commitdate": "1992-04-14", "t_min_receiptdate": "1992-06-23", "t_max_comment": "unts. furiously express accounts w" }
+{ "t_partkey": 87, "t_count": 34, "t_avg_quantity": 4.658823529411765d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 22993.157647058822d, "t_avg_discount": 0.052352941176470595d, "t_avg_tax": 0.036470588235294116d, "t_max_shipdate": "1998-09-18", "t_min_commitdate": "1992-10-18", "t_min_receiptdate": "1992-10-15", "t_max_comment": "y final de" }
+{ "t_partkey": 88, "t_count": 29, "t_avg_quantity": 4.613793103448276d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 22793.983448275863d, "t_avg_discount": 0.04724137931034483d, "t_avg_tax": 0.039655172413793106d, "t_max_shipdate": "1998-10-27", "t_min_commitdate": "1992-06-03", "t_min_receiptdate": "1992-05-16", "t_max_comment": "y slyly ironic accounts. foxes haggle slyl" }
+{ "t_partkey": 89, "t_count": 28, "t_avg_quantity": 4.864285714285715d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 24055.838571428576d, "t_avg_discount": 0.04642857142857143d, "t_avg_tax": 0.05035714285714286d, "t_max_shipdate": "1998-10-23", "t_min_commitdate": "1992-03-18", "t_min_receiptdate": "1992-05-07", "t_max_comment": "y carefully final ideas. f" }
+{ "t_partkey": 90, "t_count": 48, "t_avg_quantity": 5.4d, "t_max_suppkey": 1, "t_max_linenumber": 7, "t_avg_extendedprice": 26732.430000000004d, "t_avg_discount": 0.044583333333333336d, "t_avg_tax": 0.04229166666666667d, "t_max_shipdate": "1998-10-09", "t_min_commitdate": "1992-04-25", "t_min_receiptdate": "1992-03-17", "t_max_comment": "y regular notornis k" }
+{ "t_partkey": 91, "t_count": 28, "t_avg_quantity": 4.1571428571428575d, "t_max_suppkey": 5, "t_max_linenumber": 7, "t_avg_extendedprice": 20600.513571428568d, "t_avg_discount": 0.055714285714285716d, "t_avg_tax": 0.04107142857142858d, "t_max_shipdate": "1998-09-07", "t_min_commitdate": "1992-06-08", "t_min_receiptdate": "1992-06-20", "t_max_comment": "ven deposits about the regular, ironi" }
+{ "t_partkey": 92, "t_count": 30, "t_avg_quantity": 5.466666666666667d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 27117.126666666667d, "t_avg_discount": 0.060666666666666674d, "t_avg_tax": 0.044000000000000004d, "t_max_shipdate": "1997-11-30", "t_min_commitdate": "1992-03-15", "t_min_receiptdate": "1992-02-14", "t_max_comment": "warhorses wake never for the care" }
+{ "t_partkey": 93, "t_count": 31, "t_avg_quantity": 5.219354838709678d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 25916.445483870968d, "t_avg_discount": 0.05903225806451613d, "t_avg_tax": 0.04096774193548387d, "t_max_shipdate": "1998-11-25", "t_min_commitdate": "1992-05-29", "t_min_receiptdate": "1992-06-02", "t_max_comment": "ut the slyly bold pinto beans; fi" }
+{ "t_partkey": 94, "t_count": 32, "t_avg_quantity": 5.7d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 28331.565d, "t_avg_discount": 0.05d, "t_avg_tax": 0.040625d, "t_max_shipdate": "1998-03-09", "t_min_commitdate": "1992-04-09", "t_min_receiptdate": "1992-05-23", "t_max_comment": "y furious depen" }
+{ "t_partkey": 95, "t_count": 31, "t_avg_quantity": 4.7290322580645165d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23529.063548387097d, "t_avg_discount": 0.050967741935483875d, "t_avg_tax": 0.038387096774193545d, "t_max_shipdate": "1998-10-07", "t_min_commitdate": "1992-02-14", "t_min_receiptdate": "1992-03-23", "t_max_comment": "y final excuses. ironic, special requests a" }
+{ "t_partkey": 96, "t_count": 38, "t_avg_quantity": 5.368421052631579d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 26737.15263157895d, "t_avg_discount": 0.04315789473684212d, "t_avg_tax": 0.04026315789473684d, "t_max_shipdate": "1998-11-03", "t_min_commitdate": "1992-05-16", "t_min_receiptdate": "1992-07-02", "t_max_comment": "y. slyly iron" }
+{ "t_partkey": 97, "t_count": 39, "t_avg_quantity": 4.774358974358974d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 23802.327948717946d, "t_avg_discount": 0.04717948717948718d, "t_avg_tax": 0.03794871794871795d, "t_max_shipdate": "1998-05-15", "t_min_commitdate": "1992-03-16", "t_min_receiptdate": "1992-02-19", "t_max_comment": "y slyly express theodolites. slyly bo" }
+{ "t_partkey": 98, "t_count": 29, "t_avg_quantity": 4.441379310344828d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 22164.481379310342d, "t_avg_discount": 0.0506896551724138d, "t_avg_tax": 0.03862068965517241d, "t_max_shipdate": "1998-10-04", "t_min_commitdate": "1992-08-20", "t_min_receiptdate": "1992-10-08", "t_max_comment": "ven requests should sleep along " }
+{ "t_partkey": 99, "t_count": 22, "t_avg_quantity": 4.609090909090909d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 23024.48318181818d, "t_avg_discount": 0.05318181818181818d, "t_avg_tax": 0.038181818181818185d, "t_max_shipdate": "1998-02-16", "t_min_commitdate": "1992-03-03", "t_min_receiptdate": "1992-05-24", "t_max_comment": "yly pending excu" }
+{ "t_partkey": 100, "t_count": 41, "t_avg_quantity": 5.51219512195122d, "t_max_suppkey": 4, "t_max_linenumber": 6, "t_avg_extendedprice": 27563.731707317078d, "t_avg_discount": 0.05048780487804879d, "t_avg_tax": 0.04048780487804878d, "t_max_shipdate": "1998-06-24", "t_min_commitdate": "1992-03-06", "t_min_receiptdate": "1992-04-13", "t_max_comment": "xpress accounts sleep slyly re" }
+{ "t_partkey": 101, "t_count": 28, "t_avg_quantity": 5.707142857142857d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 28567.103571428568d, "t_avg_discount": 0.054285714285714284d, "t_avg_tax": 0.04571428571428572d, "t_max_shipdate": "1998-02-25", "t_min_commitdate": "1992-07-26", "t_min_receiptdate": "1992-08-20", "t_max_comment": "uses are care" }
+{ "t_partkey": 102, "t_count": 38, "t_avg_quantity": 4.263157894736842d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 21360.552631578947d, "t_avg_discount": 0.05052631578947368d, "t_avg_tax": 0.04315789473684211d, "t_max_shipdate": "1998-09-01", "t_min_commitdate": "1992-09-09", "t_min_receiptdate": "1992-08-28", "t_max_comment": "y unusual packa" }
+{ "t_partkey": 103, "t_count": 25, "t_avg_quantity": 6.16d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 30895.48d, "t_avg_discount": 0.0408d, "t_avg_tax": 0.0432d, "t_max_shipdate": "1998-11-16", "t_min_commitdate": "1992-05-16", "t_min_receiptdate": "1992-04-20", "t_max_comment": "yly. unusu" }
+{ "t_partkey": 104, "t_count": 19, "t_avg_quantity": 5.178947368421053d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 26000.9052631579d, "t_avg_discount": 0.04263157894736842d, "t_avg_tax": 0.034210526315789476d, "t_max_shipdate": "1998-04-17", "t_min_commitdate": "1992-03-29", "t_min_receiptdate": "1992-04-13", "t_max_comment": "yly even gifts after the sl" }
+{ "t_partkey": 105, "t_count": 36, "t_avg_quantity": 5.194444444444445d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 26104.68055555556d, "t_avg_discount": 0.05055555555555556d, "t_avg_tax": 0.03888888888888889d, "t_max_shipdate": "1998-08-25", "t_min_commitdate": "1992-03-19", "t_min_receiptdate": "1992-02-25", "t_max_comment": "yly into the carefully even " }
+{ "t_partkey": 106, "t_count": 27, "t_avg_quantity": 4.451851851851852d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 22395.040740740744d, "t_avg_discount": 0.039259259259259265d, "t_avg_tax": 0.039259259259259265d, "t_max_shipdate": "1998-07-25", "t_min_commitdate": "1992-05-18", "t_min_receiptdate": "1992-07-21", "t_max_comment": "y ironic foxes caj" }
+{ "t_partkey": 107, "t_count": 27, "t_avg_quantity": 4.733333333333333d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 23834.7d, "t_avg_discount": 0.04518518518518518d, "t_avg_tax": 0.037037037037037035d, "t_max_shipdate": "1998-09-29", "t_min_commitdate": "1992-06-25", "t_min_receiptdate": "1992-06-11", "t_max_comment": "y ruthless dolphins to " }
+{ "t_partkey": 108, "t_count": 28, "t_avg_quantity": 4.692857142857143d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 23654.346428571425d, "t_avg_discount": 0.05750000000000001d, "t_avg_tax": 0.046071428571428576d, "t_max_shipdate": "1998-09-07", "t_min_commitdate": "1992-06-14", "t_min_receiptdate": "1992-08-03", "t_max_comment": "y pending platelets x-ray ironically! pend" }
+{ "t_partkey": 109, "t_count": 35, "t_avg_quantity": 5.331428571428572d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 26899.722857142857d, "t_avg_discount": 0.048571428571428564d, "t_avg_tax": 0.044571428571428574d, "t_max_shipdate": "1997-08-27", "t_min_commitdate": "1992-06-18", "t_min_receiptdate": "1992-07-05", "t_max_comment": "ts wake furiously " }
+{ "t_partkey": 110, "t_count": 29, "t_avg_quantity": 4.86896551724138d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 24590.95379310345d, "t_avg_discount": 0.05344827586206897d, "t_avg_tax": 0.03517241379310345d, "t_max_shipdate": "1998-05-03", "t_min_commitdate": "1992-10-29", "t_min_receiptdate": "1992-09-27", "t_max_comment": "xcuses sleep quickly along th" }
+{ "t_partkey": 111, "t_count": 26, "t_avg_quantity": 6.130769230769231d, "t_max_suppkey": 8, "t_max_linenumber": 5, "t_avg_extendedprice": 30994.410384615392d, "t_avg_discount": 0.05038461538461539d, "t_avg_tax": 0.03576923076923077d, "t_max_shipdate": "1998-06-18", "t_min_commitdate": "1992-05-11", "t_min_receiptdate": "1992-07-29", "t_max_comment": "usy pinto beans b" }
+{ "t_partkey": 112, "t_count": 28, "t_avg_quantity": 5.457142857142857d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 27616.144285714287d, "t_avg_discount": 0.038571428571428576d, "t_avg_tax": 0.041785714285714294d, "t_max_shipdate": "1998-10-18", "t_min_commitdate": "1992-10-23", "t_min_receiptdate": "1992-09-29", "t_max_comment": "zle carefully sauternes. quickly" }
+{ "t_partkey": 113, "t_count": 28, "t_avg_quantity": 5.078571428571429d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 25725.7575d, "t_avg_discount": 0.04785714285714287d, "t_avg_tax": 0.048571428571428564d, "t_max_shipdate": "1998-06-28", "t_min_commitdate": "1992-08-10", "t_min_receiptdate": "1992-06-14", "t_max_comment": "yly silent deposit" }
+{ "t_partkey": 114, "t_count": 24, "t_avg_quantity": 5.041666666666667d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 25564.02291666667d, "t_avg_discount": 0.057916666666666665d, "t_avg_tax": 0.03958333333333334d, "t_max_shipdate": "1998-09-27", "t_min_commitdate": "1992-10-25", "t_min_receiptdate": "1992-12-04", "t_max_comment": "y unusual, ironic" }
+{ "t_partkey": 115, "t_count": 34, "t_avg_quantity": 4.594117647058823d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23317.673823529414d, "t_avg_discount": 0.045588235294117645d, "t_avg_tax": 0.03588235294117647d, "t_max_shipdate": "1998-04-27", "t_min_commitdate": "1992-04-19", "t_min_receiptdate": "1992-03-30", "t_max_comment": "y. final pearls kindle. accounts " }
+{ "t_partkey": 116, "t_count": 25, "t_avg_quantity": 5.5200000000000005d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 28044.635999999995d, "t_avg_discount": 0.0512d, "t_avg_tax": 0.046d, "t_max_shipdate": "1998-06-24", "t_min_commitdate": "1992-03-10", "t_min_receiptdate": "1992-04-14", "t_max_comment": "yly even epitaphs for the " }
+{ "t_partkey": 117, "t_count": 35, "t_avg_quantity": 5.337142857142858d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 27142.306857142856d, "t_avg_discount": 0.05742857142857143d, "t_avg_tax": 0.044285714285714296d, "t_max_shipdate": "1998-10-30", "t_min_commitdate": "1992-05-06", "t_min_receiptdate": "1992-05-11", "t_max_comment": "y ironic accounts. furiously even packa" }
+{ "t_partkey": 118, "t_count": 38, "t_avg_quantity": 4.321052631578947d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 21996.53447368421d, "t_avg_discount": 0.05342105263157895d, "t_avg_tax": 0.035526315789473684d, "t_max_shipdate": "1998-08-31", "t_min_commitdate": "1992-05-19", "t_min_receiptdate": "1992-07-02", "t_max_comment": "y. furiously even pinto be" }
+{ "t_partkey": 119, "t_count": 30, "t_avg_quantity": 5.4d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 27515.970000000005d, "t_avg_discount": 0.058333333333333334d, "t_avg_tax": 0.043000000000000003d, "t_max_shipdate": "1998-08-15", "t_min_commitdate": "1992-05-19", "t_min_receiptdate": "1992-06-05", "t_max_comment": "y regular theodolites w" }
+{ "t_partkey": 120, "t_count": 36, "t_avg_quantity": 5.75d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 29328.449999999997d, "t_avg_discount": 0.05222222222222223d, "t_avg_tax": 0.045000000000000005d, "t_max_shipdate": "1998-08-25", "t_min_commitdate": "1992-04-04", "t_min_receiptdate": "1992-04-02", "t_max_comment": "yly regular p" }
+{ "t_partkey": 121, "t_count": 34, "t_avg_quantity": 4.576470588235295d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 23365.628235294116d, "t_avg_discount": 0.052352941176470595d, "t_avg_tax": 0.03470588235294118d, "t_max_shipdate": "1998-08-22", "t_min_commitdate": "1992-05-22", "t_min_receiptdate": "1992-05-03", "t_max_comment": "y quickly regular packages. car" }
+{ "t_partkey": 122, "t_count": 44, "t_avg_quantity": 4.677272727272728d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 23903.67d, "t_avg_discount": 0.05113636363636364d, "t_avg_tax": 0.03977272727272727d, "t_max_shipdate": "1998-10-29", "t_min_commitdate": "1992-03-23", "t_min_receiptdate": "1992-04-07", "t_max_comment": "y bold package" }
+{ "t_partkey": 123, "t_count": 30, "t_avg_quantity": 5.213333333333334d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 26669.327999999994d, "t_avg_discount": 0.04466666666666666d, "t_avg_tax": 0.04066666666666666d, "t_max_shipdate": "1998-09-23", "t_min_commitdate": "1992-03-18", "t_min_receiptdate": "1992-02-29", "t_max_comment": "y quickly regular theodolites. final t" }
+{ "t_partkey": 124, "t_count": 32, "t_avg_quantity": 4.9375d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 25282.962499999998d, "t_avg_discount": 0.0553125d, "t_avg_tax": 0.043125d, "t_max_shipdate": "1998-11-15", "t_min_commitdate": "1992-07-21", "t_min_receiptdate": "1992-06-18", "t_max_comment": "y express ideas impress" }
+{ "t_partkey": 125, "t_count": 20, "t_avg_quantity": 6.07d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 31112.392000000003d, "t_avg_discount": 0.035500000000000004d, "t_avg_tax": 0.034d, "t_max_shipdate": "1998-05-05", "t_min_commitdate": "1992-04-24", "t_min_receiptdate": "1992-04-12", "t_max_comment": "y final deposits wake furiously! slyl" }
+{ "t_partkey": 126, "t_count": 31, "t_avg_quantity": 4.812903225806452d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 24693.08129032258d, "t_avg_discount": 0.04387096774193548d, "t_avg_tax": 0.03483870967741936d, "t_max_shipdate": "1998-01-30", "t_min_commitdate": "1992-07-09", "t_min_receiptdate": "1992-08-21", "t_max_comment": "x furiously bold packages. expres" }
+{ "t_partkey": 127, "t_count": 25, "t_avg_quantity": 4.744d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 24363.2864d, "t_avg_discount": 0.055600000000000004d, "t_avg_tax": 0.034d, "t_max_shipdate": "1998-05-25", "t_min_commitdate": "1992-06-30", "t_min_receiptdate": "1992-06-10", "t_max_comment": "ts integrate. courts haggl" }
+{ "t_partkey": 128, "t_count": 27, "t_avg_quantity": 5.155555555555556d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 26502.648888888885d, "t_avg_discount": 0.047407407407407405d, "t_avg_tax": 0.042222222222222223d, "t_max_shipdate": "1998-07-09", "t_min_commitdate": "1992-03-24", "t_min_receiptdate": "1992-03-15", "t_max_comment": "usly bold requests sleep dogge" }
+{ "t_partkey": 129, "t_count": 35, "t_avg_quantity": 5.262857142857143d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 27080.557714285715d, "t_avg_discount": 0.05600000000000001d, "t_avg_tax": 0.03514285714285714d, "t_max_shipdate": "1998-08-25", "t_min_commitdate": "1992-04-17", "t_min_receiptdate": "1992-04-02", "t_max_comment": "ven theodolites nag quickly. fluffi" }
+{ "t_partkey": 130, "t_count": 28, "t_avg_quantity": 6.0d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 30903.9d, "t_avg_discount": 0.04464285714285714d, "t_avg_tax": 0.04357142857142858d, "t_max_shipdate": "1998-07-19", "t_min_commitdate": "1992-05-30", "t_min_receiptdate": "1992-04-05", "t_max_comment": "ven theodolites around the slyly" }
+{ "t_partkey": 131, "t_count": 33, "t_avg_quantity": 4.715151515151515d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 24309.67090909091d, "t_avg_discount": 0.04454545454545455d, "t_avg_tax": 0.03878787878787879d, "t_max_shipdate": "1998-08-20", "t_min_commitdate": "1992-02-24", "t_min_receiptdate": "1992-03-09", "t_max_comment": "usual pinto beans." }
+{ "t_partkey": 132, "t_count": 30, "t_avg_quantity": 4.0200000000000005d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 20745.813000000002d, "t_avg_discount": 0.04733333333333334d, "t_avg_tax": 0.03766666666666667d, "t_max_shipdate": "1998-07-21", "t_min_commitdate": "1992-02-12", "t_min_receiptdate": "1992-04-30", "t_max_comment": "yly ironic foxes. regular requests h" }
+{ "t_partkey": 133, "t_count": 28, "t_avg_quantity": 5.6000000000000005d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 28927.639999999996d, "t_avg_discount": 0.048571428571428564d, "t_avg_tax": 0.029285714285714283d, "t_max_shipdate": "1998-05-12", "t_min_commitdate": "1992-07-07", "t_min_receiptdate": "1992-07-08", "t_max_comment": "xcuses would boost against the fluffily eve" }
+{ "t_partkey": 134, "t_count": 32, "t_avg_quantity": 5.6312500000000005d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 29117.222812499997d, "t_avg_discount": 0.051875000000000004d, "t_avg_tax": 0.0346875d, "t_max_shipdate": "1998-07-22", "t_min_commitdate": "1992-03-16", "t_min_receiptdate": "1992-06-06", "t_max_comment": "usly busy account" }
+{ "t_partkey": 135, "t_count": 29, "t_avg_quantity": 4.793103448275862d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 24807.42586206897d, "t_avg_discount": 0.054827586206896546d, "t_avg_tax": 0.03482758620689656d, "t_max_shipdate": "1998-08-03", "t_min_commitdate": "1992-04-10", "t_min_receiptdate": "1992-05-14", "t_max_comment": "y; excuses use. ironic, close instru" }
+{ "t_partkey": 136, "t_count": 35, "t_avg_quantity": 5.16d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 26732.154000000002d, "t_avg_discount": 0.04542857142857143d, "t_avg_tax": 0.036d, "t_max_shipdate": "1998-08-06", "t_min_commitdate": "1992-04-24", "t_min_receiptdate": "1992-05-24", "t_max_comment": "y final pinto " }
+{ "t_partkey": 137, "t_count": 38, "t_avg_quantity": 5.736842105263158d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 29749.2552631579d, "t_avg_discount": 0.04026315789473685d, "t_avg_tax": 0.04421052631578948d, "t_max_shipdate": "1997-08-19", "t_min_commitdate": "1992-06-29", "t_min_receiptdate": "1992-06-19", "t_max_comment": "uests cajole carefully." }
+{ "t_partkey": 138, "t_count": 42, "t_avg_quantity": 5.666666666666667d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 29413.68333333333d, "t_avg_discount": 0.05452380952380952d, "t_avg_tax": 0.03928571428571429d, "t_max_shipdate": "1998-08-29", "t_min_commitdate": "1992-04-12", "t_min_receiptdate": "1992-07-09", "t_max_comment": "yly idle deposits. final, final fox" }
+{ "t_partkey": 139, "t_count": 34, "t_avg_quantity": 5.364705882352942d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 27873.13411764706d, "t_avg_discount": 0.050588235294117656d, "t_avg_tax": 0.047058823529411764d, "t_max_shipdate": "1998-03-01", "t_min_commitdate": "1992-04-15", "t_min_receiptdate": "1992-04-28", "t_max_comment": "y express accounts above the exp" }
+{ "t_partkey": 140, "t_count": 35, "t_avg_quantity": 5.034285714285715d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 26181.809714285715d, "t_avg_discount": 0.054571428571428576d, "t_avg_tax": 0.04257142857142857d, "t_max_shipdate": "1998-06-24", "t_min_commitdate": "1992-04-14", "t_min_receiptdate": "1992-03-21", "t_max_comment": "y among the furiously special" }
+{ "t_partkey": 141, "t_count": 38, "t_avg_quantity": 5.5473684210526315d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 28877.935789473686d, "t_avg_discount": 0.037368421052631585d, "t_avg_tax": 0.052105263157894745d, "t_max_shipdate": "1998-10-26", "t_min_commitdate": "1992-02-26", "t_min_receiptdate": "1992-01-20", "t_max_comment": "yly silent ideas affix furiousl" }
+{ "t_partkey": 142, "t_count": 26, "t_avg_quantity": 6.138461538461539d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 31985.681538461537d, "t_avg_discount": 0.05d, "t_avg_tax": 0.047692307692307694d, "t_max_shipdate": "1998-06-06", "t_min_commitdate": "1992-12-21", "t_min_receiptdate": "1992-10-16", "t_max_comment": "usly bold instructions affix idly unusual, " }
+{ "t_partkey": 143, "t_count": 36, "t_avg_quantity": 4.95d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 25817.715000000004d, "t_avg_discount": 0.045000000000000005d, "t_avg_tax": 0.03972222222222222d, "t_max_shipdate": "1998-07-16", "t_min_commitdate": "1992-04-26", "t_min_receiptdate": "1992-05-17", "t_max_comment": "y pending foxes nag blithely " }
+{ "t_partkey": 144, "t_count": 32, "t_avg_quantity": 4.91875d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 25679.318125d, "t_avg_discount": 0.0465625d, "t_avg_tax": 0.0434375d, "t_max_shipdate": "1998-09-22", "t_min_commitdate": "1992-07-19", "t_min_receiptdate": "1992-07-30", "t_max_comment": "ve the fluffily " }
+{ "t_partkey": 145, "t_count": 24, "t_avg_quantity": 5.566666666666666d, "t_max_suppkey": 8, "t_max_linenumber": 6, "t_avg_extendedprice": 29089.73d, "t_avg_discount": 0.04541666666666667d, "t_avg_tax": 0.03666666666666666d, "t_max_shipdate": "1998-07-23", "t_min_commitdate": "1992-03-16", "t_min_receiptdate": "1992-01-27", "t_max_comment": "yly even platelets wake. " }
+{ "t_partkey": 146, "t_count": 27, "t_avg_quantity": 4.792592592592593d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 25068.614074074078d, "t_avg_discount": 0.05925925925925926d, "t_avg_tax": 0.04407407407407408d, "t_max_shipdate": "1998-07-09", "t_min_commitdate": "1992-05-18", "t_min_receiptdate": "1992-05-27", "t_max_comment": "ut the slyly specia" }
+{ "t_partkey": 147, "t_count": 31, "t_avg_quantity": 4.625806451612903d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 24219.334838709678d, "t_avg_discount": 0.05451612903225806d, "t_avg_tax": 0.04741935483870968d, "t_max_shipdate": "1998-06-18", "t_min_commitdate": "1992-07-06", "t_min_receiptdate": "1992-06-23", "t_max_comment": "yly special excuses. fluffily " }
+{ "t_partkey": 148, "t_count": 43, "t_avg_quantity": 5.158139534883722d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 27032.261860465118d, "t_avg_discount": 0.0516279069767442d, "t_avg_tax": 0.04093023255813954d, "t_max_shipdate": "1998-07-21", "t_min_commitdate": "1992-03-16", "t_min_receiptdate": "1992-01-27", "t_max_comment": "y special theodolites. carefully" }
+{ "t_partkey": 149, "t_count": 33, "t_avg_quantity": 4.363636363636363d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 22890.327272727274d, "t_avg_discount": 0.05d, "t_avg_tax": 0.03909090909090909d, "t_max_shipdate": "1998-06-06", "t_min_commitdate": "1992-03-06", "t_min_receiptdate": "1992-04-19", "t_max_comment": "y regular requests. furious" }
+{ "t_partkey": 150, "t_count": 29, "t_avg_quantity": 5.027586206896552d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 26398.598275862067d, "t_avg_discount": 0.05517241379310344d, "t_avg_tax": 0.04206896551724138d, "t_max_shipdate": "1998-08-06", "t_min_commitdate": "1992-05-26", "t_min_receiptdate": "1992-05-09", "t_max_comment": "thely around the bli" }
+{ "t_partkey": 151, "t_count": 24, "t_avg_quantity": 4.175d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 21942.756249999995d, "t_avg_discount": 0.045000000000000005d, "t_avg_tax": 0.03291666666666667d, "t_max_shipdate": "1998-08-09", "t_min_commitdate": "1992-02-05", "t_min_receiptdate": "1992-02-13", "t_max_comment": "y unusual foxes " }
+{ "t_partkey": 152, "t_count": 27, "t_avg_quantity": 4.970370370370371d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 26147.875925925924d, "t_avg_discount": 0.050370370370370364d, "t_avg_tax": 0.03888888888888889d, "t_max_shipdate": "1998-04-20", "t_min_commitdate": "1992-05-10", "t_min_receiptdate": "1992-07-04", "t_max_comment": "ully. carefully final accounts accordi" }
+{ "t_partkey": 153, "t_count": 35, "t_avg_quantity": 5.514285714285715d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 29036.85d, "t_avg_discount": 0.045714285714285714d, "t_avg_tax": 0.03885714285714286d, "t_max_shipdate": "1998-08-17", "t_min_commitdate": "1992-02-18", "t_min_receiptdate": "1992-03-02", "t_max_comment": "y above the bli" }
+{ "t_partkey": 154, "t_count": 30, "t_avg_quantity": 4.54d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 23929.205d, "t_avg_discount": 0.04933333333333333d, "t_avg_tax": 0.041666666666666664d, "t_max_shipdate": "1998-09-29", "t_min_commitdate": "1992-03-06", "t_min_receiptdate": "1992-03-01", "t_max_comment": "vely ironic accounts. furiously unusual acc" }
+{ "t_partkey": 155, "t_count": 23, "t_avg_quantity": 6.069565217391305d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 32021.508695652174d, "t_avg_discount": 0.0508695652173913d, "t_avg_tax": 0.037391304347826095d, "t_max_shipdate": "1998-07-27", "t_min_commitdate": "1992-10-21", "t_min_receiptdate": "1992-09-30", "t_max_comment": "y regular requests haggle." }
+{ "t_partkey": 156, "t_count": 39, "t_avg_quantity": 5.333333333333334d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 28164.0d, "t_avg_discount": 0.0458974358974359d, "t_avg_tax": 0.04410256410256411d, "t_max_shipdate": "1998-08-09", "t_min_commitdate": "1992-02-18", "t_min_receiptdate": "1992-05-03", "t_max_comment": "y regular instructions doze furiously. reg" }
+{ "t_partkey": 157, "t_count": 28, "t_avg_quantity": 5.414285714285715d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 28618.560714285715d, "t_avg_discount": 0.05714285714285714d, "t_avg_tax": 0.03964285714285714d, "t_max_shipdate": "1997-11-27", "t_min_commitdate": "1992-06-30", "t_min_receiptdate": "1992-08-01", "t_max_comment": "y regular requests engage furiously final d" }
+{ "t_partkey": 158, "t_count": 25, "t_avg_quantity": 5.144d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 27215.618000000002d, "t_avg_discount": 0.044000000000000004d, "t_avg_tax": 0.036800000000000006d, "t_max_shipdate": "1998-07-16", "t_min_commitdate": "1992-06-04", "t_min_receiptdate": "1992-08-07", "t_max_comment": "uctions cajole" }
+{ "t_partkey": 159, "t_count": 32, "t_avg_quantity": 4.9625d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 26280.159375000003d, "t_avg_discount": 0.0578125d, "t_avg_tax": 0.043125000000000004d, "t_max_shipdate": "1998-05-25", "t_min_commitdate": "1992-02-10", "t_min_receiptdate": "1992-05-20", "t_max_comment": "y special ideas. express packages pr" }
+{ "t_partkey": 160, "t_count": 42, "t_avg_quantity": 4.338095238095238d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 22995.37523809524d, "t_avg_discount": 0.04690476190476191d, "t_avg_tax": 0.03785714285714287d, "t_max_shipdate": "1998-08-14", "t_min_commitdate": "1992-04-07", "t_min_receiptdate": "1992-05-13", "t_max_comment": "yly silent deposits" }
+{ "t_partkey": 161, "t_count": 33, "t_avg_quantity": 5.109090909090909d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 27107.814545454545d, "t_avg_discount": 0.04666666666666667d, "t_avg_tax": 0.04606060606060606d, "t_max_shipdate": "1998-09-11", "t_min_commitdate": "1992-04-27", "t_min_receiptdate": "1992-04-09", "t_max_comment": "y ironic pin" }
+{ "t_partkey": 162, "t_count": 42, "t_avg_quantity": 4.895238095238096d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 25997.630476190476d, "t_avg_discount": 0.05833333333333335d, "t_avg_tax": 0.03547619047619048d, "t_max_shipdate": "1998-09-18", "t_min_commitdate": "1992-04-27", "t_min_receiptdate": "1992-04-14", "t_max_comment": "y asymptotes. regular depen" }
+{ "t_partkey": 163, "t_count": 28, "t_avg_quantity": 5.550000000000001d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 29502.690000000002d, "t_avg_discount": 0.045d, "t_avg_tax": 0.032499999999999994d, "t_max_shipdate": "1998-04-18", "t_min_commitdate": "1992-03-07", "t_min_receiptdate": "1992-03-09", "t_max_comment": "y fluffily stealt" }
+{ "t_partkey": 164, "t_count": 26, "t_avg_quantity": 4.915384615384616d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 26153.778461538463d, "t_avg_discount": 0.04076923076923077d, "t_avg_tax": 0.04115384615384616d, "t_max_shipdate": "1998-10-17", "t_min_commitdate": "1992-03-31", "t_min_receiptdate": "1992-04-04", "t_max_comment": "ymptotes boost. furiously bold p" }
+{ "t_partkey": 165, "t_count": 36, "t_avg_quantity": 5.561111111111112d, "t_max_suppkey": 10, "t_max_linenumber": 5, "t_avg_extendedprice": 29617.365555555552d, "t_avg_discount": 0.05277777777777778d, "t_avg_tax": 0.03777777777777778d, "t_max_shipdate": "1998-06-07", "t_min_commitdate": "1992-03-17", "t_min_receiptdate": "1992-04-07", "t_max_comment": "y unusual deposits prom" }
+{ "t_partkey": 166, "t_count": 33, "t_avg_quantity": 4.830303030303031d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 25749.37939393939d, "t_avg_discount": 0.04666666666666667d, "t_avg_tax": 0.03878787878787879d, "t_max_shipdate": "1998-08-11", "t_min_commitdate": "1992-06-07", "t_min_receiptdate": "1992-08-16", "t_max_comment": "uses detect spec" }
+{ "t_partkey": 167, "t_count": 31, "t_avg_quantity": 4.851612903225806d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 25887.236129032255d, "t_avg_discount": 0.052258064516129035d, "t_avg_tax": 0.037096774193548385d, "t_max_shipdate": "1998-05-02", "t_min_commitdate": "1992-05-30", "t_min_receiptdate": "1992-06-08", "t_max_comment": "yly final packages according to the quickl" }
+{ "t_partkey": 168, "t_count": 36, "t_avg_quantity": 5.1722222222222225d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 27623.804444444442d, "t_avg_discount": 0.04944444444444445d, "t_avg_tax": 0.03666666666666667d, "t_max_shipdate": "1998-06-26", "t_min_commitdate": "1992-05-20", "t_min_receiptdate": "1992-05-07", "t_max_comment": "xpress requests haggle after the final, fi" }
+{ "t_partkey": 169, "t_count": 35, "t_avg_quantity": 5.822857142857143d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 31127.829714285715d, "t_avg_discount": 0.047999999999999994d, "t_avg_tax": 0.038857142857142854d, "t_max_shipdate": "1998-07-30", "t_min_commitdate": "1992-04-18", "t_min_receiptdate": "1992-04-18", "t_max_comment": "yly final theodolites. furi" }
+{ "t_partkey": 170, "t_count": 27, "t_avg_quantity": 4.874074074074074d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 26080.43925925926d, "t_avg_discount": 0.050740740740740746d, "t_avg_tax": 0.044814814814814814d, "t_max_shipdate": "1998-10-30", "t_min_commitdate": "1992-06-24", "t_min_receiptdate": "1992-08-13", "t_max_comment": "yly ironic " }
+{ "t_partkey": 171, "t_count": 18, "t_avg_quantity": 4.533333333333334d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 24279.853333333333d, "t_avg_discount": 0.04055555555555555d, "t_avg_tax": 0.036666666666666674d, "t_max_shipdate": "1998-07-28", "t_min_commitdate": "1992-10-15", "t_min_receiptdate": "1992-11-11", "t_max_comment": "uriously ironic accounts. ironic, ir" }
+{ "t_partkey": 172, "t_count": 18, "t_avg_quantity": 5.1000000000000005d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 27340.335d, "t_avg_discount": 0.05222222222222222d, "t_avg_tax": 0.03722222222222223d, "t_max_shipdate": "1998-08-21", "t_min_commitdate": "1992-09-18", "t_min_receiptdate": "1992-09-26", "t_max_comment": "wake carefully alongside of " }
+{ "t_partkey": 173, "t_count": 34, "t_avg_quantity": 5.247058823529412d, "t_max_suppkey": 4, "t_max_linenumber": 7, "t_avg_extendedprice": 28154.930588235293d, "t_avg_discount": 0.054411764705882354d, "t_avg_tax": 0.048529411764705876d, "t_max_shipdate": "1998-09-17", "t_min_commitdate": "1992-06-20", "t_min_receiptdate": "1992-06-21", "t_max_comment": "uses. fluffily fina" }
+{ "t_partkey": 174, "t_count": 31, "t_avg_quantity": 5.3419354838709685d, "t_max_suppkey": 5, "t_max_linenumber": 7, "t_avg_extendedprice": 28690.734193548382d, "t_avg_discount": 0.05354838709677419d, "t_avg_tax": 0.046129032258064515d, "t_max_shipdate": "1998-05-31", "t_min_commitdate": "1992-09-05", "t_min_receiptdate": "1992-07-14", "t_max_comment": "y unusual packages thrash pinto " }
+{ "t_partkey": 175, "t_count": 31, "t_avg_quantity": 5.658064516129032d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 30416.906129032257d, "t_avg_discount": 0.04548387096774193d, "t_avg_tax": 0.03387096774193549d, "t_max_shipdate": "1998-09-06", "t_min_commitdate": "1992-09-30", "t_min_receiptdate": "1992-10-22", "t_max_comment": "yly special " }
+{ "t_partkey": 176, "t_count": 28, "t_avg_quantity": 6.078571428571429d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 32707.88107142857d, "t_avg_discount": 0.06d, "t_avg_tax": 0.03642857142857143d, "t_max_shipdate": "1998-11-11", "t_min_commitdate": "1992-02-28", "t_min_receiptdate": "1992-02-21", "t_max_comment": "y unusual foxes cajole ab" }
+{ "t_partkey": 177, "t_count": 29, "t_avg_quantity": 4.675862068965517d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 25183.491724137926d, "t_avg_discount": 0.045517241379310354d, "t_avg_tax": 0.04482758620689655d, "t_max_shipdate": "1998-08-24", "t_min_commitdate": "1992-04-05", "t_min_receiptdate": "1992-05-04", "t_max_comment": "y ironic instructions cajole" }
+{ "t_partkey": 178, "t_count": 41, "t_avg_quantity": 5.414634146341464d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 29189.480487804878d, "t_avg_discount": 0.04878048780487805d, "t_avg_tax": 0.038780487804878055d, "t_max_shipdate": "1998-11-11", "t_min_commitdate": "1992-06-01", "t_min_receiptdate": "1992-06-18", "t_max_comment": "yly ironic decoys; regular, iron" }
+{ "t_partkey": 179, "t_count": 19, "t_avg_quantity": 6.010526315789474d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 32431.898421052636d, "t_avg_discount": 0.04263157894736842d, "t_avg_tax": 0.02368421052631579d, "t_max_shipdate": "1997-06-03", "t_min_commitdate": "1992-04-18", "t_min_receiptdate": "1992-06-10", "t_max_comment": "y regular pain" }
+{ "t_partkey": 180, "t_count": 29, "t_avg_quantity": 4.096551724137931d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 22125.06620689655d, "t_avg_discount": 0.04758620689655172d, "t_avg_tax": 0.036551724137931035d, "t_max_shipdate": "1998-10-28", "t_min_commitdate": "1992-04-02", "t_min_receiptdate": "1992-03-18", "t_max_comment": "y final foxes by the sl" }
+{ "t_partkey": 181, "t_count": 26, "t_avg_quantity": 4.307692307692308d, "t_max_suppkey": 2, "t_max_linenumber": 6, "t_avg_extendedprice": 23286.953846153843d, "t_avg_discount": 0.05615384615384615d, "t_avg_tax": 0.05153846153846154d, "t_max_shipdate": "1998-10-23", "t_min_commitdate": "1992-07-25", "t_min_receiptdate": "1992-07-02", "t_max_comment": "ts across the even requests doze furiously" }
+{ "t_partkey": 182, "t_count": 23, "t_avg_quantity": 4.234782608695652d, "t_max_suppkey": 3, "t_max_linenumber": 7, "t_avg_extendedprice": 22913.985217391306d, "t_avg_discount": 0.03782608695652174d, "t_avg_tax": 0.036521739130434785d, "t_max_shipdate": "1998-11-04", "t_min_commitdate": "1992-04-21", "t_min_receiptdate": "1992-03-13", "t_max_comment": "yly. express ideas agai" }
+{ "t_partkey": 183, "t_count": 31, "t_avg_quantity": 4.851612903225806d, "t_max_suppkey": 4, "t_max_linenumber": 7, "t_avg_extendedprice": 26275.85032258064d, "t_avg_discount": 0.043225806451612905d, "t_avg_tax": 0.04064516129032259d, "t_max_shipdate": "1998-05-26", "t_min_commitdate": "1992-03-21", "t_min_receiptdate": "1992-05-02", "t_max_comment": "y. even excuses" }
+{ "t_partkey": 184, "t_count": 42, "t_avg_quantity": 5.380952380952381d, "t_max_suppkey": 5, "t_max_linenumber": 7, "t_avg_extendedprice": 29169.604761904764d, "t_avg_discount": 0.048809523809523817d, "t_avg_tax": 0.035d, "t_max_shipdate": "1998-07-14", "t_min_commitdate": "1992-04-23", "t_min_receiptdate": "1992-04-14", "t_max_comment": "y regular pinto beans. evenly regular packa" }
+{ "t_partkey": 185, "t_count": 21, "t_avg_quantity": 4.542857142857144d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 24649.088571428572d, "t_avg_discount": 0.04619047619047619d, "t_avg_tax": 0.042857142857142864d, "t_max_shipdate": "1998-06-16", "t_min_commitdate": "1992-02-11", "t_min_receiptdate": "1992-05-30", "t_max_comment": "unusual theodol" }
+{ "t_partkey": 186, "t_count": 30, "t_avg_quantity": 4.206666666666667d, "t_max_suppkey": 7, "t_max_linenumber": 7, "t_avg_extendedprice": 22845.986d, "t_avg_discount": 0.04766666666666667d, "t_avg_tax": 0.044666666666666674d, "t_max_shipdate": "1998-03-06", "t_min_commitdate": "1992-07-07", "t_min_receiptdate": "1992-08-04", "t_max_comment": "ymptotes could u" }
+{ "t_partkey": 187, "t_count": 29, "t_avg_quantity": 5.627586206896552d, "t_max_suppkey": 8, "t_max_linenumber": 6, "t_avg_extendedprice": 30590.99586206896d, "t_avg_discount": 0.048965517241379306d, "t_avg_tax": 0.04103448275862069d, "t_max_shipdate": "1998-11-11", "t_min_commitdate": "1992-05-01", "t_min_receiptdate": "1992-04-13", "t_max_comment": "y even forges. fluffily furious accounts" }
+{ "t_partkey": 188, "t_count": 31, "t_avg_quantity": 4.2129032258064525d, "t_max_suppkey": 9, "t_max_linenumber": 6, "t_avg_extendedprice": 22921.98516129032d, "t_avg_discount": 0.06483870967741935d, "t_avg_tax": 0.03483870967741936d, "t_max_shipdate": "1998-06-19", "t_min_commitdate": "1992-08-05", "t_min_receiptdate": "1992-10-05", "t_max_comment": "y regular asymptotes doz" }
+{ "t_partkey": 189, "t_count": 33, "t_avg_quantity": 4.533333333333334d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 24688.079999999998d, "t_avg_discount": 0.053333333333333344d, "t_avg_tax": 0.03757575757575757d, "t_max_shipdate": "1998-07-26", "t_min_commitdate": "1992-06-08", "t_min_receiptdate": "1992-07-03", "t_max_comment": "y sly theodolites. ironi" }
+{ "t_partkey": 190, "t_count": 39, "t_avg_quantity": 4.912820512820513d, "t_max_suppkey": 1, "t_max_linenumber": 7, "t_avg_extendedprice": 26779.538974358973d, "t_avg_discount": 0.04743589743589744d, "t_avg_tax": 0.03538461538461539d, "t_max_shipdate": "1998-09-24", "t_min_commitdate": "1992-05-02", "t_min_receiptdate": "1992-05-11", "t_max_comment": "y final foxes sleep blithely sl" }
+{ "t_partkey": 191, "t_count": 40, "t_avg_quantity": 5.5200000000000005d, "t_max_suppkey": 5, "t_max_linenumber": 7, "t_avg_extendedprice": 30116.844d, "t_avg_discount": 0.0475d, "t_avg_tax": 0.04025d, "t_max_shipdate": "1998-10-08", "t_min_commitdate": "1992-06-09", "t_min_receiptdate": "1992-08-09", "t_max_comment": "ys engage. th" }
+{ "t_partkey": 192, "t_count": 29, "t_avg_quantity": 4.655172413793103d, "t_max_suppkey": 6, "t_max_linenumber": 7, "t_avg_extendedprice": 25421.66379310345d, "t_avg_discount": 0.04724137931034483d, "t_avg_tax": 0.04586206896551724d, "t_max_shipdate": "1998-05-26", "t_min_commitdate": "1992-04-06", "t_min_receiptdate": "1992-03-02", "t_max_comment": "y. fluffily bold accounts grow. furio" }
+{ "t_partkey": 193, "t_count": 27, "t_avg_quantity": 4.4222222222222225d, "t_max_suppkey": 7, "t_max_linenumber": 6, "t_avg_extendedprice": 24171.64555555556d, "t_avg_discount": 0.044814814814814814d, "t_avg_tax": 0.02851851851851852d, "t_max_shipdate": "1998-08-19", "t_min_commitdate": "1992-05-05", "t_min_receiptdate": "1992-06-03", "t_max_comment": "y players sleep along the final, pending " }
+{ "t_partkey": 194, "t_count": 28, "t_avg_quantity": 4.457142857142857d, "t_max_suppkey": 8, "t_max_linenumber": 7, "t_avg_extendedprice": 24384.80571428571d, "t_avg_discount": 0.04071428571428572d, "t_avg_tax": 0.031785714285714285d, "t_max_shipdate": "1998-07-06", "t_min_commitdate": "1992-03-18", "t_min_receiptdate": "1992-02-23", "t_max_comment": "y silent requests. regular, even accounts" }
+{ "t_partkey": 195, "t_count": 30, "t_avg_quantity": 5.053333333333334d, "t_max_suppkey": 9, "t_max_linenumber": 7, "t_avg_extendedprice": 27671.800666666666d, "t_avg_discount": 0.04833333333333333d, "t_avg_tax": 0.045000000000000005d, "t_max_shipdate": "1998-01-21", "t_min_commitdate": "1992-02-12", "t_min_receiptdate": "1992-05-05", "t_max_comment": "yly pending packages snooz" }
+{ "t_partkey": 196, "t_count": 36, "t_avg_quantity": 5.011111111111112d, "t_max_suppkey": 10, "t_max_linenumber": 6, "t_avg_extendedprice": 27465.649444444443d, "t_avg_discount": 0.04972222222222223d, "t_avg_tax": 0.03944444444444444d, "t_max_shipdate": "1998-10-17", "t_min_commitdate": "1992-03-14", "t_min_receiptdate": "1992-03-27", "t_max_comment": "y quickly " }
+{ "t_partkey": 197, "t_count": 32, "t_avg_quantity": 5.2125d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 28595.514375d, "t_avg_discount": 0.0553125d, "t_avg_tax": 0.0378125d, "t_max_shipdate": "1998-05-19", "t_min_commitdate": "1993-09-09", "t_min_receiptdate": "1993-08-23", "t_max_comment": "warhorses slee" }
+{ "t_partkey": 198, "t_count": 31, "t_avg_quantity": 4.587096774193548d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 25187.519032258064d, "t_avg_discount": 0.03967741935483871d, "t_avg_tax": 0.035806451612903224d, "t_max_shipdate": "1998-10-06", "t_min_commitdate": "1992-02-23", "t_min_receiptdate": "1992-05-15", "t_max_comment": "y even accounts. quickly bold decoys" }
+{ "t_partkey": 199, "t_count": 32, "t_avg_quantity": 5.5062500000000005d, "t_max_suppkey": 10, "t_max_linenumber": 7, "t_avg_extendedprice": 30262.0746875d, "t_avg_discount": 0.052812500000000005d, "t_avg_tax": 0.043750000000000004d, "t_max_shipdate": "1998-08-14", "t_min_commitdate": "1992-05-13", "t_min_receiptdate": "1992-03-28", "t_max_comment": "y carefully ironi" }
+{ "t_partkey": 200, "t_count": 24, "t_avg_quantity": 5.458333333333334d, "t_max_suppkey": 4, "t_max_linenumber": 7, "t_avg_extendedprice": 30026.291666666668d, "t_avg_discount": 0.049166666666666664d, "t_avg_tax": 0.03375d, "t_max_shipdate": "1998-09-04", "t_min_commitdate": "1992-05-28", "t_min_receiptdate": "1992-05-12", "t_max_comment": "y silent foxes! carefully ruthless cour" }

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


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

Posted by bu...@apache.org.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
new file mode 100644
index 0000000..5ff8aeb
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.3.query.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+SELECT nation, o_year, sum(amount) AS sum_profit
+FROM
+  (
+    SELECT   n_name AS nation,
+             `get-year`(o_orderdate) AS o_year,
+             l_extendedprice * (1 - l_discount) -  ps_supplycost * l_quantity AS amount
+    FROM
+      Orders JOIN
+      (
+       SELECT l_extendedprice, l_discount, l_quantity, l_orderkey, n_name, ps_supplycost
+       FROM Part JOIN
+         (SELECT l_extendedprice, l_discount, l_quantity, l_partkey, l_orderkey, n_name, ps_supplycost
+          FROM Partsupp join
+            (SELECT l_suppkey, l_extendedprice, l_discount, l_quantity, l_partkey, l_orderkey, n_name
+             FROM
+               (SELECT s_suppkey, n_name
+                FROM Nation JOIN Supplier ON n_nationkey = s_nationkey
+               ) s1 JOIN LineItem ON s_suppkey = l_suppkey
+            ) l1 ON ps_suppkey = l_suppkey AND ps_partkey = l_partkey
+         ) l2 ON contains(p_name,'green') AND p_partkey = l_partkey
+     ) l3 ON o_orderkey = l_orderkey
+  ) profit
+GROUP BY nation, o_year
+ORDER BY nation, o_year desc;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.2.update.sqlpp
new file mode 100644
index 0000000..e7866b4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.3.query.sqlpp
new file mode 100644
index 0000000..ef499de
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item/q10_returned_item.3.query.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+SELECT c_custkey, c_name,
+       sum(l_extendedprice * (1 - l_discount)) AS revenue,
+       c_acctbal, n_name, c_address, c_phone, c_comment
+FROM  (
+        SELECT c_custkey, c_name, c_acctbal, n_name, c_address, c_phone, c_comment, l_extendedprice, l_discount
+        FROM  LineItem,
+          (
+            SELECT  c_custkey, c_name, c_acctbal, n_name, c_address, c_phone, c_comment, o_orderkey
+            from  Orders,
+                  Customer,
+                  Nation
+            WHERE c_custkey = o_custkey AND o_orderdate >= '1993-10-01'
+                  AND o_orderdate < '1994-01-01' AND c_nationkey = n_nationkey
+          ) AS ocn
+        WHERE l_orderkey = o_orderkey and l_returnflag = 'R'
+      ) AS locn
+GROUP BY c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment
+ORDER BY revenue DESC
+LIMIT 20
+;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
new file mode 100644
index 0000000..bd07d48
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.3.query.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+USE tpch;
+
+
+SELECT c_custkey, c_name,
+       sum(l_extendedprice * (1 - l_discount)) AS revenue,
+       c_acctbal, n_name, c_address, c_phone, c_comment
+FROM  (
+        SELECT c_custkey, c_name, c_acctbal, n_name, c_address, c_phone, c_comment, l_extendedprice, l_discount
+        FROM  LineItem,
+          (
+            SELECT  c_custkey, c_name, c_acctbal, n_name, c_address, c_phone, c_comment, o_orderkey
+            from  Orders,
+                  Customer,
+                  Nation
+            WHERE c_custkey = o_custkey AND o_orderdate >= '1993-10-01'
+                  AND o_orderdate < '1994-01-01' AND c_nationkey = n_nationkey
+          ) AS ocn
+        WHERE l_orderkey = o_orderkey and l_returnflag = 'R'
+      ) AS locn
+GROUP BY c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment
+ORDER BY revenue DESC
+LIMIT 20
+;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.3.query.sqlpp
new file mode 100644
index 0000000..b3a08e8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q11_important_stock/q11_important_stock.3.query.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+WITH sum as (
+      SELECT ELEMENT SUM(ps_supplycost * ps_availqty)
+      FROM  Partsupp,
+            (
+                SELECT s_suppkey
+                FROM  Supplier,
+                      Nation
+                WHERE s_nationkey = n_nationkey
+            ) AS sn
+      WHERE ps_suppkey = s_suppkey
+)[0]
+
+SELECT ps_partkey AS partkey, part_value
+FROM  (
+        SELECT ps_partkey,
+               sum(ps_supplycost * ps_availqty) AS part_value
+        FROM  Partsupp,
+              (
+                SELECT s_suppkey
+                FROM  Supplier,
+                      Nation
+                WHERE s_nationkey = n_nationkey
+              ) sn
+        WHERE ps_suppkey = s_suppkey
+        GROUP BY ps_partkey
+) t1
+WHERE part_value > sum * 0.00001
+ORDER BY part_value DESC
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.3.query.sqlpp
new file mode 100644
index 0000000..0d778e4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q12_shipping/q12_shipping.3.query.sqlpp
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+SELECT l_shipmode,
+       sum(`switch-case`(o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH',true,1,false,0)) high_line_count,
+       sum(`switch-case`(o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH',true,0,false,1)) low_line_count
+FROM  LineItem,
+      Orders
+WHERE o_orderkey = l_orderkey AND l_commitdate < l_receiptdate AND
+      l_shipdate < l_commitdate AND l_receiptdate >= '1994-01-01' AND
+      l_receiptdate < '1995-01-01' AND (l_shipmode = 'MAIL' OR l_shipmode = 'SHIP')
+GROUP BY l_shipmode
+ORDER BY l_shipmode
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
new file mode 100644
index 0000000..31d4dbc
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.3.query.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+SELECT c_count, count(gco) AS custdist
+FROM  (
+        SELECT c_custkey, sum(o_orderkey_count) AS c_count
+        FROM  (
+                SELECT c_custkey,
+                       coll_count(
+                           (
+                            select element o_orderkey
+                            from  Orders
+                            where c_custkey = o_custkey and not(like(o_comment,'%special%requests%'))
+                           )
+                         ) AS o_orderkey_count
+                from  Customer
+        ) co
+        GROUP BY c_custkey
+) gco
+GROUP BY c_count
+ORDER BY custdist DESC,c_count DESC
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
new file mode 100644
index 0000000..56d7637
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q14_promotion_effect/q14_promotion_effect.3.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+select element 100.0 *
+     sum(`switch-case`(like(p_type,'PROMO%'),true,(l_extendedprice * (1 - l_discount)),false,0.0))
+     / sum(l_extendedprice * (1 - l_discount))
+FROM  LineItem,
+      Part
+WHERE l_partkey = p_partkey AND l_shipdate >= '1995-09-01' AND l_shipdate < '1995-10-01'
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.3.query.sqlpp
new file mode 100644
index 0000000..95a360e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.3.query.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+WITH revenue AS
+(
+    SELECT l_suppkey AS supplier_no,
+           sum(l_extendedprice * (1 - l_discount)) AS total_revenue
+    FROM  LineItem
+    WHERE l_shipdate >= '1996-01-01' and l_shipdate < '1996-04-01'
+    GROUP BY l_suppkey
+),
+m AS (
+      SELECT ELEMENT max(total_revenue)
+      FROM revenue
+)[0]
+
+SELECT s_suppkey,
+       s_name,
+       s_address,
+       s_phone,
+       total_revenue
+FROM  Supplier,
+      revenue
+WHERE s_suppkey = supplier_no AND total_revenue < m + 0.000000001
+      AND total_revenue > m - 0.000000001
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
new file mode 100644
index 0000000..2b56eab
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.3.query.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+WITH tmp AS
+(
+    SELECT p_brand, p_type, p_size, ps_suppkey
+    FROM  (
+            SELECT p_brand, p_type, p_size, ps_suppkey
+            FROM  Partsupp,
+                  Part
+            WHERE p_partkey = ps_partkey AND p_brand != 'Brand#45' AND
+              not(like(p_type,'MEDIUM POLISHED%'))
+           ) AS psp,
+           Supplier
+    WHERE ps_suppkey = s_suppkey AND not(like(s_comment,'%Customer%Complaints%'))
+)
+
+SELECT p_brand, p_type, p_size, count(ps_suppkey) supplier_cnt
+FROM  (
+    SELECT p_brand, p_type, p_size, ps_suppkey
+    FROM  tmp
+    WHERE p_size = 49 OR p_size = 14 OR p_size = 23 OR p_size = 45 OR p_size = 19
+          OR p_size = 3 OR p_size = 36 OR p_size = 9
+    GROUP BY p_brand, p_type, p_size, ps_suppkey
+) AS t2
+GROUP BY p_brand, p_type, p_size
+ORDER BY supplier_cnt DESC, p_brand, p_type, p_size
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+


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

Posted by bu...@apache.org.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.3.query.sqlpp
new file mode 100644
index 0000000..cf246d6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.3.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+SELECT VALUE name
+FROM  Regions_group_no_agg AS r
+GROUP BY r_name AS name
+ORDER BY name
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.ddl.sqlpp
new file mode 100644
index 0000000..3b070de
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.ddl.sqlpp
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue782
+ * https://code.google.com/p/asterixdb/issues/detail?id=782
+ * Expected Res : SUCCESS
+ * Date         : 2nd Jun 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+
+create  table SelectedNation(NationType) primary key n_nationkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.2.update.sqlpp
new file mode 100644
index 0000000..d3f566e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.2.update.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue782
+ * https://code.google.com/p/asterixdb/issues/detail?id=782
+ * Expected Res : SUCCESS
+ * Date         : 2nd Jun 2014
+ */
+
+use tpch;
+
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table SelectedNation using localfs ((`path`=`asterix_nc1://data/tpch0.001/selectednation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.3.query.sqlpp
new file mode 100644
index 0000000..6d0d928
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate/nest_aggregate.3.query.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue782
+ * https://code.google.com/p/asterixdb/issues/detail?id=782
+ * Expected Res : SUCCESS
+ * Date         : 2nd Jun 2014
+ */
+
+USE tpch;
+
+
+SELECT  Nation.n_nationkey AS nation_key,
+        Nation.n_name AS name,
+        (
+            SELECT orderdate AS order_date, sum(o_totalprice) AS sum_price
+            FROM  Orders,
+                  Customer
+            WHERE o_custkey = c_custkey AND c_nationkey = Nation.n_nationkey
+            GROUP BY o_orderdate AS orderdate
+            ORDER BY sum_price
+            LIMIT 3
+        ) AS aggregates
+FROM  Nation,
+      SelectedNation AS sn
+WHERE Nation.n_nationkey /*+ indexnl */ = sn.n_nationkey
+ORDER BY Nation.n_nationkey
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.ddl.sqlpp
new file mode 100644
index 0000000..3b070de
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.ddl.sqlpp
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue782
+ * https://code.google.com/p/asterixdb/issues/detail?id=782
+ * Expected Res : SUCCESS
+ * Date         : 2nd Jun 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+
+create  table SelectedNation(NationType) primary key n_nationkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.2.update.sqlpp
new file mode 100644
index 0000000..d3f566e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.2.update.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue782
+ * https://code.google.com/p/asterixdb/issues/detail?id=782
+ * Expected Res : SUCCESS
+ * Date         : 2nd Jun 2014
+ */
+
+use tpch;
+
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table SelectedNation using localfs ((`path`=`asterix_nc1://data/tpch0.001/selectednation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.3.query.sqlpp
new file mode 100644
index 0000000..4a4cfc5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.3.query.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue782
+ * https://code.google.com/p/asterixdb/issues/detail?id=782
+ * Expected Res : SUCCESS
+ * Date         : 2nd Jun 2014
+ */
+
+USE tpch;
+
+
+
+SELECT  Nation.n_nationkey AS nation_key,
+        Nation.n_name AS name,
+        (
+            SELECT ELEMENT orderdate
+            FROM  Orders,
+                  Customer
+            WHERE o_custkey = c_custkey AND c_nationkey = Nation.n_nationkey
+            GROUP BY o_orderdate AS orderdate
+            ORDER BY sum(o_totalprice)
+            LIMIT 3
+        ) AS aggregates
+from  Nation,
+      SelectedNation as sn
+where Nation.n_nationkey /*+ indexnl */ = sn.n_nationkey
+order by Nation.n_nationkey
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.ddl.sqlpp
new file mode 100644
index 0000000..8649a3b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.ddl.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.2.update.sqlpp
new file mode 100644
index 0000000..d996e74
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.2.update.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
new file mode 100644
index 0000000..4fc3b5a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.3.query.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+SELECT  l_returnflag,
+        l_linestatus,
+        sum(l_quantity) AS sum_qty,
+        sum(l_extendedprice) AS sum_base_price,
+        sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price,
+        sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,
+        avg(l_quantity) AS ave_qty,
+        avg(l_extendedprice) AS ave_price,
+        avg(l_discount) AS ave_disc,
+        count(1) AS count_order
+FROM  LineItem
+WHERE l_shipdate <= '1998-09-02'
+/* +hash */
+GROUP BY l_returnflag, l_linestatus
+ORDER BY l_returnflag, l_linestatus
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
new file mode 100644
index 0000000..b13a11a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.3.query.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+WITH q2_minimum_cost_supplier_tmp1 AS
+(
+ SELECT s_acctbal, s_name, n_name, p_partkey, ps_supplycost, p_mfgr, s_address, s_phone, s_comment
+ FROM Nation JOIN Region ON n_regionkey = r_regionkey and r_name = 'EUROPE'
+ JOIN Supplier ON s_nationkey = n_nationkey
+ JOIN Partsupp ON s_suppkey = ps_suppkey
+ JOIN Part ON p_partkey = ps_partkey AND like(p_type, '%BRASS')
+),
+q2_minimum_cost_supplier_tmp2 AS
+(
+  SELECT p_partkey, min(ps_supplycost) AS ps_min_supplycost
+  FROM q2_minimum_cost_supplier_tmp1
+  GROUP BY p_partkey
+)
+
+SELECT s_acctbal, s_name, n_name, t1.p_partkey, p_mfgr, s_address, s_phone, s_comment
+FROM
+  q2_minimum_cost_supplier_tmp1 t1 JOIN q2_minimum_cost_supplier_tmp2 t2
+ON
+  t1.p_partkey = t2.p_partkey AND ps_supplycost=ps_min_supplycost
+ORDER BY s_acctbal DESC, n_name, s_name, t1.p_partkey
+LIMIT 100;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.2.update.sqlpp
new file mode 100644
index 0000000..dd4aa2f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.2.update.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
new file mode 100644
index 0000000..c620bdc
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.3.query.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+SELECT l_orderkey,
+       sum(l_extendedprice * (1 - l_discount)) AS revenue,
+       o_orderdate,
+       o_shippriority
+FROM  Customer,
+      Orders,
+      LineItem
+where c_mktsegment = 'BUILDING' AND c_custkey = o_custkey AND l_orderkey = o_orderkey AND o_orderdate < '1995-03-15' AND l_shipdate > '1995-03-15'
+/* +hash */
+GROUP BY l_orderkey, o_orderdate, o_shippriority
+ORDER BY revenue DESC,o_orderdate
+LIMIT 10
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.3.query.sqlpp
new file mode 100644
index 0000000..e2e486d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q04_order_priority/q04_order_priority.3.query.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+WITH tmp AS
+(
+    SELECT DISTINCT l_orderkey
+    FROM  LineItem
+    WHERE l_commitdate < l_receiptdate
+)
+
+SELECT o_orderpriority AS order_priority, count(Orders) AS count
+FROM Orders
+JOIN tmp
+ON l_orderkey = o_orderkey
+WHERE o_orderdate >= '1993-07-01' AND o_orderdate < '1993-10-01'
+GROUP BY o_orderpriority
+ORDER BY o_orderpriority
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
new file mode 100644
index 0000000..dce8e76
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.3.query.sqlpp
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+SELECT n_name, sum(l_extendedprice * (1 - l_discount)) AS revenue
+FROM
+  Customer JOIN
+    ( SELECT n_name, l_extendedprice, l_discount, s_nationkey, o_custkey
+      FROM Orders JOIN
+      ( SELECT n_name, l_extendedprice, l_discount, l_orderkey, s_nationkey
+        FROM LineItem JOIN
+            (   SELECT n_name, s_suppkey, s_nationkey
+                FROM Supplier JOIN
+                (   SELECT n_name, n_nationkey
+                    FROM Nation n JOIN Region r
+                    ON n_regionkey = r_regionkey
+                ) n1 ON s_nationkey = n_nationkey
+            ) s1
+        ON l_suppkey = s_suppkey
+      ) l1 ON l_orderkey = o_orderkey AND o_orderdate >= '1990-01-01'
+              AND o_orderdate < '1995-01-01'
+   ) o1
+ON c_nationkey = s_nationkey AND c_custkey = o_custkey
+GROUP BY n_name
+ORDER BY revenue DESC;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
new file mode 100644
index 0000000..6556a43
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q06_forecast_revenue_change/q06_forecast_revenue_change.3.query.sqlpp
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+{'revenue':
+      (
+        SELECT ELEMENT SUM(l_extendedprice * l_discount)
+        FROM  LineItem
+        WHERE l_shipdate >= '1994-01-01'
+              and l_shipdate < '1995-01-01'
+              and l_discount >= 0.05
+              and l_discount <= 0.07
+              and l_quantity < 24
+      )[0]
+};

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
new file mode 100644
index 0000000..5a707cd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.3.query.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+WITH q7_volume_shipping_tmp AS
+(
+    SELECT n1.n_name AS supp_nation,
+           n2.n_name AS cust_nation,
+           n1.n_nationkey AS s_nationkey,
+           n2.n_nationkey AS c_nationkey
+    from  Nation as n1,
+          Nation as n2
+    where n2.n_name = 'GERMANY' or n1.n_name = 'GERMANY'
+)
+
+SELECT supp_nation, cust_nation, l_year, sum(volume) AS revenue
+FROM
+  (
+    SELECT supp_nation, cust_nation,
+      `get-year`(l_shipdate) AS l_year,
+       l_extendedprice * (1 - l_discount) AS volume
+    FROM
+      q7_volume_shipping_tmp t JOIN
+        (SELECT l_shipdate, l_extendedprice, l_discount, c_nationkey, s_nationkey
+         FROM Supplier JOIN
+           (SELECT l_shipdate, l_extendedprice, l_discount, l_suppkey, c_nationkey
+            FROM Customer JOIN
+              (SELECT l_shipdate, l_extendedprice, l_discount, l_suppkey, o_custkey
+               FROM Orders
+               JOIN LineItem ON o_orderkey = l_orderkey AND l_shipdate >= '1992-01-01'
+                    AND l_shipdate <= '1996-12-31'
+               ) l1 ON c_custkey = o_custkey
+            ) l2 ON s_suppkey = l_suppkey
+         ) l3 ON t.c_nationkey = l3.c_nationkey AND t.s_nationkey = l3.s_nationkey
+   ) shipping
+GROUP BY supp_nation, cust_nation, l_year
+ORDER BY supp_nation, cust_nation, l_year;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.3.query.sqlpp
new file mode 100644
index 0000000..df23284
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.3.query.sqlpp
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+SELECT  year,
+        sum( `switch-case`(s_name = 'BRAZIL', true, revenue, false, 0.0) )
+        / sum(revenue) AS mkt_share
+FROM  (
+        SELECT o_year AS year,
+               l_extendedprice * (1 - l_discount) AS revenue,
+               n_name AS s_name
+        FROM  (
+                SELECT o_orderdate, l_discount, l_extendedprice, l_suppkey, s_nationkey
+                FROM  Supplier,
+                (
+                  SELECT o_orderdate, l_discount, l_extendedprice, l_suppkey
+                  FROM  (
+                         SELECT o_orderdate, l_partkey, l_discount, l_extendedprice, l_suppkey
+                         FROM  LineItem,
+                               (
+                                SELECT o_orderdate, o_orderkey
+                                FROM  Orders,
+                                      (
+                                        SELECT c_custkey
+                                        FROM  Customer,
+                                              (
+                                                SELECT n_nationkey
+                                                FROM  Nation,
+                                                      Region
+                                                WHERE n_regionkey = r_regionkey AND r_name = 'AMERICA'
+                                                ) AS nr
+                                         WHERE c_nationkey = n_nationkey
+                                       ) AS nrc
+                                WHERE c_custkey = o_custkey
+                                ) AS nrco
+                        WHERE l_orderkey = o_orderkey and o_orderdate >= '1995-01-01' and o_orderdate < '1996-12-31'
+                        ) AS lnrco,
+                        Part
+                        WHERE p_partkey = l_partkey and p_type = 'ECONOMY ANODIZED STEEL'
+                    ) AS lnrcop
+                WHERE s_suppkey = l_suppkey
+                ) AS slnrcop,
+                Nation
+                LET o_year = `get-year`(o_orderdate)
+                WHERE s_nationkey = n_nationkey
+             ) as t
+GROUP BY year
+ORDER BY year
+;


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

Posted by bu...@apache.org.
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/SqlppGroupBySugarVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
index 6c88a6a..47aa02b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
@@ -31,6 +31,7 @@ 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.Expression.Kind;
+import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.FieldAccessor;
 import org.apache.asterix.lang.common.expression.VariableExpr;
@@ -83,17 +84,20 @@ public class SqlppGroupBySugarVisitor extends AbstractSqlppExpressionScopingVisi
 
     private final Expression groupVar;
     private final Collection<VariableExpr> targetVars;
+    private final Collection<VariableExpr> allVisableVars;
 
     public SqlppGroupBySugarVisitor(LangRewritingContext context, Expression groupVar,
-            Collection<VariableExpr> targetVars) {
+            Collection<VariableExpr> targetVars, Collection<VariableExpr> allVisableVars) {
         super(context);
         this.groupVar = groupVar;
         this.targetVars = targetVars;
+        this.allVisableVars = allVisableVars;
+        allVisableVars.remove(groupVar);
     }
 
     @Override
-    public Expression visit(CallExpr callExpr, Expression arg) throws AsterixException {
-        List<Expression> newExprList = new ArrayList<Expression>();
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+        List<Expression> newExprList = new ArrayList<>();
         FunctionSignature signature = callExpr.getFunctionSignature();
         boolean aggregate = FunctionMapUtil.isSql92AggregateFunction(signature)
                 || FunctionMapUtil.isCoreAggregateFunction(signature);
@@ -112,15 +116,21 @@ public class SqlppGroupBySugarVisitor extends AbstractSqlppExpressionScopingVisi
         return callExpr;
     }
 
-    private Expression wrapAggregationArgument(Expression expr) throws AsterixException {
+    private Expression wrapAggregationArgument(Expression argExpr) throws AsterixException {
+        Expression expr = argExpr;
         if (expr.getKind() == Kind.SELECT_EXPRESSION) {
             return expr;
         }
         Set<VariableExpr> definedVars = scopeChecker.getCurrentScope().getLiveVariables();
+        allVisableVars.addAll(definedVars);
+        Set<VariableExpr> freeVars = SqlppRewriteUtil.getFreeVariable(expr);
+
+        // Whether we need to resolve undefined variables.
+        boolean needResolve = !allVisableVars.containsAll(freeVars);
+
         Set<VariableExpr> vars = new HashSet<>(targetVars);
         vars.removeAll(definedVars); // Exclude re-defined local variables.
-        Set<VariableExpr> freeVars = SqlppRewriteUtil.getFreeVariable(expr);
-        if (!vars.containsAll(freeVars)) {
+        if (!needResolve && !vars.containsAll(freeVars)) {
             return expr;
         }
 
@@ -140,8 +150,19 @@ public class SqlppGroupBySugarVisitor extends AbstractSqlppExpressionScopingVisi
         // replace variable expressions with field access
         Map<VariableExpr, Expression> varExprMap = new HashMap<>();
         for (VariableExpr usedVar : freeVars) {
-            varExprMap.put(usedVar,
-                    new FieldAccessor(var, SqlppVariableUtil.toUserDefinedVariableName(usedVar.getVar())));
+            if (allVisableVars.contains(usedVar)) {
+                // Reference to a defined variable.
+                if (vars.contains(usedVar)) {
+                    // Reference to a variable defined before the group-by,
+                    // i.e., not a variable defined by a LET after the group-by.
+                    varExprMap.put(usedVar,
+                            new FieldAccessor(var, SqlppVariableUtil.toUserDefinedVariableName(usedVar.getVar())));
+                }
+            } else {
+                // Reference to an undefined variable.
+                varExprMap.put(usedVar,
+                        this.wrapWithResolveFunction(usedVar, new HashSet<>(Collections.singleton(var))));
+            }
         }
         selectElement.setExpression(
                 (Expression) SqlppVariableSubstitutionUtil.substituteVariableWithoutContext(expr, varExprMap));

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/SqlppGroupByVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
index 16e967c..36463cb 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
@@ -26,6 +26,7 @@ import java.util.Set;
 
 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.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.context.Scope;
@@ -84,7 +85,7 @@ public class SqlppGroupByVisitor extends AbstractSqlppExpressionScopingVisitor {
     }
 
     @Override
-    public Expression visit(SelectBlock selectBlock, Expression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
         // Traverses the select block in the order of "from", "let"s, "where",
         // "group by", "let"s, "having" and "select".
         if (selectBlock.hasFromClause()) {
@@ -103,43 +104,53 @@ public class SqlppGroupByVisitor extends AbstractSqlppExpressionScopingVisitor {
             selectBlock.getGroupbyClause().accept(this, arg);
             Set<VariableExpr> withVarSet = new HashSet<>(selectBlock.getGroupbyClause().getWithVarList());
             withVarSet.remove(selectBlock.getGroupbyClause().getGroupVar());
+
+            Set<VariableExpr> allVisableVars = SqlppVariableUtil
+                    .getLiveUserDefinedVariables(scopeChecker.getCurrentScope());
             if (selectBlock.hasLetClausesAfterGroupby()) {
                 List<LetClause> letListAfterGby = selectBlock.getLetListAfterGroupby();
                 for (LetClause letClauseAfterGby : letListAfterGby) {
+                    letClauseAfterGby.accept(this, arg);
                     // Rewrites each let clause after the group-by.
                     SqlppRewriteUtil.rewriteExpressionUsingGroupVariable(selectBlock.getGroupbyClause().getGroupVar(),
-                            withVarSet, letClauseAfterGby, context);
-                    letClauseAfterGby.accept(this, arg);
+                            withVarSet, allVisableVars, letClauseAfterGby, context);
+                    // Adds let vars to all visiable vars.
+                    allVisableVars.add(letClauseAfterGby.getVarExpr());
                 }
             }
+
             if (selectBlock.hasHavingClause()) {
+                selectBlock.getHavingClause().accept(this, arg);
                 // Rewrites the having clause.
                 SqlppRewriteUtil.rewriteExpressionUsingGroupVariable(selectBlock.getGroupbyClause().getGroupVar(),
-                        withVarSet, selectBlock.getHavingClause(), context);
-                selectBlock.getHavingClause().accept(this, arg);
+                        withVarSet, allVisableVars, selectBlock.getHavingClause(), context);
             }
-            // Rewrites the select clause.
-            SqlppRewriteUtil.rewriteExpressionUsingGroupVariable(selectBlock.getGroupbyClause().getGroupVar(),
-                    withVarSet, selectBlock.getSelectClause(), context);
 
             SelectExpression parentSelectExpression = (SelectExpression) arg;
             if (parentSelectExpression.hasOrderby()) {
                 // Rewrites the order-by clause.
                 SqlppRewriteUtil.rewriteExpressionUsingGroupVariable(selectBlock.getGroupbyClause().getGroupVar(),
-                        withVarSet, parentSelectExpression.getOrderbyClause(), context);
+                        withVarSet, allVisableVars, parentSelectExpression.getOrderbyClause(), context);
             }
             if (parentSelectExpression.hasLimit()) {
                 // Rewrites the limit clause.
                 SqlppRewriteUtil.rewriteExpressionUsingGroupVariable(selectBlock.getGroupbyClause().getGroupVar(),
-                        withVarSet, parentSelectExpression.getLimitClause(), context);
+                        withVarSet, allVisableVars, parentSelectExpression.getLimitClause(), context);
             }
+
+            // Visits the select clause.
+            selectBlock.getSelectClause().accept(this, arg);
+            // Rewrites the select clause.
+            SqlppRewriteUtil.rewriteExpressionUsingGroupVariable(selectBlock.getGroupbyClause().getGroupVar(),
+                    withVarSet, allVisableVars, selectBlock.getSelectClause(), context);
+        } else {
+            selectBlock.getSelectClause().accept(this, arg);
         }
-        selectBlock.getSelectClause().accept(this, arg);
         return null;
     }
 
     @Override
-    public Expression visit(GroupbyClause gc, Expression arg) throws AsterixException {
+    public Expression visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
         Scope newScope = scopeChecker.extendCurrentScopeNoPush(true);
         // Puts all group-by variables into the symbol set of the new scope.
         for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
@@ -150,7 +161,7 @@ public class SqlppGroupByVisitor extends AbstractSqlppExpressionScopingVisitor {
             }
         }
         // Puts all live variables into withVarList.
-        List<VariableExpr> withVarList = new ArrayList<VariableExpr>();
+        List<VariableExpr> withVarList = new ArrayList<>();
         Iterator<Identifier> varIterator = scopeChecker.getCurrentScope().liveSymbols();
         while (varIterator.hasNext()) {
             Identifier ident = varIterator.next();

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/SqlppInlineUdfsVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
index e7832bb..194c029 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
@@ -43,6 +43,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.SqlppVariableSubstitutionUtil;
@@ -223,6 +224,13 @@ public class SqlppInlineUdfsVisitor extends AbstractInlineUdfsVisitor
         return p.first;
     }
 
+    @Override
+    public Boolean visit(IndependentSubquery independentSubquery, List<FunctionDecl> funcs) throws AsterixException {
+        Pair<Boolean, Expression> p = inlineUdfsInExpr(independentSubquery.getExpr(), funcs);
+        independentSubquery.setExpr(p.second);
+        return p.first;
+    }
+
     private Map<VariableExpr, Expression> extractLetBindingVariableExpressionMappings(List<LetClause> letClauses)
             throws AsterixException {
         Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>();
@@ -234,4 +242,5 @@ public class SqlppInlineUdfsVisitor extends AbstractInlineUdfsVisitor
         }
         return varExprMap;
     }
+
 }

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/VariableCheckAndRewriteVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
index 5ca2533..7082c25 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
@@ -20,11 +20,13 @@ package org.apache.asterix.lang.sqlpp.rewrites.visitor;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.asterix.common.config.MetadataConstants;
 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.common.expression.LiteralExpr;
 import org.apache.asterix.lang.common.expression.VariableExpr;
@@ -35,9 +37,12 @@ import org.apache.asterix.lang.common.struct.VarIdentifier;
 import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
 import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppExpressionScopingVisitor;
 import org.apache.asterix.metadata.declared.AqlMetadataProvider;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 
 public class VariableCheckAndRewriteVisitor extends AbstractSqlppExpressionScopingVisitor {
 
+    protected final FunctionSignature datasetFunction = new FunctionSignature(MetadataConstants.METADATA_DATAVERSE_NAME,
+            "dataset", 1);
     protected final boolean overwrite;
     protected final AqlMetadataProvider metadataProvider;
 
@@ -57,17 +62,28 @@ public class VariableCheckAndRewriteVisitor extends AbstractSqlppExpressionScopi
     }
 
     @Override
-    public Expression visit(VariableExpr varExpr, Expression arg) throws AsterixException {
+    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws AsterixException {
         String varName = varExpr.getVar().getValue();
         if (scopeChecker.isInForbiddenScopes(varName)) {
             throw new AsterixException(
-                    "Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
+                    "Inside limit clauses, it is disallowed to reference a variable having the same name"
+                            + " as any variable bound in the same scope as the limit clause.");
         }
-        if (rewriteNeeded(varExpr)) {
-            return datasetRewrite(varExpr);
-        } else {
+        if (!rewriteNeeded(varExpr)) {
             return varExpr;
         }
+        boolean resolveAsDataset = resolveDatasetFirst(arg)
+                && datasetExists(SqlppVariableUtil.toUserDefinedVariableName(varName).getValue());
+        if (resolveAsDataset) {
+            return wrapWithDatasetFunction(varExpr);
+        }
+        Set<VariableExpr> liveVars = SqlppVariableUtil.getLiveUserDefinedVariables(scopeChecker.getCurrentScope());
+        return wrapWithResolveFunction(varExpr, liveVars);
+    }
+
+    // For From/Join/UNNEST/NEST, we resolve the undefined identifier reference as dataset reference first.
+    private boolean resolveDatasetFirst(ILangExpression arg) {
+        return arg != null;
     }
 
     // Whether a rewrite is needed for a variable reference expression.
@@ -81,22 +97,41 @@ public class VariableCheckAndRewriteVisitor extends AbstractSqlppExpressionScopi
             return false;
         } else {
             // Meets a undefined variable
-            return true;
+            return overwrite;
         }
     }
 
-    // Rewrites for global variable (e.g., dataset) references.
-    private Expression datasetRewrite(VariableExpr expr) throws AsterixException {
-        if (!overwrite) {
-            return expr;
-        }
-        String funcName = "dataset";
-        String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
-        FunctionSignature signature = new FunctionSignature(dataverse, funcName, 1);
-        List<Expression> argList = new ArrayList<Expression>();
+    private Expression wrapWithDatasetFunction(VariableExpr expr) throws AsterixException {
+        List<Expression> argList = new ArrayList<>();
         //Ignore the parser-generated prefix "$" for a dataset.
-        String dataset = SqlppVariableUtil.toUserDefinedVariableName(expr.getVar()).getValue();
-        argList.add(new LiteralExpr(new StringLiteral(dataset)));
-        return new CallExpr(signature, argList);
+        String varName = SqlppVariableUtil.toUserDefinedVariableName(expr.getVar()).getValue();
+        argList.add(new LiteralExpr(new StringLiteral(varName)));
+        return new CallExpr(datasetFunction, argList);
+    }
+
+    private boolean datasetExists(String name) throws AsterixException {
+        try {
+            if (metadataProvider.findDataset(null, name) != null) {
+                return true;
+            }
+            return pathDatasetExists(name);
+        } catch (AlgebricksException e) {
+            throw new AsterixException(e);
+        }
     }
+
+    private boolean pathDatasetExists(String name) throws AlgebricksException {
+        if (!name.contains(".")) {
+            return false;
+        }
+        String[] path = name.split("\\.");
+        if (path.length != 2) {
+            return false;
+        }
+        if (metadataProvider.findDataset(path[0], path[1]) != null) {
+            return true;
+        }
+        return false;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java
new file mode 100644
index 0000000..8817d76
--- /dev/null
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.lang.sqlpp.util;
+
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.base.Expression.Kind;
+import org.apache.asterix.lang.common.expression.FieldAccessor;
+import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.struct.VarIdentifier;
+import org.apache.asterix.lang.sqlpp.parser.ParseException;
+
+public class ExpressionToVariableUtil {
+
+    private ExpressionToVariableUtil() {
+    }
+
+    public static String getGeneratedIdentifier(Expression expr) throws ParseException {
+        if (expr.getKind() == Kind.VARIABLE_EXPRESSION) {
+            VariableExpr bindingVarExpr = (VariableExpr) expr;
+            return bindingVarExpr.getVar().getValue();
+        } else if (expr.getKind() == Kind.FIELD_ACCESSOR_EXPRESSION) {
+            FieldAccessor fa = (FieldAccessor) expr;
+            return SqlppVariableUtil.toInternalVariableName(fa.getIdent().getValue());
+        } else {
+            throw new ParseException("Need an alias for the enclosed " + expr.getKind() + " expression.");
+        }
+    }
+
+    public static VariableExpr getGeneratedVariable(Expression expr) throws ParseException {
+        VarIdentifier var = new VarIdentifier(getGeneratedIdentifier(expr));
+        VariableExpr varExpr = new VariableExpr();
+        varExpr.setVar(var);
+        return varExpr;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java
index 6c737d6..122bde3 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java
@@ -33,11 +33,15 @@ import org.apache.asterix.lang.sqlpp.visitor.FreeVariableVisitor;
 
 public class SqlppRewriteUtil {
 
+    private SqlppRewriteUtil() {
+    }
+
     // Applying sugar rewriting for group-by.
     public static Expression rewriteExpressionUsingGroupVariable(VariableExpr groupVar,
-            Collection<VariableExpr> targetVarList, ILangExpression expr, LangRewritingContext context)
-                    throws AsterixException {
-        SqlppGroupBySugarVisitor visitor = new SqlppGroupBySugarVisitor(context, groupVar, targetVarList);
+            Collection<VariableExpr> targetVarList, Collection<VariableExpr> allVisableVars, ILangExpression expr,
+            LangRewritingContext context) throws AsterixException {
+        SqlppGroupBySugarVisitor visitor = new SqlppGroupBySugarVisitor(context, groupVar, targetVarList,
+                allVisableVars);
         return expr.accept(visitor, null);
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableSubstitutionUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableSubstitutionUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableSubstitutionUtil.java
index 6438f07..322b5b6 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableSubstitutionUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableSubstitutionUtil.java
@@ -45,6 +45,9 @@ public class SqlppVariableSubstitutionUtil {
      */
     public static ILangExpression substituteVariableWithoutContext(ILangExpression expression,
             Map<VariableExpr, Expression> varExprMap) throws AsterixException {
+        if (varExprMap.isEmpty()) {
+            return expression;
+        }
         VariableSubstitutionEnvironment env = new VariableSubstitutionEnvironment(varExprMap);
         return substituteVariableWithoutContext(expression, env);
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java
index 59e9389..12a2d20 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java
@@ -20,6 +20,7 @@ package org.apache.asterix.lang.sqlpp.util;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -27,6 +28,7 @@ import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
+import org.apache.asterix.lang.common.context.Scope;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.struct.VarIdentifier;
@@ -37,7 +39,10 @@ import org.apache.asterix.lang.sqlpp.visitor.FreeVariableVisitor;
 
 public class SqlppVariableUtil {
 
-    private static String USER_VAR_PREFIX = "$";
+    private static final String USER_VAR_PREFIX = "$";
+
+    private SqlppVariableUtil() {
+    }
 
     public static VarIdentifier toUserDefinedVariableName(VarIdentifier var) {
         String varName = var.getValue();
@@ -51,6 +56,30 @@ public class SqlppVariableUtil {
         return new VarIdentifier(varName);
     }
 
+    public static String toUserDefinedName(String varName) {
+        if (varName.startsWith(USER_VAR_PREFIX)) {
+            return varName.substring(1);
+        }
+        return varName;
+    }
+
+    public static Set<VariableExpr> getLiveUserDefinedVariables(Scope scope) {
+        Set<VariableExpr> results = new HashSet<>();
+        Set<VariableExpr> liveVars = scope.getLiveVariables();
+        Iterator<VariableExpr> liveVarIter = liveVars.iterator();
+        while (liveVarIter.hasNext()) {
+            VariableExpr var = liveVarIter.next();
+            if (SqlppVariableUtil.isUserDefinedVariable(var)) {
+                results.add(var);
+            }
+        }
+        return results;
+    }
+
+    private static boolean isUserDefinedVariable(VariableExpr varExpr) {
+        return varExpr.getVar().getValue().startsWith(USER_VAR_PREFIX);
+    }
+
     public static String toInternalVariableName(String varName) {
         return USER_VAR_PREFIX + varName;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
index 1bca7ac..7c46d73 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
@@ -55,6 +55,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.util.FunctionMapUtil;
 import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppQueryExpressionVisitor;
@@ -262,4 +263,9 @@ public class CheckSql92AggregateVisitor extends AbstractSqlppQueryExpressionVisi
         return false;
     }
 
+    @Override
+    public Boolean visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+        return false;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
index 2d891e0..559183e 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
@@ -46,6 +46,7 @@ import org.apache.asterix.lang.common.statement.FunctionDecl;
 import org.apache.asterix.lang.common.statement.Query;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.struct.QuantifiedPair;
+import org.apache.asterix.lang.common.struct.VarIdentifier;
 import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause;
 import org.apache.asterix.lang.sqlpp.clause.FromClause;
 import org.apache.asterix.lang.sqlpp.clause.FromTerm;
@@ -59,6 +60,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.SetOperationInput;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
@@ -389,7 +391,11 @@ public class DeepCopyVisitor extends AbstractSqlppQueryExpressionVisitor<ILangEx
 
     @Override
     public VariableExpr visit(VariableExpr varExpr, Void arg) throws AsterixException {
-        return new VariableExpr(varExpr.getVar());
+        VariableExpr clonedVar = new VariableExpr(
+                new VarIdentifier(varExpr.getVar().getValue(), varExpr.getVar().getId()));
+        clonedVar.setIsNewVar(varExpr.getIsNewVar());
+        clonedVar.setNamedValueAccess(varExpr.namedValueAccess());
+        return clonedVar;
     }
 
     @Override
@@ -412,4 +418,9 @@ public class DeepCopyVisitor extends AbstractSqlppQueryExpressionVisitor<ILangEx
         return new IndexAccessor(expr, indexExpr);
     }
 
+    @Override
+    public ILangExpression visit(IndependentSubquery independentSubquery, Void arg) throws AsterixException {
+        return new IndependentSubquery((Expression) independentSubquery.getExpr().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/visitor/FreeVariableVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java
index 6e70455..37c19ab 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java
@@ -60,6 +60,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.SqlppVariableUtil;
@@ -414,6 +415,12 @@ public class FreeVariableVisitor extends AbstractSqlppQueryExpressionVisitor<Voi
         return null;
     }
 
+    @Override
+    public Void visit(IndependentSubquery independentSubquery, Collection<VariableExpr> arg) throws AsterixException {
+        independentSubquery.getExpr().accept(this, arg);
+        return null;
+    }
+
     private void visitLetClauses(List<LetClause> letClauses, Collection<VariableExpr> freeVars)
             throws AsterixException {
         if (letClauses == null || letClauses.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
index a613e90..589381a 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
@@ -42,6 +42,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.FunctionMapUtil;
@@ -292,4 +293,10 @@ public class SqlppAstPrintVisitor extends QueryPrintVisitor implements ISqlppVis
         return null;
     }
 
+    @Override
+    public Void visit(IndependentSubquery independentSubquery, Integer 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/visitor/SqlppCloneAndSubstituteVariablesVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java
index 62581c8..8ec2b04 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java
@@ -47,6 +47,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.SetOperationInput;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
@@ -367,4 +368,12 @@ public class SqlppCloneAndSubstituteVariablesVisitor extends CloneAndSubstituteV
         return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newHavingClause, p.second);
     }
 
+    @Override
+    public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IndependentSubquery independentSubquery,
+            VariableSubstitutionEnvironment env) throws AsterixException {
+        Pair<ILangExpression, VariableSubstitutionEnvironment> p = independentSubquery.getExpr().accept(this, env);
+        IndependentSubquery newSubquery = new IndependentSubquery((Expression) p.first);
+        return new Pair<>(newSubquery, p.second);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java
index a449402..e03d711 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java
@@ -41,6 +41,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.visitor.base.ISqlppVisitor;
@@ -297,4 +298,10 @@ public class SqlppFormatPrintVisitor extends FormatPrintVisitor implements ISqlp
         }
     }
 
+    @Override
+    public Void visit(IndependentSubquery independentSubquery, Integer step) throws AsterixException {
+        independentSubquery.getExpr().accept(this, step);
+        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/visitor/base/AbstractSqlppAstVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java
index 9907999..e5bf513 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java
@@ -32,6 +32,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;
 
 /**
@@ -104,4 +105,9 @@ public abstract class AbstractSqlppAstVisitor<R, T> extends AbstractAstVisitor<R
         return null;
     }
 
+    @Override
+    public R visit(IndependentSubquery independentSubquery, T arg) throws AsterixException {
+        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/visitor/base/AbstractSqlppExpressionScopingVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
index 14e80d9..599654b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
@@ -18,15 +18,25 @@
  */
 package org.apache.asterix.lang.sqlpp.visitor.base;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.asterix.common.config.MetadataConstants;
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.clause.LimitClause;
 import org.apache.asterix.lang.common.context.Scope;
+import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
+import org.apache.asterix.lang.common.expression.LiteralExpr;
 import org.apache.asterix.lang.common.expression.QuantifiedExpression;
 import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.literal.StringLiteral;
 import org.apache.asterix.lang.common.parser.ScopeChecker;
 import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
 import org.apache.asterix.lang.common.statement.FunctionDecl;
@@ -41,12 +51,17 @@ import org.apache.asterix.lang.sqlpp.clause.JoinClause;
 import org.apache.asterix.lang.sqlpp.clause.NestClause;
 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.SqlppVariableUtil;
 import org.apache.hyracks.algebricks.core.algebra.base.Counter;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 
 public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleExpressionVisitor {
 
+    protected final FunctionSignature resolveFunction = new FunctionSignature(MetadataConstants.METADATA_DATAVERSE_NAME,
+            "resolve", FunctionIdentifier.VARARGS);
     protected final ScopeChecker scopeChecker = new ScopeChecker();
     protected final LangRewritingContext context;
 
@@ -60,19 +75,19 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
     }
 
     @Override
-    public Expression visit(FromClause fromClause, Expression arg) throws AsterixException {
+    public Expression visit(FromClause fromClause, ILangExpression arg) throws AsterixException {
         scopeChecker.extendCurrentScope();
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
-            fromTerm.accept(this, arg);
+            fromTerm.accept(this, fromClause);
         }
         return null;
     }
 
     @Override
-    public Expression visit(FromTerm fromTerm, Expression arg) throws AsterixException {
+    public Expression visit(FromTerm fromTerm, ILangExpression arg) throws AsterixException {
         scopeChecker.createNewScope();
         // Visit the left expression of a from term.
-        fromTerm.setLeftExpression(fromTerm.getLeftExpression().accept(this, arg));
+        fromTerm.setLeftExpression(fromTerm.getLeftExpression().accept(this, fromTerm));
 
         // Registers the data item variable.
         VariableExpr leftVar = fromTerm.getLeftVariable();
@@ -85,20 +100,20 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
         }
         // Visits join/unnest/nest clauses.
         for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
-            correlateClause.accept(this, arg);
+            correlateClause.accept(this, fromTerm);
         }
         return null;
     }
 
     @Override
-    public Expression visit(JoinClause joinClause, Expression arg) throws AsterixException {
+    public Expression visit(JoinClause joinClause, ILangExpression arg) throws AsterixException {
         Scope backupScope = scopeChecker.removeCurrentScope();
         Scope parentScope = scopeChecker.getCurrentScope();
         scopeChecker.createNewScope();
         // NOTE: the two join branches cannot be correlated, instead of checking
         // the correlation here,
         // we defer the check to the query optimizer.
-        joinClause.setRightExpression(joinClause.getRightExpression().accept(this, arg));
+        joinClause.setRightExpression(joinClause.getRightExpression().accept(this, joinClause));
 
         // Registers the data item variable.
         VariableExpr rightVar = joinClause.getRightVariable();
@@ -117,16 +132,16 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
         scopeChecker.pushExistingScope(mergedScope);
         // The condition expression can refer to the just registered variables
         // for the right branch.
-        joinClause.setConditionExpression(joinClause.getConditionExpression().accept(this, arg));
+        joinClause.setConditionExpression(joinClause.getConditionExpression().accept(this, joinClause));
         return null;
     }
 
     @Override
-    public Expression visit(NestClause nestClause, Expression arg) throws AsterixException {
+    public Expression visit(NestClause nestClause, ILangExpression arg) throws AsterixException {
         // NOTE: the two branches of a NEST cannot be correlated, instead of
         // checking the correlation here, we defer the check to the query
         // optimizer.
-        nestClause.setRightExpression(nestClause.getRightExpression().accept(this, arg));
+        nestClause.setRightExpression(nestClause.getRightExpression().accept(this, nestClause));
 
         // Registers the data item variable.
         VariableExpr rightVar = nestClause.getRightVariable();
@@ -140,13 +155,13 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
 
         // The condition expression can refer to the just registered variables
         // for the right branch.
-        nestClause.setConditionExpression(nestClause.getConditionExpression().accept(this, arg));
+        nestClause.setConditionExpression(nestClause.getConditionExpression().accept(this, nestClause));
         return null;
     }
 
     @Override
-    public Expression visit(UnnestClause unnestClause, Expression arg) throws AsterixException {
-        unnestClause.setRightExpression(unnestClause.getRightExpression().accept(this, arg));
+    public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws AsterixException {
+        unnestClause.setRightExpression(unnestClause.getRightExpression().accept(this, unnestClause));
 
         // register the data item variable
         VariableExpr rightVar = unnestClause.getRightVariable();
@@ -161,7 +176,7 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
     }
 
     @Override
-    public Expression visit(SelectSetOperation selectSetOperation, Expression arg) throws AsterixException {
+    public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws AsterixException {
         selectSetOperation.getLeftInput().accept(this, arg);
         for (SetOperationRight right : selectSetOperation.getRightInputs()) {
             scopeChecker.createNewScope();
@@ -171,27 +186,27 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
     }
 
     @Override
-    public Expression visit(Query q, Expression arg) throws AsterixException {
-        q.setBody(q.getBody().accept(this, arg));
+    public Expression visit(Query q, ILangExpression arg) throws AsterixException {
+        q.setBody(q.getBody().accept(this, q));
         q.setVarCounter(scopeChecker.getVarCounter());
         context.setVarCounter(scopeChecker.getVarCounter());
         return null;
     }
 
     @Override
-    public Expression visit(FunctionDecl fd, Expression arg) throws AsterixException {
+    public Expression visit(FunctionDecl fd, ILangExpression arg) throws AsterixException {
         scopeChecker.createNewScope();
-        fd.setFuncBody(fd.getFuncBody().accept(this, arg));
+        fd.setFuncBody(fd.getFuncBody().accept(this, fd));
         scopeChecker.removeCurrentScope();
         return null;
     }
 
     @Override
-    public Expression visit(GroupbyClause gc, Expression arg) throws AsterixException {
+    public Expression visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
         Scope newScope = scopeChecker.extendCurrentScopeNoPush(true);
         // Puts all group-by variables into the symbol set of the new scope.
         for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
-            gbyVarExpr.setExpr(gbyVarExpr.getExpr().accept(this, arg));
+            gbyVarExpr.setExpr(gbyVarExpr.getExpr().accept(this, gc));
             VariableExpr gbyVar = gbyVarExpr.getVar();
             if (gbyVar != null) {
                 newScope.addNewVarSymbolToScope(gbyVarExpr.getVar().getVar());
@@ -205,30 +220,30 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
     }
 
     @Override
-    public Expression visit(LimitClause limitClause, Expression arg) throws AsterixException {
+    public Expression visit(LimitClause limitClause, ILangExpression arg) throws AsterixException {
         scopeChecker.pushForbiddenScope(scopeChecker.getCurrentScope());
-        limitClause.setLimitExpr(limitClause.getLimitExpr().accept(this, arg));
+        limitClause.setLimitExpr(limitClause.getLimitExpr().accept(this, limitClause));
         scopeChecker.popForbiddenScope();
         return null;
     }
 
     @Override
-    public Expression visit(LetClause letClause, Expression arg) throws AsterixException {
+    public Expression visit(LetClause letClause, ILangExpression arg) throws AsterixException {
         scopeChecker.extendCurrentScope();
-        letClause.setBindingExpr(letClause.getBindingExpr().accept(this, arg));
+        letClause.setBindingExpr(letClause.getBindingExpr().accept(this, letClause));
         scopeChecker.getCurrentScope().addNewVarSymbolToScope(letClause.getVarExpr().getVar());
         return null;
     }
 
     @Override
-    public Expression visit(SelectExpression selectExpression, Expression arg) throws AsterixException {
+    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws AsterixException {
         Scope scopeBeforeSelectExpression = scopeChecker.getCurrentScope();
         scopeChecker.createNewScope();
 
         // visit let list
         if (selectExpression.hasLetClauses()) {
             for (LetClause letClause : selectExpression.getLetList()) {
-                letClause.accept(this, arg);
+                letClause.accept(this, selectExpression);
             }
         }
 
@@ -237,12 +252,12 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
 
         // visit order by
         if (selectExpression.hasOrderby()) {
-            selectExpression.getOrderbyClause().accept(this, arg);
+            selectExpression.getOrderbyClause().accept(this, selectExpression);
         }
 
         // visit limit
         if (selectExpression.hasLimit()) {
-            selectExpression.getLimitClause().accept(this, arg);
+            selectExpression.getLimitClause().accept(this, selectExpression);
         }
 
         // Exit scopes that were entered within this select expression
@@ -253,19 +268,31 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
     }
 
     @Override
-    public Expression visit(QuantifiedExpression qe, Expression arg) throws AsterixException {
+    public Expression visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+        // Masks parent scopes so as that the subquery is independent of the environment.
+        // In this way, free variables defined in the subquery will not be resolved using
+        // variables defined in the parent scope.
+        Scope scope = new Scope(scopeChecker, scopeChecker.getCurrentScope(), true);
+        scopeChecker.pushExistingScope(scope);
+        independentSubquery.getExpr().accept(this, arg);
+        scopeChecker.removeCurrentScope();
+        return independentSubquery;
+    }
+
+    @Override
+    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws AsterixException {
         scopeChecker.createNewScope();
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
             scopeChecker.getCurrentScope().addNewVarSymbolToScope(pair.getVarExpr().getVar());
-            pair.setExpr(pair.getExpr().accept(this, arg));
+            pair.setExpr(pair.getExpr().accept(this, qe));
         }
-        qe.setSatisfiesExpr(qe.getSatisfiesExpr().accept(this, arg));
+        qe.setSatisfiesExpr(qe.getSatisfiesExpr().accept(this, qe));
         scopeChecker.removeCurrentScope();
         return qe;
     }
 
     @Override
-    public Expression visit(VariableExpr varExpr, Expression arg) throws AsterixException {
+    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws AsterixException {
         String varName = varExpr.getVar().getValue();
         if (scopeChecker.isInForbiddenScopes(varName)) {
             throw new AsterixException(
@@ -281,4 +308,14 @@ public class AbstractSqlppExpressionScopingVisitor extends AbstractSqlppSimpleEx
         return varExpr;
     }
 
+    // Rewrites for an undefined variable reference, which potentially could be a syntatic sugar.
+    protected Expression wrapWithResolveFunction(VariableExpr expr, Set<VariableExpr> liveVars)
+            throws AsterixException {
+        List<Expression> argList = new ArrayList<>();
+        //Ignore the parser-generated prefix "$" for a dataset.
+        String varName = SqlppVariableUtil.toUserDefinedVariableName(expr.getVar().getValue()).getValue();
+        argList.add(new LiteralExpr(new StringLiteral(varName)));
+        argList.addAll(liveVars);
+        return new CallExpr(resolveFunction, argList);
+    }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
index 18c2789..262b260 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.clause.LimitClause;
@@ -57,13 +58,15 @@ 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;
 
-public class AbstractSqlppSimpleExpressionVisitor extends AbstractSqlppQueryExpressionVisitor<Expression, Expression> {
+public class AbstractSqlppSimpleExpressionVisitor
+        extends AbstractSqlppQueryExpressionVisitor<Expression, ILangExpression> {
 
     @Override
-    public Expression visit(FromClause fromClause, Expression arg) throws AsterixException {
+    public Expression visit(FromClause fromClause, ILangExpression arg) throws AsterixException {
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
             fromTerm.accept(this, arg);
         }
@@ -71,7 +74,7 @@ public class AbstractSqlppSimpleExpressionVisitor extends AbstractSqlppQueryExpr
     }
 
     @Override
-    public Expression visit(FromTerm fromTerm, Expression arg) throws AsterixException {
+    public Expression visit(FromTerm fromTerm, ILangExpression arg) throws AsterixException {
         // Visit the left expression of a from term.
         fromTerm.setLeftExpression(fromTerm.getLeftExpression().accept(this, arg));
 
@@ -83,33 +86,33 @@ public class AbstractSqlppSimpleExpressionVisitor extends AbstractSqlppQueryExpr
     }
 
     @Override
-    public Expression visit(JoinClause joinClause, Expression arg) throws AsterixException {
+    public Expression visit(JoinClause joinClause, ILangExpression arg) throws AsterixException {
         joinClause.setRightExpression(joinClause.getRightExpression().accept(this, arg));
         joinClause.setConditionExpression(joinClause.getConditionExpression().accept(this, arg));
         return null;
     }
 
     @Override
-    public Expression visit(NestClause nestClause, Expression arg) throws AsterixException {
+    public Expression visit(NestClause nestClause, ILangExpression arg) throws AsterixException {
         nestClause.setRightExpression(nestClause.getRightExpression().accept(this, arg));
         nestClause.setConditionExpression(nestClause.getConditionExpression().accept(this, arg));
         return null;
     }
 
     @Override
-    public Expression visit(UnnestClause unnestClause, Expression arg) throws AsterixException {
+    public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws AsterixException {
         unnestClause.setRightExpression(unnestClause.getRightExpression().accept(this, arg));
         return null;
     }
 
     @Override
-    public Expression visit(Projection projection, Expression arg) throws AsterixException {
+    public Expression visit(Projection projection, ILangExpression arg) throws AsterixException {
         projection.setExpression(projection.getExpression().accept(this, arg));
         return null;
     }
 
     @Override
-    public Expression visit(SelectBlock selectBlock, Expression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
         // Traverses the select block in the order of "from", "let"s, "where",
         // "group by", "let"s, "having" and "select".
         if (selectBlock.hasFromClause()) {
@@ -141,24 +144,24 @@ public class AbstractSqlppSimpleExpressionVisitor extends AbstractSqlppQueryExpr
     }
 
     @Override
-    public Expression visit(SelectClause selectClause, Expression arg) throws AsterixException {
+    public Expression visit(SelectClause selectClause, ILangExpression arg) throws AsterixException {
         if (selectClause.selectElement()) {
-            selectClause.getSelectElement().accept(this, arg);
+            selectClause.getSelectElement().accept(this, selectClause);
         }
         if (selectClause.selectRegular()) {
-            selectClause.getSelectRegular().accept(this, arg);
+            selectClause.getSelectRegular().accept(this, selectClause);
         }
         return null;
     }
 
     @Override
-    public Expression visit(SelectElement selectElement, Expression arg) throws AsterixException {
-        selectElement.setExpression(selectElement.getExpression().accept(this, arg));
+    public Expression visit(SelectElement selectElement, ILangExpression arg) throws AsterixException {
+        selectElement.setExpression(selectElement.getExpression().accept(this, selectElement));
         return null;
     }
 
     @Override
-    public Expression visit(SelectRegular selectRegular, Expression arg) throws AsterixException {
+    public Expression visit(SelectRegular selectRegular, ILangExpression arg) throws AsterixException {
         for (Projection projection : selectRegular.getProjections()) {
             projection.accept(this, arg);
         }
@@ -166,7 +169,7 @@ public class AbstractSqlppSimpleExpressionVisitor extends AbstractSqlppQueryExpr
     }
 
     @Override
-    public Expression visit(SelectSetOperation selectSetOperation, Expression arg) throws AsterixException {
+    public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws AsterixException {
         selectSetOperation.getLeftInput().accept(this, arg);
         for (SetOperationRight right : selectSetOperation.getRightInputs()) {
             right.getSetOperationRightInput().accept(this, arg);
@@ -175,173 +178,179 @@ public class AbstractSqlppSimpleExpressionVisitor extends AbstractSqlppQueryExpr
     }
 
     @Override
-    public Expression visit(HavingClause havingClause, Expression arg) throws AsterixException {
-        havingClause.setFilterExpression(havingClause.getFilterExpression().accept(this, arg));
+    public Expression visit(HavingClause havingClause, ILangExpression arg) throws AsterixException {
+        havingClause.setFilterExpression(havingClause.getFilterExpression().accept(this, havingClause));
         return null;
     }
 
     @Override
-    public Expression visit(Query q, Expression arg) throws AsterixException {
-        q.setBody(q.getBody().accept(this, arg));
+    public Expression visit(Query q, ILangExpression arg) throws AsterixException {
+        q.setBody(q.getBody().accept(this, q));
         return null;
     }
 
     @Override
-    public Expression visit(FunctionDecl fd, Expression arg) throws AsterixException {
-        fd.setFuncBody(fd.getFuncBody().accept(this, arg));
+    public Expression visit(FunctionDecl fd, ILangExpression arg) throws AsterixException {
+        fd.setFuncBody(fd.getFuncBody().accept(this, fd));
         return null;
     }
 
     @Override
-    public Expression visit(WhereClause whereClause, Expression arg) throws AsterixException {
-        whereClause.setWhereExpr(whereClause.getWhereExpr().accept(this, arg));
+    public Expression visit(WhereClause whereClause, ILangExpression arg) throws AsterixException {
+        whereClause.setWhereExpr(whereClause.getWhereExpr().accept(this, whereClause));
         return null;
     }
 
     @Override
-    public Expression visit(OrderbyClause oc, Expression arg) throws AsterixException {
-        List<Expression> newOrderbyList = new ArrayList<Expression>();
+    public Expression visit(OrderbyClause oc, ILangExpression arg) throws AsterixException {
+        List<Expression> newOrderbyList = new ArrayList<>();
         for (Expression orderExpr : oc.getOrderbyList()) {
-            newOrderbyList.add(orderExpr.accept(this, arg));
+            newOrderbyList.add(orderExpr.accept(this, oc));
         }
         oc.setOrderbyList(newOrderbyList);
         return null;
     }
 
     @Override
-    public Expression visit(GroupbyClause gc, Expression arg) throws AsterixException {
+    public Expression visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
         for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
-            gbyVarExpr.setExpr(gbyVarExpr.getExpr().accept(this, arg));
+            gbyVarExpr.setExpr(gbyVarExpr.getExpr().accept(this, gc));
         }
         return null;
     }
 
     @Override
-    public Expression visit(LimitClause limitClause, Expression arg) throws AsterixException {
-        limitClause.setLimitExpr(limitClause.getLimitExpr().accept(this, arg));
+    public Expression visit(LimitClause limitClause, ILangExpression arg) throws AsterixException {
+        limitClause.setLimitExpr(limitClause.getLimitExpr().accept(this, limitClause));
         if (limitClause.hasOffset()) {
-            limitClause.setOffset(limitClause.getOffset().accept(this, arg));
+            limitClause.setOffset(limitClause.getOffset().accept(this, limitClause));
         }
         return null;
     }
 
     @Override
-    public Expression visit(LetClause letClause, Expression arg) throws AsterixException {
-        letClause.setBindingExpr(letClause.getBindingExpr().accept(this, arg));
+    public Expression visit(LetClause letClause, ILangExpression arg) throws AsterixException {
+        letClause.setBindingExpr(letClause.getBindingExpr().accept(this, letClause));
         return null;
     }
 
     @Override
-    public Expression visit(SelectExpression selectExpression, Expression arg) throws AsterixException {
+    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws AsterixException {
         // visit let list
         if (selectExpression.hasLetClauses()) {
             for (LetClause letClause : selectExpression.getLetList()) {
-                letClause.accept(this, arg);
+                letClause.accept(this, selectExpression);
             }
         }
 
         // visit the main select.
-        selectExpression.getSelectSetOperation().accept(this, arg);
+        selectExpression.getSelectSetOperation().accept(this, selectExpression);
 
         // visit order by
         if (selectExpression.hasOrderby()) {
             for (Expression orderExpr : selectExpression.getOrderbyClause().getOrderbyList()) {
-                orderExpr.accept(this, arg);
+                orderExpr.accept(this, selectExpression);
             }
         }
 
         // visit limit
         if (selectExpression.hasLimit()) {
-            selectExpression.getLimitClause().accept(this, arg);
+            selectExpression.getLimitClause().accept(this, selectExpression);
         }
         return selectExpression;
     }
 
     @Override
-    public Expression visit(LiteralExpr l, Expression arg) throws AsterixException {
+    public Expression visit(LiteralExpr l, ILangExpression arg) throws AsterixException {
         return l;
     }
 
     @Override
-    public Expression visit(ListConstructor lc, Expression arg) throws AsterixException {
-        List<Expression> newExprList = new ArrayList<Expression>();
+    public Expression visit(ListConstructor lc, ILangExpression arg) throws AsterixException {
+        List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : lc.getExprList()) {
-            newExprList.add(expr.accept(this, arg));
+            newExprList.add(expr.accept(this, lc));
         }
         lc.setExprList(newExprList);
         return lc;
     }
 
     @Override
-    public Expression visit(RecordConstructor rc, Expression arg) throws AsterixException {
+    public Expression visit(RecordConstructor rc, ILangExpression arg) throws AsterixException {
         for (FieldBinding binding : rc.getFbList()) {
-            binding.setLeftExpr(binding.getLeftExpr().accept(this, arg));
-            binding.setRightExpr(binding.getRightExpr().accept(this, arg));
+            binding.setLeftExpr(binding.getLeftExpr().accept(this, rc));
+            binding.setRightExpr(binding.getRightExpr().accept(this, rc));
         }
         return rc;
     }
 
     @Override
-    public Expression visit(OperatorExpr operatorExpr, Expression arg) throws AsterixException {
-        List<Expression> newExprList = new ArrayList<Expression>();
+    public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws AsterixException {
+        List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : operatorExpr.getExprList()) {
-            newExprList.add(expr.accept(this, arg));
+            newExprList.add(expr.accept(this, operatorExpr));
         }
         operatorExpr.setExprList(newExprList);
         return operatorExpr;
     }
 
     @Override
-    public Expression visit(IfExpr ifExpr, Expression arg) throws AsterixException {
-        ifExpr.setCondExpr(ifExpr.getCondExpr().accept(this, arg));
-        ifExpr.setThenExpr(ifExpr.getThenExpr().accept(this, arg));
-        ifExpr.setElseExpr(ifExpr.getElseExpr().accept(this, arg));
+    public Expression visit(IfExpr ifExpr, ILangExpression arg) throws AsterixException {
+        ifExpr.setCondExpr(ifExpr.getCondExpr().accept(this, ifExpr));
+        ifExpr.setThenExpr(ifExpr.getThenExpr().accept(this, ifExpr));
+        ifExpr.setElseExpr(ifExpr.getElseExpr().accept(this, ifExpr));
         return ifExpr;
     }
 
     @Override
-    public Expression visit(QuantifiedExpression qe, Expression arg) throws AsterixException {
+    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws AsterixException {
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
-            pair.setExpr(pair.getExpr().accept(this, arg));
+            pair.setExpr(pair.getExpr().accept(this, qe));
         }
-        qe.setSatisfiesExpr(qe.getSatisfiesExpr().accept(this, arg));
+        qe.setSatisfiesExpr(qe.getSatisfiesExpr().accept(this, qe));
         return qe;
     }
 
     @Override
-    public Expression visit(CallExpr callExpr, Expression arg) throws AsterixException {
-        List<Expression> newExprList = new ArrayList<Expression>();
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+        List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : callExpr.getExprList()) {
-            newExprList.add(expr.accept(this, arg));
+            newExprList.add(expr.accept(this, callExpr));
         }
         callExpr.setExprList(newExprList);
         return callExpr;
     }
 
     @Override
-    public Expression visit(VariableExpr varExpr, Expression arg) throws AsterixException {
+    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws AsterixException {
         return varExpr;
     }
 
     @Override
-    public Expression visit(UnaryExpr u, Expression arg) throws AsterixException {
-        u.setExpr(u.getExpr().accept(this, arg));
+    public Expression visit(UnaryExpr u, ILangExpression arg) throws AsterixException {
+        u.setExpr(u.getExpr().accept(this, u));
         return u;
     }
 
     @Override
-    public Expression visit(FieldAccessor fa, Expression arg) throws AsterixException {
-        fa.setExpr(fa.getExpr().accept(this, arg));
+    public Expression visit(FieldAccessor fa, ILangExpression arg) throws AsterixException {
+        fa.setExpr(fa.getExpr().accept(this, fa));
         return fa;
     }
 
     @Override
-    public Expression visit(IndexAccessor ia, Expression arg) throws AsterixException {
-        ia.setExpr(ia.getExpr().accept(this, arg));
+    public Expression visit(IndexAccessor ia, ILangExpression arg) throws AsterixException {
+        ia.setExpr(ia.getExpr().accept(this, ia));
         if (ia.getIndexExpr() != null) {
             ia.setIndexExpr(ia.getIndexExpr());
         }
         return ia;
     }
 
+    @Override
+    public Expression visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+        independentSubquery.setExpr(independentSubquery.getExpr().accept(this, arg));
+        return independentSubquery;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java
index 538d9c3..4e5e58d 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java
@@ -32,6 +32,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;
 
 public interface ISqlppVisitor<R, T> extends ILangVisitor<R, T> {
@@ -61,4 +62,6 @@ public interface ISqlppVisitor<R, T> extends ILangVisitor<R, T> {
     R visit(UnnestClause unnestClause, T arg) throws AsterixException;
 
     R visit(HavingClause havingClause, T arg) throws AsterixException;
+
+    R visit(IndependentSubquery independentSubquery, T arg) throws AsterixException;
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.html
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.html b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.html
index 8aecbd9..34f576f 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.html
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.html
@@ -833,7 +833,7 @@
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod100">Projection</A></TD>
 <TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
-<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod44">Expression</A> ( &lt;AS&gt; )? <A HREF="#prod18">Identifier</A> | <A HREF="#prod44">Expression</A> &lt;DOT&gt; &lt;MUL&gt; | &lt;MUL&gt; )</TD>
+<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod44">Expression</A> ( ( &lt;AS&gt; )? <A HREF="#prod18">Identifier</A> )? | <A HREF="#prod44">Expression</A> &lt;DOT&gt; &lt;MUL&gt; | &lt;MUL&gt; )</TD>
 </TR>
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod94">FromClause</A></TD>
@@ -843,22 +843,22 @@
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod101">FromTerm</A></TD>
 <TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
-<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod44">Expression</A> ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )? ( ( <A HREF="#prod102">JoinType</A> )? ( <A HREF="#prod103">JoinClause</A> | <A HREF="#prod104">NestClause</A> | <A HREF="#prod105">UnnestClause</A> ) )*</TD>
+<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod44">Expression</A> ( ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> )? ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )? ( ( <A HREF="#prod102">JoinType</A> )? ( <A HREF="#prod103">JoinClause</A> | <A HREF="#prod104">NestClause</A> | <A HREF="#prod105">UnnestClause</A> ) )*</TD>
 </TR>
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod103">JoinClause</A></TD>
 <TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
-<TD ALIGN=LEFT VALIGN=BASELINE>&lt;JOIN&gt; <A HREF="#prod44">Expression</A> ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )? &lt;ON&gt; <A HREF="#prod44">Expression</A></TD>
+<TD ALIGN=LEFT VALIGN=BASELINE>&lt;JOIN&gt; <A HREF="#prod44">Expression</A> ( ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> )? ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )? &lt;ON&gt; <A HREF="#prod44">Expression</A></TD>
 </TR>
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod104">NestClause</A></TD>
 <TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
-<TD ALIGN=LEFT VALIGN=BASELINE>&lt;NEST&gt; <A HREF="#prod44">Expression</A> ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )? &lt;ON&gt; <A HREF="#prod44">Expression</A></TD>
+<TD ALIGN=LEFT VALIGN=BASELINE>&lt;NEST&gt; <A HREF="#prod44">Expression</A> ( ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> )? ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )? &lt;ON&gt; <A HREF="#prod44">Expression</A></TD>
 </TR>
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod105">UnnestClause</A></TD>
 <TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
-<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;UNNEST&gt; | &lt;CORRELATE&gt; | &lt;FLATTEN&gt; ) <A HREF="#prod44">Expression</A> ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )?</TD>
+<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;UNNEST&gt; | &lt;CORRELATE&gt; | &lt;FLATTEN&gt; ) <A HREF="#prod44">Expression</A> ( ( &lt;AS&gt; )? <A HREF="#prod50">Variable</A> ) ( &lt;AT&gt; <A HREF="#prod50">Variable</A> )?</TD>
 </TR>
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod102">JoinType</A></TD>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 05acb1d..f587e50 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -143,6 +143,7 @@ import org.apache.asterix.lang.sqlpp.optype.JoinType;
 import org.apache.asterix.lang.sqlpp.optype.SetOpType;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
+import org.apache.asterix.lang.sqlpp.util.ExpressionToVariableUtil;
 import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.common.utils.Triple;
@@ -2352,11 +2353,14 @@ Projection Projection() throws ParseException: {
 {
   (
     LOOKAHEAD(2)
-    expr= Expression() (<AS>)? name = Identifier()
+    expr = Expression() ((<AS>)? name = Identifier())?
     | expr = Expression() <DOT> <MUL> {exprStar = true; }
     | <MUL> {star = true; }
   )
   {
+    if(name == null){
+       name = SqlppVariableUtil.toUserDefinedName(ExpressionToVariableUtil.getGeneratedIdentifier(expr));
+    }
     return new Projection(expr, name, star, exprStar);
   }
 }
@@ -2385,7 +2389,7 @@ FromTerm FromTerm() throws ParseException :
   List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>();
 }
 {
-  leftExpr = Expression() (<AS>)? leftVar = Variable() (<AT> posVar = Variable())?
+  leftExpr = Expression() ((<AS>)? leftVar = Variable())? (<AT> posVar = Variable())?
   (
      {JoinType joinType = JoinType.INNER; }
      (joinType = JoinType())?
@@ -2403,6 +2407,9 @@ FromTerm FromTerm() throws ParseException :
      }
   )*
   {
+    if(leftVar==null){
+        leftVar = ExpressionToVariableUtil.getGeneratedVariable(leftExpr);
+    }
     return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
   }
 }
@@ -2415,8 +2422,11 @@ JoinClause JoinClause(JoinType joinType) throws ParseException :
     Expression conditionExpr = null;
 }
 {
-  <JOIN> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
+  <JOIN> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
   {
+    if(rightVar==null){
+        rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr);
+    }
     return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
   }
 }
@@ -2429,8 +2439,11 @@ NestClause NestClause(JoinType joinType) throws ParseException :
     Expression conditionExpr = null;
 }
 {
-  <NEST> rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())?  <ON> conditionExpr = Expression()
+  <NEST> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())?  <ON> conditionExpr = Expression()
   {
+    if(rightVar==null){
+        rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr);
+    }
     return new NestClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
   }
 }
@@ -2442,8 +2455,11 @@ UnnestClause UnnestClause(JoinType joinType) throws ParseException :
     VariableExpr posVar = null;
 }
 {
-  (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() (<AS>)? rightVar = Variable() (<AT> posVar = Variable())?
+  (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())?
   {
+    if(rightVar==null){
+        rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr);
+    }
     return new UnnestClause(joinType, rightExpr, rightVar, posVar);
   }
 }
@@ -2572,15 +2588,24 @@ GroupbyClause GroupbyClause()throws ParseException :
         var = Variable()
         )?
         {
+            if(var==null){
+                var = ExpressionToVariableUtil.getGeneratedVariable(expr);
+            }
             GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
             vePairList.add(pair1);
         }
        ( LOOKAHEAD(1) <COMMA>
+         {
+            var = null;
+         }
          expr = Expression()
          (LOOKAHEAD(1)  (<AS>)?
          var = Variable()
          )?
          {
+             if(var==null){
+                var = ExpressionToVariableUtil.getGeneratedVariable(expr);
+             }
              GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
              vePairList.add(pair2);
          }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java
index 7557b79..226ab3c 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java
@@ -2104,8 +2104,13 @@ public class AqlMetadataProvider implements IMetadataProvider<AqlSourceId, Strin
     }
 
     public Dataset findDataset(String dataverse, String dataset) throws AlgebricksException {
+        String dv = dataverse == null ? (defaultDataverse == null ? null : defaultDataverse.getDataverseName())
+                : dataverse;
+        if (dv == null) {
+            return null;
+        }
         try {
-            return MetadataManager.INSTANCE.getDataset(mdTxnCtx, dataverse, dataset);
+            return MetadataManager.INSTANCE.getDataset(mdTxnCtx, dv, dataset);
         } catch (MetadataException e) {
             throw new AlgebricksException(e);
         }


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

Posted by bu...@apache.org.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.3.query.sqlpp
new file mode 100644
index 0000000..cfe9557
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.3.query.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue785
+ * https://code.google.com/p/asterixdb/issues/detail?id=785
+ * Expected Res : SUCCESS
+ * Date         : 2nd Oct. 2014
+ */
+
+USE tpch;
+
+
+WITH  t AS (
+      SELECT nation.n_nationkey, nation.n_name
+      FROM  Nation AS nation,
+            SelectedNation AS sn
+      WHERE nation.n_nationkey = sn.n_nationkey
+),
+X as (
+      SELECT nation_key, orderdate AS order_date, sum(o_totalprice) AS sum_price
+      FROM  t,
+            Customer,
+            Orders
+      WHERE o_custkey = c_custkey and c_nationkey = n_nationkey
+      GROUP BY o_orderdate AS orderdate, n_nationkey AS nation_key
+)
+
+SELECT nation_key,
+       (
+            SELECT order_date AS orderdate, sum_price
+            FROM  X // the X here refers to implicit variable X defined in the outer FROM.
+            ORDER BY sum_price desc
+            LIMIT 3
+        ) AS sum_price
+FROM  X
+GROUP BY nation_key
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.1.ddl.sqlpp
new file mode 100644
index 0000000..18e3fa1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.1.ddl.sqlpp
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue785
+ * https://code.google.com/p/asterixdb/issues/detail?id=785
+ * Expected Res : SUCCESS
+ * Date         : 2nd Oct. 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+
+create  table SelectedNation(NationType) primary key n_nationkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.2.update.sqlpp
new file mode 100644
index 0000000..23539e7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.2.update.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue785
+ * https://code.google.com/p/asterixdb/issues/detail?id=785
+ * Expected Res : SUCCESS
+ * Date         : 2nd Oct. 2014
+ */
+
+use tpch;
+
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table SelectedNation using localfs ((`path`=`asterix_nc1://data/tpch0.001/selectednation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.3.query.sqlpp
new file mode 100644
index 0000000..113df95
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785/query-issue785.3.query.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue785
+ * https://code.google.com/p/asterixdb/issues/detail?id=785
+ * Expected Res : SUCCESS
+ * Date         : 2nd Oct. 2014
+ */
+
+USE tpch;
+
+
+SELECT  nation_key,
+        (
+            SELECT od AS orderdate,  sum_price
+            FROM x
+            GROUP BY order_date AS od
+            LET sum_price = sum(sum_price)
+            ORDER BY sum_price desc
+            LIMIT 3
+        ) AS sum_price
+FROM  (
+        SELECT nation_key, orderdate AS order_date, sum(o_totalprice) AS sum_price
+        FROM  Nation,
+              Customer,
+              Orders AS orders
+        WHERE o_custkey = c_custkey AND c_nationkey = n_nationkey
+        GROUP BY o_orderdate as orderdate, n_nationkey as nation_key
+) AS x
+GROUP BY nation_key
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.1.ddl.sqlpp
new file mode 100644
index 0000000..33f5419
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.1.ddl.sqlpp
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue786
+ * https://code.google.com/p/asterixdb/issues/detail?id=786
+ * Expected Res : SUCCESS
+ * Date         : 10th Oct. 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+
+create  table SelectedNation(NationType) primary key n_nationkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.2.update.sqlpp
new file mode 100644
index 0000000..9c8bfd6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.2.update.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue786
+ * https://code.google.com/p/asterixdb/issues/detail?id=786
+ * Expected Res : SUCCESS
+ * Date         : 10th Oct. 2014
+ */
+
+use tpch;
+
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table SelectedNation using localfs ((`path`=`asterix_nc1://data/tpch0.001/selectednation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.3.query.sqlpp
new file mode 100644
index 0000000..a9fc808
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue786/query-issue786.3.query.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue786
+ * https://code.google.com/p/asterixdb/issues/detail?id=786
+ * Expected Res : SUCCESS
+ * Date         : 10th Oct. 2014
+ */
+
+USE tpch;
+
+
+SELECT  nation.n_nationkey AS nation_key,
+        nation.n_name AS name,
+        (
+            SELECT orderdate AS order_date, sum(o_totalprice) AS sum_price
+            FROM  Orders,
+                  Customer
+            WHERE o_custkey = c_custkey AND c_nationkey = nation.n_nationkey
+            GROUP BY o_orderdate as orderdate
+            ORDER BY sum_price DESC
+            LIMIT 3
+        ) AS aggregates
+FROM  Nation AS nation,
+      SelectedNation AS sn
+WHERE nation.n_nationkey = sn.sn_nationkey
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.ddl.sqlpp
new file mode 100644
index 0000000..b26ac3d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.1.ddl.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.2.update.sqlpp
new file mode 100644
index 0000000..6f25576
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.2.update.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.3.query.sqlpp
new file mode 100644
index 0000000..e361e74
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-2/query-issue810-2.3.query.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+use tpch;
+
+
+SELECT l_returnflag,
+       l_linestatus,
+       coll_count(cheaps) AS count_cheaps,
+       total_charges AS total_charges
+FROM  LineItem as l
+WHERE l_shipdate <= '1998-09-02'
+/* +hash */
+GROUP BY l_returnflag, l_linestatus
+WITH  cheaps AS (
+      SELECT ELEMENT l
+      FROM  l
+      WHERE l_discount > 0.05
+  ),
+total_charges AS sum(l_extendedprice * (1 - l_discount) * (1 + l_tax))
+ORDER BY l_returnflag,l_linestatus
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.ddl.sqlpp
new file mode 100644
index 0000000..b26ac3d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.1.ddl.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.2.update.sqlpp
new file mode 100644
index 0000000..6f25576
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.2.update.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.3.query.sqlpp
new file mode 100644
index 0000000..d8c9222
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810-3/query-issue810-3.3.query.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+USE tpch;
+
+
+SELECT  l_returnflag,
+        l_linestatus,
+        coll_count(cheaps) AS count_cheaps,
+        coll_avg(expensives) AS avg_expensive_discounts,
+        sum_disc_prices AS sum_disc_prices,
+        total_charges AS total_charges
+FROM  LineItem AS l
+WHERE l_shipdate <= '1998-09-02'
+/* +hash */
+GROUP BY l_returnflag, l_linestatus
+WITH  expensives AS (
+      SELECT ELEMENT l_discount
+      FROM  l
+      WHERE l_discount <= 0.05
+      ),
+cheaps as (
+      SELECT ELEMENT l
+      FROM  l
+      WHERE l_discount > 0.05
+  ),
+sum_disc_prices AS sum(l_extendedprice * (1 - l_discount)),
+total_charges AS sum(l_extendedprice * (1 - l_discount) * (1 + l_tax))
+ORDER BY l_returnflag,l_linestatus
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.1.ddl.sqlpp
new file mode 100644
index 0000000..b26ac3d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.1.ddl.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.2.update.sqlpp
new file mode 100644
index 0000000..6f25576
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.2.update.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.3.query.sqlpp
new file mode 100644
index 0000000..cf9582a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue810/query-issue810.3.query.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date         : 16th Nov. 2014
+ */
+
+USE tpch;
+
+
+SELECT l_returnflag,
+       l_linestatus,
+       coll_count(cheap) AS count_cheaps,
+       coll_count(expensive) AS count_expensives
+FROM LineItem AS l
+WHERE l_shipdate <= '1998-09-02'
+/* +hash */
+GROUP BY l_returnflag, l_linestatus
+LET  cheap = (
+      SELECT ELEMENT l
+      FROM l
+      WHERE l_discount > 0.05
+),
+expensive = (
+      SELECT ELEMENT l
+      FROM l
+      WHERE l_discount <= 0.05
+)
+ORDER BY l_returnflag,l_linestatus
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/records/record-add-fields/highly-nested-open/highly-nested-open.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/records/record-add-fields/highly-nested-open/highly-nested-open.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/records/record-add-fields/highly-nested-open/highly-nested-open.3.adm
index e2c1091..44de144 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/records/record-add-fields/highly-nested-open/highly-nested-open.3.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/records/record-add-fields/highly-nested-open/highly-nested-open.3.adm
@@ -1,4 +1,4 @@
-{ "id": 1, "animal-info": "Test information", "class": { "id": 1, "fullClassification": { "id": 1, "Kingdom": "Animalia", "lower": { "id": 1, "Phylum": "Chordata", "lower": { "id": 1, "Class": "Mammalia", "lower": { "id": 1, "Order": "Carnivora", "lower": { "id": 1, "Family": "Mustelinae", "lower": { "id": 1, "Genus": "Gulo", "lower": { "id": 1, "Species": "Gulo" } } } } } } } } }
-{ "id": 2, "animal-info": "Test information", "class": { "id": 2, "fullClassification": { "id": 2, "Kingdom": "Animalia", "lower": { "id": 2, "Phylum": "Chordata", "lower": { "id": 2, "Class": "Mammalia", "lower": { "id": 2, "Order": "Artiodactyla", "lower": { "id": 2, "Family": "Giraffidae", "lower": { "id": 2, "Genus": "Okapia", "lower": { "id": 2, "Species": "Johnstoni" } } } } } } } } }
-{ "id": 3, "animal-info": "Test information", "class": { "id": 3, "fullClassification": { "id": 3, "Kingdom": "Animalia", "lower": { "id": 3, "Phylum": "Chordata", "lower": { "id": 3, "Class": "Mammalia", "lower": { "id": 3, "Order": "Atlantogenata", "lower": { "id": 3, "Family": "Afrotheria", "lower": { "id": 3, "Genus": "Paenungulata", "lower": { "id": 3, "Species": "Hyracoidea" } } } } } } } } }
-{ "id": 4, "animal-info": "Test information", "class": { "id": 4, "fullClassification": { "id": 4, "Kingdom": "Animalia", "lower": { "id": 4, "Phylum": "Chordata", "lower": { "id": 4, "Class": "Aves", "lower": { "id": 4, "Order": "Accipitriformes", "lower": { "id": 4, "Family": "Accipitridae", "lower": { "id": 4, "Genus": "Buteo", "lower": { "id": 4, "Species": "Jamaicensis" } } } } } } } } }
+{ "id": 1, "class": { "id": 1, "fullClassification": { "id": 1, "Kingdom": "Animalia", "lower": { "id": 1, "Phylum": "Chordata", "lower": { "id": 1, "Class": "Mammalia", "lower": { "id": 1, "Order": "Carnivora", "lower": { "id": 1, "Family": "Mustelinae", "lower": { "id": 1, "Genus": "Gulo", "lower": { "id": 1, "Species": "Gulo" } } } } } } } }, "animal-info": "Test information" }
+{ "id": 2, "class": { "id": 2, "fullClassification": { "id": 2, "Kingdom": "Animalia", "lower": { "id": 2, "Phylum": "Chordata", "lower": { "id": 2, "Class": "Mammalia", "lower": { "id": 2, "Order": "Artiodactyla", "lower": { "id": 2, "Family": "Giraffidae", "lower": { "id": 2, "Genus": "Okapia", "lower": { "id": 2, "Species": "Johnstoni" } } } } } } } }, "animal-info": "Test information" }
+{ "id": 3, "class": { "id": 3, "fullClassification": { "id": 3, "Kingdom": "Animalia", "lower": { "id": 3, "Phylum": "Chordata", "lower": { "id": 3, "Class": "Mammalia", "lower": { "id": 3, "Order": "Atlantogenata", "lower": { "id": 3, "Family": "Afrotheria", "lower": { "id": 3, "Genus": "Paenungulata", "lower": { "id": 3, "Species": "Hyracoidea" } } } } } } } }, "animal-info": "Test information" }
+{ "id": 4, "class": { "id": 4, "fullClassification": { "id": 4, "Kingdom": "Animalia", "lower": { "id": 4, "Phylum": "Chordata", "lower": { "id": 4, "Class": "Aves", "lower": { "id": 4, "Order": "Accipitriformes", "lower": { "id": 4, "Family": "Accipitridae", "lower": { "id": 4, "Genus": "Buteo", "lower": { "id": 4, "Species": "Jamaicensis" } } } } } } } }, "animal-info": "Test information" }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/distinct_by/distinct_by.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/distinct_by/distinct_by.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/distinct_by/distinct_by.1.adm
new file mode 100644
index 0000000..472cb64
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/distinct_by/distinct_by.1.adm
@@ -0,0 +1,28 @@
+{ "l_returnflag": "A", "l_linestatus": "F", "l_shipmode": "AIR" }
+{ "l_returnflag": "A", "l_linestatus": "F", "l_shipmode": "FOB" }
+{ "l_returnflag": "A", "l_linestatus": "F", "l_shipmode": "MAIL" }
+{ "l_returnflag": "A", "l_linestatus": "F", "l_shipmode": "RAIL" }
+{ "l_returnflag": "A", "l_linestatus": "F", "l_shipmode": "REG AIR" }
+{ "l_returnflag": "A", "l_linestatus": "F", "l_shipmode": "SHIP" }
+{ "l_returnflag": "A", "l_linestatus": "F", "l_shipmode": "TRUCK" }
+{ "l_returnflag": "N", "l_linestatus": "F", "l_shipmode": "AIR" }
+{ "l_returnflag": "N", "l_linestatus": "F", "l_shipmode": "FOB" }
+{ "l_returnflag": "N", "l_linestatus": "F", "l_shipmode": "MAIL" }
+{ "l_returnflag": "N", "l_linestatus": "F", "l_shipmode": "RAIL" }
+{ "l_returnflag": "N", "l_linestatus": "F", "l_shipmode": "REG AIR" }
+{ "l_returnflag": "N", "l_linestatus": "F", "l_shipmode": "SHIP" }
+{ "l_returnflag": "N", "l_linestatus": "F", "l_shipmode": "TRUCK" }
+{ "l_returnflag": "N", "l_linestatus": "O", "l_shipmode": "AIR" }
+{ "l_returnflag": "N", "l_linestatus": "O", "l_shipmode": "FOB" }
+{ "l_returnflag": "N", "l_linestatus": "O", "l_shipmode": "MAIL" }
+{ "l_returnflag": "N", "l_linestatus": "O", "l_shipmode": "RAIL" }
+{ "l_returnflag": "N", "l_linestatus": "O", "l_shipmode": "REG AIR" }
+{ "l_returnflag": "N", "l_linestatus": "O", "l_shipmode": "SHIP" }
+{ "l_returnflag": "N", "l_linestatus": "O", "l_shipmode": "TRUCK" }
+{ "l_returnflag": "R", "l_linestatus": "F", "l_shipmode": "AIR" }
+{ "l_returnflag": "R", "l_linestatus": "F", "l_shipmode": "FOB" }
+{ "l_returnflag": "R", "l_linestatus": "F", "l_shipmode": "MAIL" }
+{ "l_returnflag": "R", "l_linestatus": "F", "l_shipmode": "RAIL" }
+{ "l_returnflag": "R", "l_linestatus": "F", "l_shipmode": "REG AIR" }
+{ "l_returnflag": "R", "l_linestatus": "F", "l_shipmode": "SHIP" }
+{ "l_returnflag": "R", "l_linestatus": "F", "l_shipmode": "TRUCK" }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/group_no_agg/group_no_agg.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/group_no_agg/group_no_agg.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/group_no_agg/group_no_agg.1.adm
new file mode 100644
index 0000000..4b43fed
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/group_no_agg/group_no_agg.1.adm
@@ -0,0 +1,5 @@
+"AFRICA"
+"AMERICA"
+"ASIA"
+"EUROPE"
+"MIDDLE EAST"

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.adm
new file mode 100644
index 0000000..428af08
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate/nest_aggregate.1.adm
@@ -0,0 +1,11 @@
+{ "nation_key": 0, "name": "ALGERIA", "aggregates": [ { "order_date": "1994-05-27", "sum_price": 1051.15d }, { "order_date": "1994-05-08", "sum_price": 4819.91d }, { "order_date": "1993-08-27", "sum_price": 10500.27d } ] }
+{ "nation_key": 1, "name": "ARGENTINA", "aggregates": [ { "order_date": "1997-08-14", "sum_price": 16763.95d }, { "order_date": "1997-11-26", "sum_price": 18653.09d }, { "order_date": "1998-04-20", "sum_price": 24637.96d } ] }
+{ "nation_key": 2, "name": "BRAZIL", "aggregates": [ { "order_date": "1993-03-05", "sum_price": 8225.96d }, { "order_date": "1994-08-31", "sum_price": 19056.99d }, { "order_date": "1997-05-04", "sum_price": 23984.88d } ] }
+{ "nation_key": 3, "name": "CANADA", "aggregates": [ { "order_date": "1992-02-22", "sum_price": 1084.38d }, { "order_date": "1992-11-28", "sum_price": 4766.19d }, { "order_date": "1995-02-17", "sum_price": 4913.06d } ] }
+{ "nation_key": 4, "name": "EGYPT", "aggregates": [ { "order_date": "1998-04-19", "sum_price": 3089.42d }, { "order_date": "1996-03-12", "sum_price": 3892.77d }, { "order_date": "1997-07-25", "sum_price": 11405.4d } ] }
+{ "nation_key": 19, "name": "ROMANIA", "aggregates": [ { "order_date": "1994-07-05", "sum_price": 7108.12d }, { "order_date": "1994-11-17", "sum_price": 13282.23d }, { "order_date": "1997-02-07", "sum_price": 16689.19d } ] }
+{ "nation_key": 20, "name": "SAUDI ARABIA", "aggregates": [ { "order_date": "1994-04-30", "sum_price": 6406.29d }, { "order_date": "1992-05-10", "sum_price": 45695.84d }, { "order_date": "1994-01-31", "sum_price": 62316.61d } ] }
+{ "nation_key": 21, "name": "VIETNAM", "aggregates": [ { "order_date": "1994-02-17", "sum_price": 1984.14d }, { "order_date": "1995-08-05", "sum_price": 16922.51d }, { "order_date": "1994-06-01", "sum_price": 21088.59d } ] }
+{ "nation_key": 22, "name": "RUSSIA", "aggregates": [ { "order_date": "1993-11-16", "sum_price": 7471.75d }, { "order_date": "1996-01-11", "sum_price": 8720.45d }, { "order_date": "1995-07-15", "sum_price": 27016.74d } ] }
+{ "nation_key": 23, "name": "UNITED KINGDOM", "aggregates": [ { "order_date": "1997-12-18", "sum_price": 10934.84d }, { "order_date": "1995-05-26", "sum_price": 11474.95d }, { "order_date": "1997-05-13", "sum_price": 18307.45d } ] }
+{ "nation_key": 24, "name": "UNITED STATES", "aggregates": [  ] }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.adm
new file mode 100644
index 0000000..3834939
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/nest_aggregate2/nest_aggregate2.1.adm
@@ -0,0 +1,11 @@
+{ "nation_key": 0, "name": "ALGERIA", "aggregates": [ "1994-05-27", "1994-05-08", "1993-08-27" ] }
+{ "nation_key": 1, "name": "ARGENTINA", "aggregates": [ "1997-08-14", "1997-11-26", "1998-04-20" ] }
+{ "nation_key": 2, "name": "BRAZIL", "aggregates": [ "1993-03-05", "1994-08-31", "1997-05-04" ] }
+{ "nation_key": 3, "name": "CANADA", "aggregates": [ "1992-02-22", "1992-11-28", "1995-02-17" ] }
+{ "nation_key": 4, "name": "EGYPT", "aggregates": [ "1998-04-19", "1996-03-12", "1997-07-25" ] }
+{ "nation_key": 19, "name": "ROMANIA", "aggregates": [ "1994-07-05", "1994-11-17", "1997-02-07" ] }
+{ "nation_key": 20, "name": "SAUDI ARABIA", "aggregates": [ "1994-04-30", "1992-05-10", "1994-01-31" ] }
+{ "nation_key": 21, "name": "VIETNAM", "aggregates": [ "1994-02-17", "1995-08-05", "1994-06-01" ] }
+{ "nation_key": 22, "name": "RUSSIA", "aggregates": [ "1993-11-16", "1996-01-11", "1995-07-15" ] }
+{ "nation_key": 23, "name": "UNITED KINGDOM", "aggregates": [ "1997-12-18", "1995-05-26", "1997-05-13" ] }
+{ "nation_key": 24, "name": "UNITED STATES", "aggregates": [  ] }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.adm
new file mode 100644
index 0000000..8acdda4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q01_pricing_summary_report_nt/q01_pricing_summary_report_nt.1.adm
@@ -0,0 +1,4 @@
+{ "l_returnflag": "A", "l_linestatus": "F", "sum_qty": 37474.0d, "sum_base_price": 3.7569624640000015E7d, "sum_disc_price": 3.567619209699997E7d, "sum_charge": 3.7101416222424E7d, "ave_qty": 25.354533152909337d, "ave_price": 25419.231826792973d, "ave_disc": 0.05086603518267936d, "count_order": 1478 }
+{ "l_returnflag": "N", "l_linestatus": "F", "sum_qty": 1041.0d, "sum_base_price": 1041301.0700000001d, "sum_disc_price": 999060.898d, "sum_charge": 1036450.8022800002d, "ave_qty": 27.394736842105264d, "ave_price": 27402.659736842106d, "ave_disc": 0.04289473684210526d, "count_order": 38 }
+{ "l_returnflag": "N", "l_linestatus": "O", "sum_qty": 75168.0d, "sum_base_price": 7.538495537000003E7d, "sum_disc_price": 7.165316630340004E7d, "sum_charge": 7.449879813307303E7d, "ave_qty": 25.558653519211152d, "ave_price": 25632.422771166282d, "ave_disc": 0.04969738184291074d, "count_order": 2941 }
+{ "l_returnflag": "R", "l_linestatus": "F", "sum_qty": 36511.0d, "sum_base_price": 3.657084124000002E7d, "sum_disc_price": 3.473847287579997E7d, "sum_charge": 3.616906011219299E7d, "ave_qty": 25.059025394646532d, "ave_price": 25100.09693891559d, "ave_disc": 0.05002745367192867d, "count_order": 1457 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.adm
new file mode 100644
index 0000000..a7d5b93
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q02_minimum_cost_supplier/q02_minimum_cost_supplier.1.adm
@@ -0,0 +1,13 @@
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 2, "p_mfgr": "Manufacturer#1", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 4, "p_mfgr": "Manufacturer#3", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 22, "p_mfgr": "Manufacturer#4", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 35, "p_mfgr": "Manufacturer#4", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 38, "p_mfgr": "Manufacturer#4", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 62, "p_mfgr": "Manufacturer#3", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 79, "p_mfgr": "Manufacturer#4", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 94, "p_mfgr": "Manufacturer#3", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 102, "p_mfgr": "Manufacturer#3", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 106, "p_mfgr": "Manufacturer#3", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 131, "p_mfgr": "Manufacturer#5", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 159, "p_mfgr": "Manufacturer#4", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }
+{ "s_acctbal": 6820.35d, "s_name": "Supplier#000000007", "n_name": "UNITED KINGDOM", "p_partkey": 193, "p_mfgr": "Manufacturer#4", "s_address": "s,4TicNGB4uO6PaSqNBUq", "s_phone": "33-990-965-2201", "s_comment": "s unwind silently furiously regular courts. final requests are deposits. requests wake quietly blit" }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.adm
new file mode 100644
index 0000000..625a418
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q03_shipping_priority_nt/q03_shipping_priority_nt.1.adm
@@ -0,0 +1,8 @@
+{ "l_orderkey": 1637, "revenue": 164224.9253d, "o_orderdate": "1995-02-08", "o_shippriority": 0 }
+{ "l_orderkey": 5191, "revenue": 49378.309400000006d, "o_orderdate": "1994-12-11", "o_shippriority": 0 }
+{ "l_orderkey": 742, "revenue": 43728.048d, "o_orderdate": "1994-12-23", "o_shippriority": 0 }
+{ "l_orderkey": 3492, "revenue": 43716.072400000005d, "o_orderdate": "1994-11-24", "o_shippriority": 0 }
+{ "l_orderkey": 2883, "revenue": 36666.9612d, "o_orderdate": "1995-01-23", "o_shippriority": 0 }
+{ "l_orderkey": 998, "revenue": 11785.548600000002d, "o_orderdate": "1994-11-26", "o_shippriority": 0 }
+{ "l_orderkey": 3430, "revenue": 4726.6775d, "o_orderdate": "1994-12-12", "o_shippriority": 0 }
+{ "l_orderkey": 4423, "revenue": 3055.9365d, "o_orderdate": "1995-02-17", "o_shippriority": 0 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.adm
new file mode 100644
index 0000000..5e38c96
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q04_order_priority/q04_order_priority.1.adm
@@ -0,0 +1,5 @@
+{ "order_priority": "1-URGENT", "count": 9 }
+{ "order_priority": "2-HIGH", "count": 7 }
+{ "order_priority": "3-MEDIUM", "count": 9 }
+{ "order_priority": "4-NOT SPECIFIED", "count": 8 }
+{ "order_priority": "5-LOW", "count": 12 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.adm
new file mode 100644
index 0000000..ac68fb3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q05_local_supplier_volume/q05_local_supplier_volume.1.adm
@@ -0,0 +1,8 @@
+{ "n_name": "PERU", "revenue": 1099912.8209000002d }
+{ "n_name": "MOROCCO", "revenue": 520107.17919999996d }
+{ "n_name": "IRAN", "revenue": 375610.964d }
+{ "n_name": "IRAQ", "revenue": 364417.398d }
+{ "n_name": "ETHIOPIA", "revenue": 253825.76219999997d }
+{ "n_name": "ARGENTINA", "revenue": 102659.0106d }
+{ "n_name": "UNITED KINGDOM", "revenue": 61065.8711d }
+{ "n_name": "KENYA", "revenue": 29679.393200000002d }

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

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.adm
new file mode 100644
index 0000000..37138fc
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q07_volume_shipping/q07_volume_shipping.1.adm
@@ -0,0 +1,37 @@
+{ "supp_nation": "ARGENTINA", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 63089.1006d }
+{ "supp_nation": "ARGENTINA", "cust_nation": "GERMANY", "l_year": 1993, "revenue": 64024.4532d }
+{ "supp_nation": "ARGENTINA", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 32719.877199999995d }
+{ "supp_nation": "ARGENTINA", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 63729.862400000005d }
+{ "supp_nation": "ARGENTINA", "cust_nation": "GERMANY", "l_year": 1996, "revenue": 1801.8198d }
+{ "supp_nation": "ETHIOPIA", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 74693.317d }
+{ "supp_nation": "ETHIOPIA", "cust_nation": "GERMANY", "l_year": 1993, "revenue": 13733.706600000001d }
+{ "supp_nation": "ETHIOPIA", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 83631.40359999999d }
+{ "supp_nation": "ETHIOPIA", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 69329.67199999999d }
+{ "supp_nation": "ETHIOPIA", "cust_nation": "GERMANY", "l_year": 1996, "revenue": 42017.435999999994d }
+{ "supp_nation": "IRAN", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 38014.335399999996d }
+{ "supp_nation": "IRAN", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 252152.5927d }
+{ "supp_nation": "IRAN", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 9106.957199999999d }
+{ "supp_nation": "IRAQ", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 68040.7747d }
+{ "supp_nation": "IRAQ", "cust_nation": "GERMANY", "l_year": 1993, "revenue": 3676.8004d }
+{ "supp_nation": "IRAQ", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 85948.85280000001d }
+{ "supp_nation": "IRAQ", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 66380.2488d }
+{ "supp_nation": "KENYA", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 77164.5422d }
+{ "supp_nation": "KENYA", "cust_nation": "GERMANY", "l_year": 1993, "revenue": 63792.8736d }
+{ "supp_nation": "KENYA", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 74537.6256d }
+{ "supp_nation": "KENYA", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 37851.309d }
+{ "supp_nation": "KENYA", "cust_nation": "GERMANY", "l_year": 1996, "revenue": 18467.316d }
+{ "supp_nation": "MOROCCO", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 89669.69080000001d }
+{ "supp_nation": "MOROCCO", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 173726.0087d }
+{ "supp_nation": "MOROCCO", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 37169.8497d }
+{ "supp_nation": "PERU", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 226624.7652d }
+{ "supp_nation": "PERU", "cust_nation": "GERMANY", "l_year": 1993, "revenue": 58359.3076d }
+{ "supp_nation": "PERU", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 345376.29829999997d }
+{ "supp_nation": "PERU", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 52968.9424d }
+{ "supp_nation": "PERU", "cust_nation": "GERMANY", "l_year": 1996, "revenue": 7960.72d }
+{ "supp_nation": "UNITED KINGDOM", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 100143.32139999999d }
+{ "supp_nation": "UNITED KINGDOM", "cust_nation": "GERMANY", "l_year": 1993, "revenue": 41582.5227d }
+{ "supp_nation": "UNITED KINGDOM", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 164740.32710000002d }
+{ "supp_nation": "UNITED KINGDOM", "cust_nation": "GERMANY", "l_year": 1996, "revenue": 50909.551999999996d }
+{ "supp_nation": "UNITED STATES", "cust_nation": "GERMANY", "l_year": 1992, "revenue": 52480.9528d }
+{ "supp_nation": "UNITED STATES", "cust_nation": "GERMANY", "l_year": 1994, "revenue": 115566.8388d }
+{ "supp_nation": "UNITED STATES", "cust_nation": "GERMANY", "l_year": 1995, "revenue": 80489.69949999999d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.adm
new file mode 100644
index 0000000..5a0b1da
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q08_national_market_share/q08_national_market_share.1.adm
@@ -0,0 +1,2 @@
+{ "year": 1995, "mkt_share": 0.0d }
+{ "year": 1996, "mkt_share": 0.0d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.1.adm
new file mode 100644
index 0000000..e9f3f47
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q09_product_type_profit_nt/q09_product_type_profit_nt.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/q10_returned_item/q10_returned_ite.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q10_returned_item/q10_returned_ite.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q10_returned_item/q10_returned_ite.1.adm
new file mode 100644
index 0000000..126a026
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q10_returned_item/q10_returned_ite.1.adm
@@ -0,0 +1,20 @@
+{ "c_custkey": 121, "c_name": "Customer#000000121", "revenue": 282635.1719, "c_acctbal": 6428.32, "n_name": "PERU", "c_address": "tv nCR2YKupGN73mQudO", "c_phone": "27-411-990-2959", "c_comment": "uriously stealthy ideas. carefully final courts use carefully" }
+{ "c_custkey": 124, "c_name": "Customer#000000124", "revenue": 222182.51880000002, "c_acctbal": 1842.49, "n_name": "CHINA", "c_address": "aTbyVAW5tCd,v09O", "c_phone": "28-183-750-7809", "c_comment": "le fluffily even dependencies. quietly s" }
+{ "c_custkey": 106, "c_name": "Customer#000000106", "revenue": 190241.3334, "c_acctbal": 3288.42, "n_name": "ARGENTINA", "c_address": "xGCOEAUjUNG", "c_phone": "11-751-989-4627", "c_comment": "lose slyly. ironic accounts along the evenly regular theodolites wake about the special, final gifts. " }
+{ "c_custkey": 16, "c_name": "Customer#000000016", "revenue": 161422.04609999998, "c_acctbal": 4681.03, "n_name": "IRAN", "c_address": "cYiaeMLZSMAOQ2 d0W,", "c_phone": "20-781-609-3107", "c_comment": "kly silent courts. thinly regular theodolites sleep fluffily after " }
+{ "c_custkey": 44, "c_name": "Customer#000000044", "revenue": 149364.5652, "c_acctbal": 7315.94, "n_name": "MOZAMBIQUE", "c_address": "Oi,dOSPwDu4jo4x,,P85E0dmhZGvNtBwi", "c_phone": "26-190-260-5375", "c_comment": "r requests around the unusual, bold a" }
+{ "c_custkey": 71, "c_name": "Customer#000000071", "revenue": 129481.0245, "c_acctbal": -611.19, "n_name": "GERMANY", "c_address": "TlGalgdXWBmMV,6agLyWYDyIz9MKzcY8gl,w6t1B", "c_phone": "17-710-812-5403", "c_comment": "g courts across the regular, final pinto beans are blithely pending ac" }
+{ "c_custkey": 89, "c_name": "Customer#000000089", "revenue": 121663.1243, "c_acctbal": 1530.76, "n_name": "KENYA", "c_address": "dtR, y9JQWUO6FoJExyp8whOU", "c_phone": "24-394-451-5404", "c_comment": "counts are slyly beyond the slyly final accounts. quickly final ideas wake. r" }
+{ "c_custkey": 112, "c_name": "Customer#000000112", "revenue": 111137.71409999998, "c_acctbal": 2953.35, "n_name": "ROMANIA", "c_address": "RcfgG3bO7QeCnfjqJT1", "c_phone": "29-233-262-8382", "c_comment": "rmanently unusual multipliers. blithely ruthless deposits are furiously along the" }
+{ "c_custkey": 62, "c_name": "Customer#000000062", "revenue": 106368.01529999998, "c_acctbal": 595.61, "n_name": "GERMANY", "c_address": "upJK2Dnw13,", "c_phone": "17-361-978-7059", "c_comment": "kly special dolphins. pinto beans are slyly. quickly regular accounts are furiously a" }
+{ "c_custkey": 146, "c_name": "Customer#000000146", "revenue": 103265.98879999999, "c_acctbal": 3328.68, "n_name": "CANADA", "c_address": "GdxkdXG9u7iyI1,,y5tq4ZyrcEy", "c_phone": "13-835-723-3223", "c_comment": "ffily regular dinos are slyly unusual requests. slyly specia" }
+{ "c_custkey": 19, "c_name": "Customer#000000019", "revenue": 99306.0127, "c_acctbal": 8914.71, "n_name": "CHINA", "c_address": "uc,3bHIx84H,wdrmLOjVsiqXCq2tr", "c_phone": "28-396-526-5053", "c_comment": " nag. furiously careful packages are slyly at the accounts. furiously regular in" }
+{ "c_custkey": 145, "c_name": "Customer#000000145", "revenue": 99256.9018, "c_acctbal": 9748.93, "n_name": "JORDAN", "c_address": "kQjHmt2kcec cy3hfMh969u", "c_phone": "23-562-444-8454", "c_comment": "ests? express, express instructions use. blithely fina" }
+{ "c_custkey": 103, "c_name": "Customer#000000103", "revenue": 97311.77240000002, "c_acctbal": 2757.45, "n_name": "INDONESIA", "c_address": "8KIsQX4LJ7QMsj6DrtFtXu0nUEdV,8a", "c_phone": "19-216-107-2107", "c_comment": "furiously pending notornis boost slyly around the blithely ironic ideas? final, even instructions cajole fl" }
+{ "c_custkey": 136, "c_name": "Customer#000000136", "revenue": 95855.39799999999, "c_acctbal": -842.39, "n_name": "GERMANY", "c_address": "QoLsJ0v5C1IQbh,DS1", "c_phone": "17-501-210-4726", "c_comment": "ackages sleep ironic, final courts. even requests above the blithely bold requests g" }
+{ "c_custkey": 53, "c_name": "Customer#000000053", "revenue": 92568.9124, "c_acctbal": 4113.64, "n_name": "MOROCCO", "c_address": "HnaxHzTfFTZs8MuCpJyTbZ47Cm4wFOOgib", "c_phone": "25-168-852-5363", "c_comment": "ar accounts are. even foxes are blithely. fluffily pending deposits boost" }
+{ "c_custkey": 49, "c_name": "Customer#000000049", "revenue": 90965.7262, "c_acctbal": 4573.94, "n_name": "IRAN", "c_address": "cNgAeX7Fqrdf7HQN9EwjUa4nxT,68L FKAxzl", "c_phone": "20-908-631-4424", "c_comment": "nusual foxes! fluffily pending packages maintain to the regular " }
+{ "c_custkey": 37, "c_name": "Customer#000000037", "revenue": 88065.74579999999, "c_acctbal": -917.75, "n_name": "INDIA", "c_address": "7EV4Pwh,3SboctTWt", "c_phone": "18-385-235-7162", "c_comment": "ilent packages are carefully among the deposits. furiousl" }
+{ "c_custkey": 82, "c_name": "Customer#000000082", "revenue": 86998.9644, "c_acctbal": 9468.34, "n_name": "CHINA", "c_address": "zhG3EZbap4c992Gj3bK,3Ne,Xn", "c_phone": "28-159-442-5305", "c_comment": "s wake. bravely regular accounts are furiously. regula" }
+{ "c_custkey": 125, "c_name": "Customer#000000125", "revenue": 84808.068, "c_acctbal": -234.12, "n_name": "ROMANIA", "c_address": ",wSZXdVR xxIIfm9s8ITyLl3kgjT6UC07GY0Y", "c_phone": "29-261-996-3120", "c_comment": "x-ray finally after the packages? regular requests c" }
+{ "c_custkey": 59, "c_name": "Customer#000000059", "revenue": 84655.5711, "c_acctbal": 3458.6, "n_name": "ARGENTINA", "c_address": "zLOCP0wh92OtBihgspOGl4", "c_phone": "11-355-584-3112", "c_comment": "ously final packages haggle blithely after the express deposits. furiou" }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.adm
new file mode 100644
index 0000000..ed5dae4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q10_returned_item_int64/q10_returned_item_int64.1.adm
@@ -0,0 +1,20 @@
+{ "c_custkey": 121, "c_name": "Customer#000000121", "revenue": 282635.1719d, "c_acctbal": 6428.32d, "n_name": "PERU", "c_address": "tv nCR2YKupGN73mQudO", "c_phone": "27-411-990-2959", "c_comment": "uriously stealthy ideas. carefully final courts use carefully" }
+{ "c_custkey": 124, "c_name": "Customer#000000124", "revenue": 222182.5188d, "c_acctbal": 1842.49d, "n_name": "CHINA", "c_address": "aTbyVAW5tCd,v09O", "c_phone": "28-183-750-7809", "c_comment": "le fluffily even dependencies. quietly s" }
+{ "c_custkey": 106, "c_name": "Customer#000000106", "revenue": 190241.3334d, "c_acctbal": 3288.42d, "n_name": "ARGENTINA", "c_address": "xGCOEAUjUNG", "c_phone": "11-751-989-4627", "c_comment": "lose slyly. ironic accounts along the evenly regular theodolites wake about the special, final gifts. " }
+{ "c_custkey": 16, "c_name": "Customer#000000016", "revenue": 161422.04609999998d, "c_acctbal": 4681.03d, "n_name": "IRAN", "c_address": "cYiaeMLZSMAOQ2 d0W,", "c_phone": "20-781-609-3107", "c_comment": "kly silent courts. thinly regular theodolites sleep fluffily after " }
+{ "c_custkey": 44, "c_name": "Customer#000000044", "revenue": 149364.5652d, "c_acctbal": 7315.94d, "n_name": "MOZAMBIQUE", "c_address": "Oi,dOSPwDu4jo4x,,P85E0dmhZGvNtBwi", "c_phone": "26-190-260-5375", "c_comment": "r requests around the unusual, bold a" }
+{ "c_custkey": 71, "c_name": "Customer#000000071", "revenue": 129481.02450000001d, "c_acctbal": -611.19d, "n_name": "GERMANY", "c_address": "TlGalgdXWBmMV,6agLyWYDyIz9MKzcY8gl,w6t1B", "c_phone": "17-710-812-5403", "c_comment": "g courts across the regular, final pinto beans are blithely pending ac" }
+{ "c_custkey": 89, "c_name": "Customer#000000089", "revenue": 121663.1243d, "c_acctbal": 1530.76d, "n_name": "KENYA", "c_address": "dtR, y9JQWUO6FoJExyp8whOU", "c_phone": "24-394-451-5404", "c_comment": "counts are slyly beyond the slyly final accounts. quickly final ideas wake. r" }
+{ "c_custkey": 112, "c_name": "Customer#000000112", "revenue": 111137.7141d, "c_acctbal": 2953.35d, "n_name": "ROMANIA", "c_address": "RcfgG3bO7QeCnfjqJT1", "c_phone": "29-233-262-8382", "c_comment": "rmanently unusual multipliers. blithely ruthless deposits are furiously along the" }
+{ "c_custkey": 62, "c_name": "Customer#000000062", "revenue": 106368.0153d, "c_acctbal": 595.61d, "n_name": "GERMANY", "c_address": "upJK2Dnw13,", "c_phone": "17-361-978-7059", "c_comment": "kly special dolphins. pinto beans are slyly. quickly regular accounts are furiously a" }
+{ "c_custkey": 146, "c_name": "Customer#000000146", "revenue": 103265.98879999999d, "c_acctbal": 3328.68d, "n_name": "CANADA", "c_address": "GdxkdXG9u7iyI1,,y5tq4ZyrcEy", "c_phone": "13-835-723-3223", "c_comment": "ffily regular dinos are slyly unusual requests. slyly specia" }
+{ "c_custkey": 19, "c_name": "Customer#000000019", "revenue": 99306.0127d, "c_acctbal": 8914.71d, "n_name": "CHINA", "c_address": "uc,3bHIx84H,wdrmLOjVsiqXCq2tr", "c_phone": "28-396-526-5053", "c_comment": " nag. furiously careful packages are slyly at the accounts. furiously regular in" }
+{ "c_custkey": 145, "c_name": "Customer#000000145", "revenue": 99256.9018d, "c_acctbal": 9748.93d, "n_name": "JORDAN", "c_address": "kQjHmt2kcec cy3hfMh969u", "c_phone": "23-562-444-8454", "c_comment": "ests? express, express instructions use. blithely fina" }
+{ "c_custkey": 103, "c_name": "Customer#000000103", "revenue": 97311.77240000002d, "c_acctbal": 2757.45d, "n_name": "INDONESIA", "c_address": "8KIsQX4LJ7QMsj6DrtFtXu0nUEdV,8a", "c_phone": "19-216-107-2107", "c_comment": "furiously pending notornis boost slyly around the blithely ironic ideas? final, even instructions cajole fl" }
+{ "c_custkey": 136, "c_name": "Customer#000000136", "revenue": 95855.39799999999d, "c_acctbal": -842.39d, "n_name": "GERMANY", "c_address": "QoLsJ0v5C1IQbh,DS1", "c_phone": "17-501-210-4726", "c_comment": "ackages sleep ironic, final courts. even requests above the blithely bold requests g" }
+{ "c_custkey": 53, "c_name": "Customer#000000053", "revenue": 92568.9124d, "c_acctbal": 4113.64d, "n_name": "MOROCCO", "c_address": "HnaxHzTfFTZs8MuCpJyTbZ47Cm4wFOOgib", "c_phone": "25-168-852-5363", "c_comment": "ar accounts are. even foxes are blithely. fluffily pending deposits boost" }
+{ "c_custkey": 49, "c_name": "Customer#000000049", "revenue": 90965.7262d, "c_acctbal": 4573.94d, "n_name": "IRAN", "c_address": "cNgAeX7Fqrdf7HQN9EwjUa4nxT,68L FKAxzl", "c_phone": "20-908-631-4424", "c_comment": "nusual foxes! fluffily pending packages maintain to the regular " }
+{ "c_custkey": 37, "c_name": "Customer#000000037", "revenue": 88065.74579999999d, "c_acctbal": -917.75d, "n_name": "INDIA", "c_address": "7EV4Pwh,3SboctTWt", "c_phone": "18-385-235-7162", "c_comment": "ilent packages are carefully among the deposits. furiousl" }
+{ "c_custkey": 82, "c_name": "Customer#000000082", "revenue": 86998.9644d, "c_acctbal": 9468.34d, "n_name": "CHINA", "c_address": "zhG3EZbap4c992Gj3bK,3Ne,Xn", "c_phone": "28-159-442-5305", "c_comment": "s wake. bravely regular accounts are furiously. regula" }
+{ "c_custkey": 125, "c_name": "Customer#000000125", "revenue": 84808.068d, "c_acctbal": -234.12d, "n_name": "ROMANIA", "c_address": ",wSZXdVR xxIIfm9s8ITyLl3kgjT6UC07GY0Y", "c_phone": "29-261-996-3120", "c_comment": "x-ray finally after the packages? regular requests c" }
+{ "c_custkey": 59, "c_name": "Customer#000000059", "revenue": 84655.5711d, "c_acctbal": 3458.6d, "n_name": "ARGENTINA", "c_address": "zLOCP0wh92OtBihgspOGl4", "c_phone": "11-355-584-3112", "c_comment": "ously final packages haggle blithely after the express deposits. furiou" }


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

Posted by bu...@apache.org.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.adm
new file mode 100644
index 0000000..0fc28fb
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q11_important_stock/q11_important_stock.1.adm
@@ -0,0 +1,200 @@
+{ "partkey": 25, "part_value": 2.832302068E7d }
+{ "partkey": 124, "part_value": 2.59627599E7d }
+{ "partkey": 175, "part_value": 2.385395363E7d }
+{ "partkey": 197, "part_value": 2.248551967E7d }
+{ "partkey": 163, "part_value": 2.099460571E7d }
+{ "partkey": 160, "part_value": 2.00232846E7d }
+{ "partkey": 82, "part_value": 1.991921335E7d }
+{ "partkey": 169, "part_value": 1.898734723E7d }
+{ "partkey": 29, "part_value": 1.867279344E7d }
+{ "partkey": 26, "part_value": 1.861245827E7d }
+{ "partkey": 73, "part_value": 1.827170729E7d }
+{ "partkey": 161, "part_value": 1.7987463009999998E7d }
+{ "partkey": 75, "part_value": 1.7959598009999998E7d }
+{ "partkey": 34, "part_value": 1.778083836E7d }
+{ "partkey": 98, "part_value": 1.7763191509999998E7d }
+{ "partkey": 69, "part_value": 1.728526943E7d }
+{ "partkey": 111, "part_value": 1.7083882619999997E7d }
+{ "partkey": 171, "part_value": 1.635442066E7d }
+{ "partkey": 166, "part_value": 1.6351893740000002E7d }
+{ "partkey": 77, "part_value": 1.598059909E7d }
+{ "partkey": 78, "part_value": 1.58768992E7d }
+{ "partkey": 143, "part_value": 1.585686159E7d }
+{ "partkey": 17, "part_value": 1.547426112E7d }
+{ "partkey": 109, "part_value": 1.5054682620000001E7d }
+{ "partkey": 105, "part_value": 1.5053163809999999E7d }
+{ "partkey": 96, "part_value": 1.495213259E7d }
+{ "partkey": 146, "part_value": 1.481075944E7d }
+{ "partkey": 136, "part_value": 1.465496775E7d }
+{ "partkey": 116, "part_value": 1.4432091339999998E7d }
+{ "partkey": 128, "part_value": 1.4393555259999998E7d }
+{ "partkey": 142, "part_value": 1.422039904E7d }
+{ "partkey": 121, "part_value": 1.420032605E7d }
+{ "partkey": 30, "part_value": 1.416313241E7d }
+{ "partkey": 16, "part_value": 1.413646503E7d }
+{ "partkey": 198, "part_value": 1.413535335E7d }
+{ "partkey": 79, "part_value": 1.38652287E7d }
+{ "partkey": 90, "part_value": 1.373279748E7d }
+{ "partkey": 32, "part_value": 1.369962979E7d }
+{ "partkey": 74, "part_value": 1.338871111E7d }
+{ "partkey": 1, "part_value": 1.337870724E7d }
+{ "partkey": 89, "part_value": 1.337148041E7d }
+{ "partkey": 22, "part_value": 1.3354991740000002E7d }
+{ "partkey": 186, "part_value": 1.317604077E7d }
+{ "partkey": 189, "part_value": 1.305492542E7d }
+{ "partkey": 14, "part_value": 1.299397721E7d }
+{ "partkey": 93, "part_value": 1.299298218E7d }
+{ "partkey": 168, "part_value": 1.299041501E7d }
+{ "partkey": 99, "part_value": 1.2750046790000001E7d }
+{ "partkey": 167, "part_value": 1.268255069E7d }
+{ "partkey": 2, "part_value": 1.258471636E7d }
+{ "partkey": 182, "part_value": 1.256239411E7d }
+{ "partkey": 61, "part_value": 1.253677656E7d }
+{ "partkey": 112, "part_value": 1.234957975E7d }
+{ "partkey": 178, "part_value": 1.2260301739999998E7d }
+{ "partkey": 172, "part_value": 1.219775193E7d }
+{ "partkey": 165, "part_value": 1.219746506E7d }
+{ "partkey": 184, "part_value": 1.216784393E7d }
+{ "partkey": 187, "part_value": 1.214970141E7d }
+{ "partkey": 153, "part_value": 1.2119354219999999E7d }
+{ "partkey": 95, "part_value": 1.20468895E7d }
+{ "partkey": 11, "part_value": 1.2007151559999999E7d }
+{ "partkey": 125, "part_value": 1.2003476109999998E7d }
+{ "partkey": 154, "part_value": 1.185113385E7d }
+{ "partkey": 15, "part_value": 1.1798438790000001E7d }
+{ "partkey": 67, "part_value": 1.178579951E7d }
+{ "partkey": 8, "part_value": 1.1707892620000001E7d }
+{ "partkey": 87, "part_value": 1.168637671E7d }
+{ "partkey": 134, "part_value": 1.1683586929999998E7d }
+{ "partkey": 130, "part_value": 1.1682461489999998E7d }
+{ "partkey": 43, "part_value": 1.161150462E7d }
+{ "partkey": 102, "part_value": 1.151554211E7d }
+{ "partkey": 21, "part_value": 1.141066856E7d }
+{ "partkey": 62, "part_value": 1.138927324E7d }
+{ "partkey": 9, "part_value": 1.126484373E7d }
+{ "partkey": 80, "part_value": 1.118329032E7d }
+{ "partkey": 173, "part_value": 1.102677486E7d }
+{ "partkey": 94, "part_value": 1.092440116E7d }
+{ "partkey": 3, "part_value": 1.075814545E7d }
+{ "partkey": 103, "part_value": 1.06912216E7d }
+{ "partkey": 158, "part_value": 1.067861635E7d }
+{ "partkey": 49, "part_value": 1.06445572E7d }
+{ "partkey": 139, "part_value": 1.044045371E7d }
+{ "partkey": 192, "part_value": 1.035745974E7d }
+{ "partkey": 24, "part_value": 1.033911936E7d }
+{ "partkey": 39, "part_value": 1.03210148E7d }
+{ "partkey": 156, "part_value": 1.014364082E7d }
+{ "partkey": 188, "part_value": 1.011906085E7d }
+{ "partkey": 12, "part_value": 1.01085874E7d }
+{ "partkey": 33, "part_value": 1.005296264E7d }
+{ "partkey": 28, "part_value": 1.005234286E7d }
+{ "partkey": 40, "part_value": 9927827.77d }
+{ "partkey": 199, "part_value": 9907803.559999999d }
+{ "partkey": 193, "part_value": 9869674.77d }
+{ "partkey": 106, "part_value": 9869361.73d }
+{ "partkey": 108, "part_value": 9868370.309999999d }
+{ "partkey": 183, "part_value": 9855564.82d }
+{ "partkey": 70, "part_value": 9700431.94d }
+{ "partkey": 48, "part_value": 9655921.88d }
+{ "partkey": 118, "part_value": 9622756.15d }
+{ "partkey": 13, "part_value": 9592610.32d }
+{ "partkey": 83, "part_value": 9543465.08d }
+{ "partkey": 159, "part_value": 9519909.44d }
+{ "partkey": 147, "part_value": 9513932.18d }
+{ "partkey": 45, "part_value": 9423874.47d }
+{ "partkey": 117, "part_value": 9408426.72d }
+{ "partkey": 135, "part_value": 9311247.280000001d }
+{ "partkey": 185, "part_value": 9305341.780000001d }
+{ "partkey": 131, "part_value": 9223742.49d }
+{ "partkey": 7, "part_value": 9175528.21d }
+{ "partkey": 71, "part_value": 9167712.04d }
+{ "partkey": 100, "part_value": 9131099.530000001d }
+{ "partkey": 76, "part_value": 9092927.11d }
+{ "partkey": 53, "part_value": 8979121.97d }
+{ "partkey": 141, "part_value": 8686511.120000001d }
+{ "partkey": 64, "part_value": 8627897.290000001d }
+{ "partkey": 101, "part_value": 8521762.0d }
+{ "partkey": 176, "part_value": 8510175.88d }
+{ "partkey": 19, "part_value": 8481679.5d }
+{ "partkey": 194, "part_value": 8464559.54d }
+{ "partkey": 91, "part_value": 8460636.52d }
+{ "partkey": 132, "part_value": 8416851.239999998d }
+{ "partkey": 113, "part_value": 8405217.96d }
+{ "partkey": 51, "part_value": 8247118.499999999d }
+{ "partkey": 41, "part_value": 8187897.16d }
+{ "partkey": 55, "part_value": 8092552.890000001d }
+{ "partkey": 72, "part_value": 8007155.3d }
+{ "partkey": 115, "part_value": 7954624.0d }
+{ "partkey": 170, "part_value": 7895241.609999999d }
+{ "partkey": 114, "part_value": 7832023.28d }
+{ "partkey": 37, "part_value": 7809598.659999999d }
+{ "partkey": 54, "part_value": 7578243.79d }
+{ "partkey": 180, "part_value": 7531794.4799999995d }
+{ "partkey": 60, "part_value": 7508961.69d }
+{ "partkey": 31, "part_value": 7433034.240000001d }
+{ "partkey": 35, "part_value": 7132671.49d }
+{ "partkey": 140, "part_value": 7122050.08d }
+{ "partkey": 150, "part_value": 7106237.92d }
+{ "partkey": 107, "part_value": 7082828.68d }
+{ "partkey": 123, "part_value": 7049500.720000001d }
+{ "partkey": 190, "part_value": 7017966.9d }
+{ "partkey": 120, "part_value": 6920857.090000001d }
+{ "partkey": 196, "part_value": 6905182.43d }
+{ "partkey": 177, "part_value": 6887257.27d }
+{ "partkey": 126, "part_value": 6813302.029999999d }
+{ "partkey": 122, "part_value": 6812763.34d }
+{ "partkey": 200, "part_value": 6780024.53d }
+{ "partkey": 157, "part_value": 6766365.680000001d }
+{ "partkey": 63, "part_value": 6724960.14d }
+{ "partkey": 38, "part_value": 6667789.55d }
+{ "partkey": 58, "part_value": 6640619.380000001d }
+{ "partkey": 145, "part_value": 6633786.59d }
+{ "partkey": 144, "part_value": 6546945.92d }
+{ "partkey": 20, "part_value": 6533101.39d }
+{ "partkey": 127, "part_value": 6483139.620000001d }
+{ "partkey": 10, "part_value": 6433776.51d }
+{ "partkey": 47, "part_value": 6407355.369999999d }
+{ "partkey": 191, "part_value": 6347187.43d }
+{ "partkey": 137, "part_value": 6180452.85d }
+{ "partkey": 56, "part_value": 6145826.6d }
+{ "partkey": 104, "part_value": 6134341.85d }
+{ "partkey": 44, "part_value": 6038126.66d }
+{ "partkey": 97, "part_value": 6036047.1899999995d }
+{ "partkey": 181, "part_value": 5853464.149999999d }
+{ "partkey": 162, "part_value": 5829410.54d }
+{ "partkey": 86, "part_value": 5746713.88d }
+{ "partkey": 52, "part_value": 5680644.4799999995d }
+{ "partkey": 155, "part_value": 5552007.57d }
+{ "partkey": 92, "part_value": 5489588.279999999d }
+{ "partkey": 5, "part_value": 5461046.930000001d }
+{ "partkey": 18, "part_value": 5456316.21d }
+{ "partkey": 149, "part_value": 5367514.63d }
+{ "partkey": 110, "part_value": 5261352.11d }
+{ "partkey": 4, "part_value": 5162989.07d }
+{ "partkey": 6, "part_value": 5120392.470000001d }
+{ "partkey": 148, "part_value": 5061589.27d }
+{ "partkey": 42, "part_value": 4957032.47d }
+{ "partkey": 119, "part_value": 4954403.4799999995d }
+{ "partkey": 84, "part_value": 4891082.38d }
+{ "partkey": 65, "part_value": 4834763.09d }
+{ "partkey": 66, "part_value": 4719253.369999999d }
+{ "partkey": 179, "part_value": 4610607.919999999d }
+{ "partkey": 23, "part_value": 4531731.12d }
+{ "partkey": 68, "part_value": 4504770.61d }
+{ "partkey": 27, "part_value": 4371849.52d }
+{ "partkey": 36, "part_value": 4036576.8999999994d }
+{ "partkey": 129, "part_value": 3997604.78d }
+{ "partkey": 195, "part_value": 3817436.31d }
+{ "partkey": 59, "part_value": 3765210.2100000004d }
+{ "partkey": 57, "part_value": 3739347.12d }
+{ "partkey": 138, "part_value": 3567425.75d }
+{ "partkey": 174, "part_value": 3484708.3100000005d }
+{ "partkey": 164, "part_value": 3462215.0d }
+{ "partkey": 81, "part_value": 3421610.42d }
+{ "partkey": 46, "part_value": 3398443.33d }
+{ "partkey": 85, "part_value": 3338711.3899999997d }
+{ "partkey": 50, "part_value": 3145791.9699999997d }
+{ "partkey": 88, "part_value": 3117730.2399999998d }
+{ "partkey": 151, "part_value": 2727444.22d }
+{ "partkey": 152, "part_value": 1837809.1700000002d }
+{ "partkey": 133, "part_value": 1517282.3299999998d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q12_shipping/q12_shipping.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q12_shipping/q12_shipping.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q12_shipping/q12_shipping.1.adm
new file mode 100644
index 0000000..e0eeaf8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q12_shipping/q12_shipping.1.adm
@@ -0,0 +1,2 @@
+{ "l_shipmode": "MAIL", "high_line_count": 5, "low_line_count": 5 }
+{ "l_shipmode": "SHIP", "high_line_count": 5, "low_line_count": 10 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.adm
new file mode 100644
index 0000000..9257a84
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q13_customer_distribution/q13_customer_distribution.1.adm
@@ -0,0 +1,27 @@
+{ "c_count": 0, "custdist": 50 }
+{ "c_count": 16, "custdist": 8 }
+{ "c_count": 17, "custdist": 7 }
+{ "c_count": 20, "custdist": 6 }
+{ "c_count": 13, "custdist": 6 }
+{ "c_count": 12, "custdist": 6 }
+{ "c_count": 9, "custdist": 6 }
+{ "c_count": 23, "custdist": 5 }
+{ "c_count": 14, "custdist": 5 }
+{ "c_count": 10, "custdist": 5 }
+{ "c_count": 21, "custdist": 4 }
+{ "c_count": 18, "custdist": 4 }
+{ "c_count": 11, "custdist": 4 }
+{ "c_count": 8, "custdist": 4 }
+{ "c_count": 7, "custdist": 4 }
+{ "c_count": 26, "custdist": 3 }
+{ "c_count": 22, "custdist": 3 }
+{ "c_count": 6, "custdist": 3 }
+{ "c_count": 5, "custdist": 3 }
+{ "c_count": 4, "custdist": 3 }
+{ "c_count": 29, "custdist": 2 }
+{ "c_count": 24, "custdist": 2 }
+{ "c_count": 19, "custdist": 2 }
+{ "c_count": 15, "custdist": 2 }
+{ "c_count": 28, "custdist": 1 }
+{ "c_count": 25, "custdist": 1 }
+{ "c_count": 3, "custdist": 1 }

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

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.adm
new file mode 100644
index 0000000..817794b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q15_top_supplier/q15_top_supplier.1.adm
@@ -0,0 +1 @@
+{ "s_suppkey": 10, "s_name": "Supplier#000000010", "s_address": "Saygah3gYWMp72i PY", "s_phone": "34-852-489-8585", "total_revenue": 797313.3838d }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.adm
new file mode 100644
index 0000000..045b764
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tpch-sql-sugar/q16_parts_supplier_relationship/q16_parts_supplier_relationship.1.adm
@@ -0,0 +1,34 @@
+{ "p_brand": "Brand#11", "p_type": "PROMO ANODIZED TIN", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#11", "p_type": "SMALL PLATED COPPER", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#11", "p_type": "STANDARD POLISHED TIN", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#13", "p_type": "MEDIUM ANODIZED STEEL", "p_size": 36, "supplier_cnt": 4 }
+{ "p_brand": "Brand#13", "p_type": "SMALL BRUSHED NICKEL", "p_size": 19, "supplier_cnt": 4 }
+{ "p_brand": "Brand#14", "p_type": "SMALL ANODIZED NICKEL", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#15", "p_type": "LARGE ANODIZED BRASS", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#21", "p_type": "LARGE BURNISHED COPPER", "p_size": 19, "supplier_cnt": 4 }
+{ "p_brand": "Brand#23", "p_type": "ECONOMY BRUSHED COPPER", "p_size": 9, "supplier_cnt": 4 }
+{ "p_brand": "Brand#24", "p_type": "MEDIUM PLATED STEEL", "p_size": 19, "supplier_cnt": 4 }
+{ "p_brand": "Brand#25", "p_type": "MEDIUM PLATED BRASS", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#31", "p_type": "ECONOMY PLATED STEEL", "p_size": 23, "supplier_cnt": 4 }
+{ "p_brand": "Brand#31", "p_type": "PROMO POLISHED TIN", "p_size": 23, "supplier_cnt": 4 }
+{ "p_brand": "Brand#32", "p_type": "MEDIUM BURNISHED BRASS", "p_size": 49, "supplier_cnt": 4 }
+{ "p_brand": "Brand#33", "p_type": "LARGE BRUSHED TIN", "p_size": 36, "supplier_cnt": 4 }
+{ "p_brand": "Brand#33", "p_type": "SMALL BURNISHED NICKEL", "p_size": 3, "supplier_cnt": 4 }
+{ "p_brand": "Brand#34", "p_type": "LARGE PLATED BRASS", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#34", "p_type": "MEDIUM BRUSHED COPPER", "p_size": 9, "supplier_cnt": 4 }
+{ "p_brand": "Brand#34", "p_type": "SMALL PLATED BRASS", "p_size": 14, "supplier_cnt": 4 }
+{ "p_brand": "Brand#35", "p_type": "STANDARD ANODIZED STEEL", "p_size": 23, "supplier_cnt": 4 }
+{ "p_brand": "Brand#43", "p_type": "MEDIUM ANODIZED BRASS", "p_size": 14, "supplier_cnt": 4 }
+{ "p_brand": "Brand#43", "p_type": "PROMO POLISHED BRASS", "p_size": 19, "supplier_cnt": 4 }
+{ "p_brand": "Brand#43", "p_type": "SMALL BRUSHED NICKEL", "p_size": 9, "supplier_cnt": 4 }
+{ "p_brand": "Brand#44", "p_type": "SMALL PLATED COPPER", "p_size": 19, "supplier_cnt": 4 }
+{ "p_brand": "Brand#51", "p_type": "ECONOMY POLISHED STEEL", "p_size": 49, "supplier_cnt": 4 }
+{ "p_brand": "Brand#52", "p_type": "MEDIUM BURNISHED TIN", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#52", "p_type": "SMALL BURNISHED NICKEL", "p_size": 14, "supplier_cnt": 4 }
+{ "p_brand": "Brand#53", "p_type": "LARGE BURNISHED NICKEL", "p_size": 23, "supplier_cnt": 4 }
+{ "p_brand": "Brand#53", "p_type": "MEDIUM BRUSHED COPPER", "p_size": 3, "supplier_cnt": 4 }
+{ "p_brand": "Brand#53", "p_type": "STANDARD PLATED STEEL", "p_size": 45, "supplier_cnt": 4 }
+{ "p_brand": "Brand#54", "p_type": "ECONOMY ANODIZED BRASS", "p_size": 9, "supplier_cnt": 4 }
+{ "p_brand": "Brand#55", "p_type": "STANDARD ANODIZED BRASS", "p_size": 36, "supplier_cnt": 4 }
+{ "p_brand": "Brand#55", "p_type": "STANDARD BRUSHED COPPER", "p_size": 3, "supplier_cnt": 4 }
+{ "p_brand": "Brand#25", "p_type": "SMALL BURNISHED COPPER", "p_size": 3, "supplier_cnt": 3 }


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

Posted by bu...@apache.org.
Support implicit variable name and column name.

1. Support WITH clause for general cases;
2. Fixed open/closed type optimization;
3. Fixed scoping for nested aggregations;
4. Fixed side effects during partition property analysis;
5. Fixed type propagation policy for Subplan operator.

Change-Id: I409b9ba139c9f000a6b9b84d519d172d0069e4bb
Reviewed-on: https://asterix-gerrit.ics.uci.edu/950
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <ti...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/9e3f9bef
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/9e3f9bef
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/9e3f9bef

Branch: refs/heads/master
Commit: 9e3f9befa09c355905747e405f860d384f9e169b
Parents: 5a12edf
Author: Yingyi Bu <yi...@couchbase.com>
Authored: Fri Jul 1 10:07:37 2016 -0700
Committer: Yingyi Bu <bu...@gmail.com>
Committed: Fri Jul 1 12:40:34 2016 -0700

----------------------------------------------------------------------
 .../asterix/optimizer/base/RuleCollections.java |   4 +-
 .../optimizer/rules/ResolveVariableRule.java    | 286 ++++++++++
 .../rules/SetClosedRecordConstructorsRule.java  |  35 +-
 .../LangExpressionToPlanTranslator.java         |   8 +-
 .../SqlppExpressionToPlanTranslator.java        |  43 ++
 .../asterix/test/sqlpp/ParserTestExecutor.java  |   3 +
 .../results/aggregate/constant-gby-agg.plan     |   6 +-
 .../results/disjunction-to-join-delete-3.plan   |   8 +-
 .../results/scan-insert-secondary-index.plan    |   4 +-
 .../optimizerts/results/scan-insert.plan        |   4 +-
 .../parserts/results_parser_sqlpp/2.ast         |   8 +-
 .../results_parser_sqlpp/columnalias.ast        |  10 +-
 .../results_parser_sqlpp/columnalias2.ast       |   4 +-
 .../results_parser_sqlpp/columnalias3.ast       |  10 +-
 .../results_parser_sqlpp/nestedFLWOGR3.ast      |   8 +-
 .../queries_sqlpp/dapd/q2-2/q2-2.1.ddl.sqlpp    |  55 ++
 .../queries_sqlpp/dapd/q2-2/q2-2.2.update.sqlpp |  19 +
 .../queries_sqlpp/dapd/q2-2/q2-2.3.query.sqlpp  |  40 ++
 .../queries_sqlpp/dapd/q2-3/q2-3.1.ddl.sqlpp    |  55 ++
 .../queries_sqlpp/dapd/q2-3/q2-3.2.update.sqlpp |  19 +
 .../queries_sqlpp/dapd/q2-3/q2-3.3.query.sqlpp  |  38 ++
 .../queries_sqlpp/dapd/q2-4/q2-4.1.ddl.sqlpp    |  55 ++
 .../queries_sqlpp/dapd/q2-4/q2-4.2.update.sqlpp |  19 +
 .../queries_sqlpp/dapd/q2-4/q2-4.3.query.sqlpp  |  39 ++
 .../queries_sqlpp/dapd/q2-5/q2-5.1.ddl.sqlpp    |  55 ++
 .../queries_sqlpp/dapd/q2-5/q2-5.2.update.sqlpp |  19 +
 .../queries_sqlpp/dapd/q2-5/q2-5.3.query.sqlpp  |  39 ++
 .../varlen-encoding.3.query.sqlpp               |   2 +
 .../distinct_by/distinct_by.1.ddl.sqlpp         |  47 ++
 .../distinct_by/distinct_by.2.update.sqlpp      |  24 +
 .../distinct_by/distinct_by.3.query.sqlpp       |  26 +
 .../group_no_agg/group_no_agg.1.ddl.sqlpp       |  34 ++
 .../group_no_agg/group_no_agg.2.update.sqlpp    |  24 +
 .../group_no_agg/group_no_agg.3.query.sqlpp     |  27 +
 .../nest_aggregate/nest_aggregate.1.ddl.sqlpp   |  94 ++++
 .../nest_aggregate.2.update.sqlpp               |  40 ++
 .../nest_aggregate/nest_aggregate.3.query.sqlpp |  44 ++
 .../nest_aggregate2/nest_aggregate2.1.ddl.sqlpp |  94 ++++
 .../nest_aggregate2.2.update.sqlpp              |  40 ++
 .../nest_aggregate2.3.query.sqlpp               |  45 ++
 .../q01_pricing_summary_report_nt.1.ddl.sqlpp   |  47 ++
 ...q01_pricing_summary_report_nt.2.update.sqlpp |  24 +
 .../q01_pricing_summary_report_nt.3.query.sqlpp |  37 ++
 .../q02_minimum_cost_supplier.1.ddl.sqlpp       | 134 +++++
 .../q02_minimum_cost_supplier.2.update.sqlpp    |  38 ++
 .../q02_minimum_cost_supplier.3.query.sqlpp     |  44 ++
 .../q03_shipping_priority_nt.1.ddl.sqlpp        | 134 +++++
 .../q03_shipping_priority_nt.2.update.sqlpp     |  28 +
 .../q03_shipping_priority_nt.3.query.sqlpp      |  35 ++
 .../q04_order_priority.1.ddl.sqlpp              | 134 +++++
 .../q04_order_priority.2.update.sqlpp           |  38 ++
 .../q04_order_priority.3.query.sqlpp            |  37 ++
 .../q05_local_supplier_volume.1.ddl.sqlpp       | 134 +++++
 .../q05_local_supplier_volume.2.update.sqlpp    |  38 ++
 .../q05_local_supplier_volume.3.query.sqlpp     |  42 ++
 .../q06_forecast_revenue_change.1.ddl.sqlpp     | 134 +++++
 .../q06_forecast_revenue_change.2.update.sqlpp  |  38 ++
 .../q06_forecast_revenue_change.3.query.sqlpp   |  33 ++
 .../q07_volume_shipping.1.ddl.sqlpp             | 134 +++++
 .../q07_volume_shipping.2.update.sqlpp          |  38 ++
 .../q07_volume_shipping.3.query.sqlpp           |  55 ++
 .../q08_national_market_share.1.ddl.sqlpp       | 134 +++++
 .../q08_national_market_share.2.update.sqlpp    |  38 ++
 .../q08_national_market_share.3.query.sqlpp     |  67 +++
 .../q09_product_type_profit_nt.1.ddl.sqlpp      | 134 +++++
 .../q09_product_type_profit_nt.2.update.sqlpp   |  38 ++
 .../q09_product_type_profit_nt.3.query.sqlpp    |  47 ++
 .../q10_returned_item.1.ddl.sqlpp               | 134 +++++
 .../q10_returned_item.2.update.sqlpp            |  38 ++
 .../q10_returned_item.3.query.sqlpp             |  43 ++
 .../q10_returned_item_int64.1.ddl.sqlpp         | 134 +++++
 .../q10_returned_item_int64.2.update.sqlpp      |  38 ++
 .../q10_returned_item_int64.3.query.sqlpp       |  44 ++
 .../q11_important_stock.1.ddl.sqlpp             | 134 +++++
 .../q11_important_stock.2.update.sqlpp          |  38 ++
 .../q11_important_stock.3.query.sqlpp           |  51 ++
 .../q12_shipping/q12_shipping.1.ddl.sqlpp       | 134 +++++
 .../q12_shipping/q12_shipping.2.update.sqlpp    |  38 ++
 .../q12_shipping/q12_shipping.3.query.sqlpp     |  33 ++
 .../q13_customer_distribution.1.ddl.sqlpp       | 134 +++++
 .../q13_customer_distribution.2.update.sqlpp    |  38 ++
 .../q13_customer_distribution.3.query.sqlpp     |  40 ++
 .../q14_promotion_effect.1.ddl.sqlpp            | 134 +++++
 .../q14_promotion_effect.2.update.sqlpp         |  38 ++
 .../q14_promotion_effect.3.query.sqlpp          |  29 +
 .../q15_top_supplier.1.ddl.sqlpp                | 134 +++++
 .../q15_top_supplier.2.update.sqlpp             |  38 ++
 .../q15_top_supplier.3.query.sqlpp              |  45 ++
 .../q16_parts_supplier_relationship.1.ddl.sqlpp | 134 +++++
 ...6_parts_supplier_relationship.2.update.sqlpp |  38 ++
 ...16_parts_supplier_relationship.3.query.sqlpp |  47 ++
 .../q17_large_gby_variant.1.ddl.sqlpp           | 134 +++++
 .../q17_large_gby_variant.2.update.sqlpp        |  38 ++
 .../q17_large_gby_variant.3.query.sqlpp         |  38 ++
 ...q17_small_quantity_order_revenue.1.ddl.sqlpp | 134 +++++
 ..._small_quantity_order_revenue.2.update.sqlpp |  38 ++
 ...7_small_quantity_order_revenue.3.query.sqlpp |  36 ++
 .../q18_large_volume_customer.1.ddl.sqlpp       | 134 +++++
 .../q18_large_volume_customer.2.update.sqlpp    |  38 ++
 .../q18_large_volume_customer.3.query.sqlpp     |  40 ++
 .../q19_discounted_revenue.1.ddl.sqlpp          | 134 +++++
 .../q19_discounted_revenue.2.update.sqlpp       |  38 ++
 .../q19_discounted_revenue.3.query.sqlpp        |  55 ++
 .../q20_potential_part_promotion.1.ddl.sqlpp    | 134 +++++
 .../q20_potential_part_promotion.2.update.sqlpp |  38 ++
 .../q20_potential_part_promotion.3.query.sqlpp  |  59 ++
 ...uppliers_who_kept_orders_waiting.1.ddl.sqlpp | 134 +++++
 ...liers_who_kept_orders_waiting.2.update.sqlpp |  38 ++
 ...pliers_who_kept_orders_waiting.3.query.sqlpp |  70 +++
 .../q22_global_sales_opportunity.1.ddl.sqlpp    | 134 +++++
 .../q22_global_sales_opportunity.2.update.sqlpp |  38 ++
 .../q22_global_sales_opportunity.3.query.sqlpp  |  38 ++
 .../query-issue562/query-issue562.1.ddl.sqlpp   | 140 +++++
 .../query-issue562.2.update.sqlpp               |  44 ++
 .../query-issue562/query-issue562.3.query.sqlpp |  47 ++
 .../query-issue601/query-issue601.1.ddl.sqlpp   |  53 ++
 .../query-issue601.2.update.sqlpp               |  30 +
 .../query-issue601/query-issue601.3.query.sqlpp |  32 ++
 .../query-issue638/query-issue638.1.ddl.sqlpp   | 140 +++++
 .../query-issue638.2.update.sqlpp               |  25 +
 .../query-issue638/query-issue638.3.query.sqlpp |  52 ++
 .../query-issue785-2.1.ddl.sqlpp                |  94 ++++
 .../query-issue785-2.2.update.sqlpp             |  40 ++
 .../query-issue785-2.3.query.sqlpp              |  53 ++
 .../query-issue785/query-issue785.1.ddl.sqlpp   |  94 ++++
 .../query-issue785.2.update.sqlpp               |  40 ++
 .../query-issue785/query-issue785.3.query.sqlpp |  47 ++
 .../query-issue786/query-issue786.1.ddl.sqlpp   |  94 ++++
 .../query-issue786.2.update.sqlpp               |  40 ++
 .../query-issue786/query-issue786.3.query.sqlpp |  43 ++
 .../query-issue810-2.1.ddl.sqlpp                |  53 ++
 .../query-issue810-2.2.update.sqlpp             |  30 +
 .../query-issue810-2.3.query.sqlpp              |  44 ++
 .../query-issue810-3.1.ddl.sqlpp                |  53 ++
 .../query-issue810-3.2.update.sqlpp             |  30 +
 .../query-issue810-3.3.query.sqlpp              |  52 ++
 .../query-issue810/query-issue810.1.ddl.sqlpp   |  53 ++
 .../query-issue810.2.update.sqlpp               |  30 +
 .../query-issue810/query-issue810.3.query.sqlpp |  48 ++
 .../highly-nested-open/highly-nested-open.3.adm |   8 +-
 .../distinct_by/distinct_by.1.adm               |  28 +
 .../group_no_agg/group_no_agg.1.adm             |   5 +
 .../nest_aggregate/nest_aggregate.1.adm         |  11 +
 .../nest_aggregate2/nest_aggregate2.1.adm       |  11 +
 .../q01_pricing_summary_report_nt.1.adm         |   4 +
 .../q02_minimum_cost_supplier.1.adm             |  13 +
 .../q03_shipping_priority_nt.1.adm              |   8 +
 .../q04_order_priority/q04_order_priority.1.adm |   5 +
 .../q05_local_supplier_volume.1.adm             |   8 +
 .../q06_forecast_revenue_change.1.adm           |   1 +
 .../q07_volume_shipping.1.adm                   |  37 ++
 .../q08_national_market_share.1.adm             |   2 +
 .../q09_product_type_profit_nt.1.adm            |  59 ++
 .../q10_returned_item/q10_returned_ite.1.adm    |  20 +
 .../q10_returned_item_int64.1.adm               |  20 +
 .../q11_important_stock.1.adm                   | 200 +++++++
 .../q12_shipping/q12_shipping.1.adm             |   2 +
 .../q13_customer_distribution.1.adm             |  27 +
 .../q14_promotion_effect.1.adm                  |   1 +
 .../q15_top_supplier/q15_top_supplier.1.adm     |   1 +
 .../q16_parts_supplier_relationship.1.adm       |  34 ++
 .../q17_large_gby_variant.3.adm                 | 200 +++++++
 .../q17_small_quantity_order_revenue.1.adm      |   1 +
 .../q18_large_volume_customer.1.adm             | 100 ++++
 .../q19_discounted_revenue.1.adm                |   1 +
 .../q20_potential_part_promotion.1.adm          |  10 +
 .../q21_suppliers_who_kept_orders_waiting.1.adm |  10 +
 .../q22_global_sales_opportunity.1.adm          |  23 +
 .../query-issue562/query-issue562.1.adm         |   7 +
 .../query-issue601/query-issue601.1.adm         |   7 +
 .../query-issue638/query-issue638.1.adm         |  59 ++
 .../query-issue785-2/query-issue785-2.1.adm     |  10 +
 .../query-issue785/query-issue785.1.adm         |  24 +
 .../query-issue786/query-issue786.1.adm         |   0
 .../query-issue810-2/query-issue810-2.1.adm     |   4 +
 .../query-issue810-3/query-issue810-3.1.adm     |   4 +
 .../query-issue810/query-issue810.1.adm         |   4 +
 .../query-issue827-2/query-issue827-2.1.adm     |   1 +
 .../query-issue827/query-issue827.1.adm         |   1 +
 .../query-issue827-2/query-issue827-2.1.adm     |   1 -
 .../query-issue827/query-issue827.1.adm         |   1 -
 .../groupby-orderby-count.3.ast                 |   8 +-
 .../overlap_bins_gby_3/overlap_bins_gby_3.3.ast |   8 +-
 .../query-ASTERIXDB-1263.23.ast                 |  12 +-
 .../query-ASTERIXDB-1263.23.ast                 |  12 +-
 .../resources/runtimets/testsuite_sqlpp.xml     | 211 +++++++-
 .../asterix/lang/common/base/Expression.java    |   4 +-
 .../asterix/lang/sqlpp/clause/FromTerm.java     |   7 +-
 .../sqlpp/expression/IndependentSubquery.java   |  57 ++
 .../lang/sqlpp/expression/SelectExpression.java |   2 +-
 .../rewrites/SqlppFunctionBodyRewriter.java     |   3 +
 .../lang/sqlpp/rewrites/SqlppQueryRewriter.java |  34 +-
 .../visitor/InlineColumnAliasVisitor.java       |  19 +-
 .../visitor/InlineWithExpressionVisitor.java    |  72 +++
 .../SqlppBuiltinFunctionRewriteVisitor.java     |   5 +-
 .../SqlppGlobalAggregationSugarVisitor.java     |   4 +-
 .../visitor/SqlppGroupBySugarVisitor.java       |  37 +-
 .../rewrites/visitor/SqlppGroupByVisitor.java   |  37 +-
 .../visitor/SqlppInlineUdfsVisitor.java         |   9 +
 .../visitor/VariableCheckAndRewriteVisitor.java |  71 ++-
 .../sqlpp/util/ExpressionToVariableUtil.java    |  53 ++
 .../lang/sqlpp/util/SqlppRewriteUtil.java       |  10 +-
 .../util/SqlppVariableSubstitutionUtil.java     |   3 +
 .../lang/sqlpp/util/SqlppVariableUtil.java      |  31 +-
 .../visitor/CheckSql92AggregateVisitor.java     |   6 +
 .../lang/sqlpp/visitor/DeepCopyVisitor.java     |  13 +-
 .../lang/sqlpp/visitor/FreeVariableVisitor.java |   7 +
 .../sqlpp/visitor/SqlppAstPrintVisitor.java     |   7 +
 ...SqlppCloneAndSubstituteVariablesVisitor.java |   9 +
 .../sqlpp/visitor/SqlppFormatPrintVisitor.java  |   7 +
 .../visitor/base/AbstractSqlppAstVisitor.java   |   6 +
 .../AbstractSqlppExpressionScopingVisitor.java  | 101 ++--
 .../AbstractSqlppSimpleExpressionVisitor.java   | 139 ++---
 .../lang/sqlpp/visitor/base/ISqlppVisitor.java  |   3 +
 .../src/main/javacc/SQLPP.html                  |  10 +-
 .../asterix-lang-sqlpp/src/main/javacc/SQLPP.jj |  35 +-
 .../metadata/declared/AqlMetadataProvider.java  |   7 +-
 .../om/functions/AsterixBuiltinFunctions.java   | 541 +++++++++----------
 .../impl/CollectionMemberResultType.java        |   3 +-
 .../impl/OpenRecordConstructorResultType.java   |  42 +-
 .../ScalarVersionOfAggregateResultType.java     |   7 +-
 .../apache/asterix/om/types/ARecordType.java    |  47 +-
 .../operators/logical/SubplanOperator.java      |   3 +-
 .../LogicalOperatorPrettyPrintVisitor.java      |   2 +-
 .../BroadcastPartitioningProperty.java          |   5 +-
 .../properties/IPartitioningProperty.java       |  13 +-
 .../properties/OrderedPartitionedProperty.java  |  18 +-
 .../core/algebra/properties/PropertiesUtil.java |  10 +-
 .../properties/RandomPartitioningProperty.java  |   5 +-
 .../properties/StructuralPropertiesVector.java  |  12 +-
 .../UnorderedPartitionedProperty.java           |   9 +-
 .../org/apache/hyracks/util/IntSerDeUtils.java  |  10 +-
 232 files changed, 10173 insertions(+), 603 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
index 53348fb..683d722 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
@@ -27,7 +27,6 @@ import org.apache.asterix.optimizer.rules.AsterixExtractFunctionsFromJoinConditi
 import org.apache.asterix.optimizer.rules.AsterixInlineVariablesRule;
 import org.apache.asterix.optimizer.rules.AsterixIntroduceGroupByCombinerRule;
 import org.apache.asterix.optimizer.rules.ByNameToByIndexFieldAccessRule;
-import org.apache.asterix.optimizer.rules.RemoveLeftOuterUnnestForLeftOuterJoinRule;
 import org.apache.asterix.optimizer.rules.CancelUnnestWithNestedListifyRule;
 import org.apache.asterix.optimizer.rules.CheckFilterExpressionTypeRule;
 import org.apache.asterix.optimizer.rules.ConstantFoldingRule;
@@ -59,11 +58,13 @@ import org.apache.asterix.optimizer.rules.PushGroupByThroughProduct;
 import org.apache.asterix.optimizer.rules.PushLimitIntoOrderByRule;
 import org.apache.asterix.optimizer.rules.PushProperJoinThroughProduct;
 import org.apache.asterix.optimizer.rules.PushSimilarityFunctionsBelowJoin;
+import org.apache.asterix.optimizer.rules.RemoveLeftOuterUnnestForLeftOuterJoinRule;
 import org.apache.asterix.optimizer.rules.RemoveRedundantListifyRule;
 import org.apache.asterix.optimizer.rules.RemoveRedundantSelectRule;
 import org.apache.asterix.optimizer.rules.RemoveSortInFeedIngestionRule;
 import org.apache.asterix.optimizer.rules.RemoveUnusedOneToOneEquiJoinRule;
 import org.apache.asterix.optimizer.rules.ReplaceSinkOpWithCommitOpRule;
+import org.apache.asterix.optimizer.rules.ResolveVariableRule;
 import org.apache.asterix.optimizer.rules.SetAsterixPhysicalOperatorsRule;
 import org.apache.asterix.optimizer.rules.SetClosedRecordConstructorsRule;
 import org.apache.asterix.optimizer.rules.SimilarityCheckRule;
@@ -150,6 +151,7 @@ public final class RuleCollections {
 
     public static final List<IAlgebraicRewriteRule> buildNormalizationRuleCollection() {
         List<IAlgebraicRewriteRule> normalization = new LinkedList<>();
+        normalization.add(new ResolveVariableRule());
         normalization.add(new IntroduceUnnestForCollectionToSequenceRule());
         normalization.add(new EliminateSubplanRule());
         normalization.add(new EnforceOrderByAfterSubplan());

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ResolveVariableRule.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ResolveVariableRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ResolveVariableRule.java
new file mode 100644
index 0000000..4965197
--- /dev/null
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ResolveVariableRule.java
@@ -0,0 +1,286 @@
+/*
+ * 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.optimizer.rules;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.asterix.lang.common.util.FunctionUtil;
+import org.apache.asterix.metadata.declared.AqlMetadataProvider;
+import org.apache.asterix.om.base.AString;
+import org.apache.asterix.om.constants.AsterixConstantValue;
+import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IAlgebricksConstantValue;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
+import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+
+/**
+ * This rule resolves references to undefined identifiers as:
+ * 1. variable/field-access paths, or
+ * 2. datasets
+ * based on the available type and metatadata information.
+ */
+public class ResolveVariableRule implements IAlgebraicRewriteRule {
+
+    @Override
+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
+        return false;
+    }
+
+    @Override
+    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
+        ILogicalOperator op = opRef.getValue();
+        if (op.getInputs().isEmpty()) {
+            return false;
+        }
+        // Populates the latest type information, e.g., resolved path sugars.
+        context.computeAndSetTypeEnvironmentForOperator(op);
+        if (op.acceptExpressionTransform(exprRef -> rewriteExpressionReference(op, exprRef, context))) {
+            // Generates the up-to-date type information.
+            context.computeAndSetTypeEnvironmentForOperator(op);
+            return true;
+        }
+        return false;
+    }
+
+    // Recursively rewrites for an expression within an operator.
+    private boolean rewriteExpressionReference(ILogicalOperator op, Mutable<ILogicalExpression> exprRef,
+            IOptimizationContext context) throws AlgebricksException {
+        ILogicalExpression expr = exprRef.getValue();
+        if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+            return false;
+        }
+        boolean changed = false;
+        AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
+        for (Mutable<ILogicalExpression> funcArgRef : funcExpr.getArguments()) {
+            if (rewriteExpressionReference(op, funcArgRef, context)) {
+                context.computeAndSetTypeEnvironmentForOperator(op);
+                changed = true;
+            }
+        }
+
+        // Cleans up extra scan-collections if there is.
+        cleanupScanCollectionForDataset(funcExpr);
+
+        // Does the actual resolution.
+        return changed || resolve(op, context, exprRef);
+    }
+
+    // Resolves a "resolve" function call expression to a fully qualified variable/field-access path or
+    // a dataset.
+    private boolean resolve(ILogicalOperator op, IOptimizationContext context, Mutable<ILogicalExpression> exprRef)
+            throws AlgebricksException {
+        AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) exprRef.getValue();
+        if (funcExpr.getFunctionIdentifier() != AsterixBuiltinFunctions.RESOLVE) {
+            return false;
+        }
+        ILogicalExpression arg = funcExpr.getArguments().get(0).getValue();
+        String unresolvedVarName = extractVariableName(arg);
+        return resolveInternal(exprRef, hasMatchedDataset(unresolvedVarName, context),
+                findCandidatePaths(op, extractPossibleVariables(funcExpr.getArguments()), unresolvedVarName, context),
+                unresolvedVarName);
+    }
+
+    // Extracts all possible variables from the arguments of the "resolve" function.
+    private List<LogicalVariable> extractPossibleVariables(List<Mutable<ILogicalExpression>> args)
+            throws AlgebricksException {
+        List<LogicalVariable> vars = new ArrayList<>();
+        // The first arg is is the name of the undefined variable.
+        for (int index = 1; index < args.size(); ++index) {
+            vars.add(extractVariable(args.get(index).getValue()));
+        }
+        return vars;
+    }
+
+    // Resolves an undefined name to a dataset or a fully qualified variable/field-access path
+    // based on the given information of dataset matches and candidate paths.
+    private boolean resolveInternal(Mutable<ILogicalExpression> funcRef, boolean hasMatchedDataset,
+            Collection<Pair<LogicalVariable, List<String>>> varAccessCandidates, String unresolvedVarName)
+            throws AlgebricksException {
+        AbstractFunctionCallExpression func = (AbstractFunctionCallExpression) funcRef.getValue();
+        int numVarCandidates = varAccessCandidates.size();
+        if (numVarCandidates > 1 || (numVarCandidates == 1 && hasMatchedDataset)) {
+            throw new AlgebricksException(
+                    "Cannot resolve ambiguous alias (variable) reference for identifier " + unresolvedVarName);
+        } else if (numVarCandidates <= 0) {
+            if (!hasMatchedDataset) {
+                throw new AlgebricksException(
+                        "Undefined alias (variable) reference for identifier " + unresolvedVarName);
+            }
+            // Rewrites the "resolve" function to a "dataset" function.
+            func.setFunctionInfo(FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.DATASET));
+        } else {
+            // Rewrites to field-access-by-names.
+            Pair<LogicalVariable, List<String>> varAndPath = varAccessCandidates.iterator().next();
+            LogicalVariable var = varAndPath.first;
+            List<String> path = varAndPath.second;
+            Mutable<ILogicalExpression> firstArgRef = new MutableObject<>(new VariableReferenceExpression(var));
+            ILogicalExpression newFunc = null;
+            for (String fieldName : path) {
+                List<Mutable<ILogicalExpression>> args = new ArrayList<>();
+                args.add(firstArgRef);
+                args.add(new MutableObject<ILogicalExpression>(
+                        new ConstantExpression(new AsterixConstantValue(new AString(fieldName)))));
+                newFunc = new ScalarFunctionCallExpression(
+                        FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME), args);
+                firstArgRef = new MutableObject<>(newFunc);
+            }
+            funcRef.setValue(newFunc);
+        }
+        return true;
+    }
+
+    // Finds all candidate fully qualified variable/field-access paths.
+    private Set<Pair<LogicalVariable, List<String>>> findCandidatePaths(ILogicalOperator op,
+            Collection<LogicalVariable> inputLiveVars, String unresolvedVarName, IOptimizationContext context)
+            throws AlgebricksException {
+        Set<Pair<LogicalVariable, List<String>>> candidates = new HashSet<>();
+        IVariableTypeEnvironment env = context.getOutputTypeEnvironment(op.getInputs().get(0).getValue());
+        for (LogicalVariable var : inputLiveVars) {
+            IAType type = (IAType) env.getVarType(var);
+            candidates.addAll(findCandidatePathsForVariable(unresolvedVarName, type, var, new ArrayList<String>()));
+        }
+        return candidates;
+    }
+
+    // Recursively finds candidate paths under a variable.
+    private Set<Pair<LogicalVariable, List<String>>> findCandidatePathsForVariable(String unresolvedVarName,
+            IAType pathType, LogicalVariable var, List<String> parentPath) throws AlgebricksException {
+        Set<Pair<LogicalVariable, List<String>>> varAccessCandidates = new HashSet<>();
+        IAType type = pathType;
+        if (type.getTypeTag() == ATypeTag.UNION) {
+            type = ((AUnionType) type).getActualType();
+        }
+        ATypeTag tag = type.getTypeTag();
+        if (tag == ATypeTag.ANY) {
+            List<String> path = new ArrayList<>(parentPath);
+            path.add(unresolvedVarName);
+            varAccessCandidates.add(new Pair<>(var, path));
+        }
+        if (tag == ATypeTag.RECORD) {
+            ARecordType recordType = (ARecordType) type;
+            if (recordType.canContainField(unresolvedVarName)) {
+                // If the field name is possible.
+                List<String> path = new ArrayList<>(parentPath);
+                path.add(unresolvedVarName);
+                varAccessCandidates.add(new Pair<>(var, path));
+            } else {
+                // Recursively identified possible paths.
+                String[] fieldNames = recordType.getFieldNames();
+                IAType[] fieldTypes = recordType.getFieldTypes();
+                for (int index = 0; index < fieldNames.length; ++index) {
+                    List<String> path = new ArrayList<>(parentPath);
+                    path.add(fieldNames[index]);
+                    varAccessCandidates
+                            .addAll(findCandidatePathsForVariable(unresolvedVarName, fieldTypes[index], var, path));
+                }
+            }
+        }
+        return varAccessCandidates;
+    }
+
+    // Checks whether the name matches a dataset.
+    private boolean hasMatchedDataset(String name, IOptimizationContext context) throws AlgebricksException {
+        AqlMetadataProvider mdp = (AqlMetadataProvider) context.getMetadataProvider();
+        if (name.contains(".")) {
+            String[] path = name.split("\\.");
+            if (path.length != 2) {
+                return false;
+            }
+            if (mdp.findDataset(path[0], path[1]) != null) {
+                return true;
+            }
+        }
+        if (mdp.findDataset(mdp.getDefaultDataverseName(), name) != null) {
+            return true;
+        }
+        return false;
+    }
+
+    // Extracts the variable from a variable reference expression.
+    private LogicalVariable extractVariable(ILogicalExpression expr) throws AlgebricksException {
+        if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
+            VariableReferenceExpression varRefExpr = (VariableReferenceExpression) expr;
+            return varRefExpr.getVariableReference();
+        } else {
+            // The sugar visitor gurantees this would not happen.
+            throw new AlgebricksException("The argument should be a variable reference expression.");
+        }
+    }
+
+    // Cleans up scan collections on top of a "dataset" function call since "dataset"
+    // is an unnest function.
+    private void cleanupScanCollectionForDataset(AbstractFunctionCallExpression funcExpr) {
+        if (funcExpr.getFunctionIdentifier() != AsterixBuiltinFunctions.SCAN_COLLECTION) {
+            return;
+        }
+        ILogicalExpression arg = funcExpr.getArguments().get(0).getValue();
+        if (arg.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+            return;
+        }
+        AbstractFunctionCallExpression argFuncExpr = (AbstractFunctionCallExpression) arg;
+        if (argFuncExpr.getFunctionIdentifier() != AsterixBuiltinFunctions.DATASET) {
+            return;
+        }
+        funcExpr.setFunctionInfo(argFuncExpr.getFunctionInfo());
+        funcExpr.getArguments().clear();
+        funcExpr.getArguments().addAll(argFuncExpr.getArguments());
+    }
+
+    // Extracts the name of an undefined variable.
+    private String extractVariableName(ILogicalExpression arg) throws AlgebricksException {
+        if (arg.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
+            throw new AlgebricksException("The argument is expected to be a constant value.");
+        }
+        ConstantExpression ce = (ConstantExpression) arg;
+        IAlgebricksConstantValue acv = ce.getValue();
+        if (!(acv instanceof AsterixConstantValue)) {
+            throw new AlgebricksException("The argument is expected to be an Asterix constant value.");
+        }
+        AsterixConstantValue acv2 = (AsterixConstantValue) acv;
+        if (acv2.getObject().getType().getTypeTag() != ATypeTag.STRING) {
+            throw new AlgebricksException("The argument is expected to be a string constant value.");
+        }
+        return ((AString) acv2.getObject()).getStringValue();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java
index 2829ec4..c57cdd8 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/SetClosedRecordConstructorsRule.java
@@ -22,11 +22,9 @@ import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.lang.common.util.FunctionUtil;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.typecomputer.base.TypeCastUtils;
-import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
-import org.apache.asterix.om.types.AUnionType;
-import org.apache.asterix.om.types.AUnorderedListType;
 import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.om.types.TypeHelper;
 import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
@@ -172,39 +170,12 @@ public class SetClosedRecordConstructorsRule implements IAlgebraicRewriteRule {
                 throw new AlgebricksException(
                         "Could not infer type for variable '" + expr.getVariableReference() + "'.");
             }
-            boolean dataIsClosed = isClosed((IAType) varType);
-            return new ClosedDataInfo(false, dataIsClosed, expr);
+            return new ClosedDataInfo(false, TypeHelper.isClosed((IAType) varType), expr);
         }
 
         private boolean hasClosedType(ILogicalExpression expr) throws AlgebricksException {
             IAType t = (IAType) context.getExpressionTypeComputer().getType(expr, context.getMetadataProvider(), env);
-            return isClosed(t);
-        }
-
-        private static boolean isClosed(IAType t) throws AlgebricksException {
-            switch (t.getTypeTag()) {
-                case MISSING:
-                case ANY:
-                    return false;
-                case SHORTWITHOUTTYPEINFO:
-                    return true;
-                case RECORD:
-                    return !((ARecordType) t).isOpen();
-                case UNION:
-                    AUnionType ut = (AUnionType) t;
-                    if (!isClosed(ut.getActualType())) {
-                        return false;
-                    }
-                    return true;
-                case ORDEREDLIST:
-                    AOrderedListType ol = (AOrderedListType) t;
-                    return isClosed(ol.getItemType());
-                case UNORDEREDLIST:
-                    AUnorderedListType ul = (AUnorderedListType) t;
-                    return isClosed(ul.getItemType());
-                default:
-                    return true;
-            }
+            return TypeHelper.isClosed(t);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index 0040b61..13eb399 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -1340,10 +1340,10 @@ class LangExpressionToPlanTranslator
 
     protected boolean expressionNeedsNoNesting(Expression expr) {
         Kind k = expr.getKind();
-        return (k == Kind.LITERAL_EXPRESSION) || (k == Kind.LIST_CONSTRUCTOR_EXPRESSION)
-                || (k == Kind.RECORD_CONSTRUCTOR_EXPRESSION) || (k == Kind.VARIABLE_EXPRESSION)
-                || (k == Kind.CALL_EXPRESSION) || (k == Kind.OP_EXPRESSION) || (k == Kind.FIELD_ACCESSOR_EXPRESSION)
-                || (k == Kind.INDEX_ACCESSOR_EXPRESSION) || (k == Kind.UNARY_EXPRESSION) || (k == Kind.IF_EXPRESSION);
+        return k == Kind.LITERAL_EXPRESSION || k == Kind.LIST_CONSTRUCTOR_EXPRESSION
+                || k == Kind.RECORD_CONSTRUCTOR_EXPRESSION || k == Kind.VARIABLE_EXPRESSION || k == Kind.CALL_EXPRESSION
+                || k == Kind.OP_EXPRESSION || k == Kind.FIELD_ACCESSOR_EXPRESSION || k == Kind.INDEX_ACCESSOR_EXPRESSION
+                || k == Kind.UNARY_EXPRESSION || k == Kind.IF_EXPRESSION || k == Kind.INDEPENDENT_SUBQUERY;
     }
 
     protected <T> List<T> mkSingletonArrayList(T item) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
index 5c50c41..410da06 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
@@ -49,6 +49,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.optype.JoinType;
 import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
@@ -66,6 +67,7 @@ import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
 import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
 import org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
@@ -76,6 +78,7 @@ import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnne
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterUnnestOperator;
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
@@ -154,6 +157,20 @@ class SqlppExpressionToPlanTranslator extends LangExpressionToPlanTranslator imp
     }
 
     @Override
+    public Pair<ILogicalOperator, LogicalVariable> visit(IndependentSubquery independentSubquery,
+            Mutable<ILogicalOperator> tupleSource) throws AsterixException {
+        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(independentSubquery.getExpr(),
+                tupleSource);
+        // Replaces nested tuple source with empty tuple source so that the subquery can be independent
+        // from its input operators.
+        replaceNtsWithEts(eo.second.getValue());
+        LogicalVariable var = context.newVar();
+        AssignOperator assignOp = new AssignOperator(var, new MutableObject<ILogicalExpression>(eo.first));
+        assignOp.getInputs().add(eo.second);
+        return new Pair<>(assignOp, var);
+    }
+
+    @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SelectSetOperation selectSetOperation,
             Mutable<ILogicalOperator> tupSource) throws AsterixException {
         Mutable<ILogicalOperator> currentOpRef = tupSource;
@@ -499,4 +516,30 @@ class SqlppExpressionToPlanTranslator extends LangExpressionToPlanTranslator imp
         }
     }
 
+    // Replaces nested tuple source with empty tuple source in nested subplans of
+    // a subplan operator.
+    private void replaceNtsWithEts(ILogicalOperator op) {
+        if (op.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
+            return;
+        }
+        SubplanOperator subplanOp = (SubplanOperator) op;
+        for (ILogicalPlan plan : subplanOp.getNestedPlans()) {
+            for (Mutable<ILogicalOperator> rootRef : plan.getRoots()) {
+                replaceNtsWithEtsTopDown(rootRef);
+            }
+        }
+    }
+
+    // Recursively replaces nested tuple source with empty tuple source
+    // in the operator tree under opRef.
+    private void replaceNtsWithEtsTopDown(Mutable<ILogicalOperator> opRef) {
+        ILogicalOperator op = opRef.getValue();
+        if (op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
+            opRef.setValue(new EmptyTupleSourceOperator());
+        }
+        for (Mutable<ILogicalOperator> childRef : op.getInputs()) {
+            replaceNtsWithEtsTopDown(childRef);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java
index e522457..fa7b272 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.test.sqlpp;
 
+import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -45,6 +46,7 @@ import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
 import org.apache.asterix.lang.sqlpp.rewrites.SqlppRewriterFactory;
 import org.apache.asterix.lang.sqlpp.util.SqlppAstPrintUtil;
 import org.apache.asterix.metadata.declared.AqlMetadataProvider;
+import org.apache.asterix.metadata.entities.Dataset;
 import org.apache.asterix.test.aql.TestExecutor;
 import org.apache.asterix.testframework.context.TestCaseContext;
 import org.apache.asterix.testframework.context.TestFileContext;
@@ -122,6 +124,7 @@ public class ParserTestExecutor extends TestExecutor {
             when(aqlMetadataProvider.getDefaultDataverseName()).thenReturn(dvName);
             when(aqlMetadataProvider.getConfig()).thenReturn(config);
             when(config.get(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS)).thenReturn("true");
+            when(aqlMetadataProvider.findDataset(anyString(), anyString())).thenReturn(mock(Dataset.class));
 
             for (Statement st : statements) {
                 if (st.getKind() == Kind.QUERY) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan
index dec5a77..37dcce2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan
@@ -3,13 +3,13 @@
     -- STREAM_PROJECT  |PARTITIONED|
       -- ASSIGN  |PARTITIONED|
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$29]  |PARTITIONED|
+          -- PRE_CLUSTERED_GROUP_BY[$$28]  |PARTITIONED|
                   {
                     -- AGGREGATE  |LOCAL|
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
                   }
-            -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$29(ASC)] HASH:[$$29]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$25]  |PARTITIONED|
+            -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$28(ASC)] HASH:[$$28]  |PARTITIONED|
+              -- SORT_GROUP_BY[$$24]  |PARTITIONED|
                       {
                         -- AGGREGATE  |LOCAL|
                           -- NESTED_TUPLE_SOURCE  |LOCAL|

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan
index 7d38039..1cb56c9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan
@@ -9,7 +9,7 @@
                 -- INSERT_DELETE  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- MATERIALIZE  |PARTITIONED|
-                      -- HASH_PARTITION_EXCHANGE [$$10]  |PARTITIONED|
+                      -- HASH_PARTITION_EXCHANGE [$$8]  |PARTITIONED|
                         -- ASSIGN  |PARTITIONED|
                           -- STREAM_PROJECT  |PARTITIONED|
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
@@ -18,9 +18,9 @@
                                   -- UNNEST  |UNPARTITIONED|
                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
                                 -- HASH_PARTITION_EXCHANGE [$$9]  |PARTITIONED|
-                                  -- STREAM_PROJECT  |PARTITIONED|
-                                    -- ASSIGN  |PARTITIONED|
+                                  -- ASSIGN  |PARTITIONED|
+                                    -- STREAM_PROJECT  |PARTITIONED|
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                         -- DATASOURCE_SCAN  |PARTITIONED|
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan
index cc9a865..5806723 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan
@@ -12,7 +12,7 @@
                       -- ASSIGN  |PARTITIONED|
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                           -- INSERT_DELETE  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$7]  |PARTITIONED|
+                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                               -- ASSIGN  |PARTITIONED|
                                 -- STREAM_PROJECT  |PARTITIONED|
                                   -- ASSIGN  |PARTITIONED|
@@ -21,4 +21,4 @@
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                           -- DATASOURCE_SCAN  |PARTITIONED|
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert.plan
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert.plan
index b34944d..b925aae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/scan-insert.plan
@@ -2,7 +2,7 @@
   -- STREAM_PROJECT  |PARTITIONED|
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
       -- INSERT_DELETE  |PARTITIONED|
-        -- HASH_PARTITION_EXCHANGE [$$7]  |PARTITIONED|
+        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
           -- ASSIGN  |PARTITIONED|
             -- STREAM_PROJECT  |PARTITIONED|
               -- ASSIGN  |PARTITIONED|
@@ -11,4 +11,4 @@
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                       -- DATASOURCE_SCAN  |PARTITIONED|
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/2.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/2.ast b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/2.ast
index 13c4380..a57de72 100644
--- a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/2.ast
+++ b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/2.ast
@@ -89,12 +89,12 @@ Let Variable [ Name=$by_chapter ]
           (
             SELECT ELEMENT [
             FieldAccessor [
-              Variable [ Name=#3 ]
+              Variable [ Name=#4 ]
               Field=es
             ]
             ]
-            FROM [              Variable [ Name=#1 ]
-              AS Variable [ Name=#3 ]
+            FROM [              Variable [ Name=#3 ]
+              AS Variable [ Name=#4 ]
             ]
           )
         ]
@@ -114,7 +114,7 @@ Let Variable [ Name=$by_chapter ]
         ]
         Field=chapter_name
       ]
-      GROUP AS Variable [ Name=#4 ]
+      GROUP AS Variable [ Name=#3 ]
       (
         e:=Variable [ Name=$e ]
         sig_sponsorship_count:=Variable [ Name=$sig_sponsorship_count ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias.ast b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias.ast
index 62b84d8..14b5108 100644
--- a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias.ast
+++ b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias.ast
@@ -1,6 +1,6 @@
 Query:
 SELECT [
-Variable [ Name=#1 ]
+Variable [ Name=$root ]
 root
 ]
 FROM [  FunctionCall Metadata.dataset@1[
@@ -9,7 +9,7 @@ FROM [  FunctionCall Metadata.dataset@1[
   AS Variable [ Name=$t ]
 ]
 Groupby
-  Variable [ Name=#1 ]
+  Variable [ Name=$root ]
   :=
   FunctionCall null.SQRT@1[
     OperatorExpr [
@@ -24,17 +24,17 @@ Groupby
       ]
     ]
   ]
-  GROUP AS Variable [ Name=#2 ]
+  GROUP AS Variable [ Name=#1 ]
   (
     t:=Variable [ Name=$t ]
   )
 
 Let Variable [ Name=$u ]
   :=
-  Variable [ Name=#1 ]
+  Variable [ Name=$root ]
  HAVING
   OperatorExpr [
-    Variable [ Name=#1 ]
+    Variable [ Name=$root ]
     >
     LiteralExpr [LONG] [0]
   ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias2.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias2.ast b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias2.ast
index c82e1da..0b7ccd2 100644
--- a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias2.ast
+++ b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias2.ast
@@ -25,13 +25,13 @@ FROM [  FunctionCall Metadata.dataset@1[
   AS Variable [ Name=$root ]
 ]
 Groupby
-  Variable [ Name=#1 ]
+  Variable [ Name=$id ]
   :=
   FieldAccessor [
     Variable [ Name=$root ]
     Field=id
   ]
-  GROUP AS Variable [ Name=#2 ]
+  GROUP AS Variable [ Name=#1 ]
   (
     root:=Variable [ Name=$root ]
   )

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias3.ast b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias3.ast
index fd269aa..cdd4653 100644
--- a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias3.ast
+++ b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/columnalias3.ast
@@ -4,7 +4,7 @@ RecordConstructor [
   (
     LiteralExpr [STRING] [root]
     :
-    Variable [ Name=#1 ]
+    Variable [ Name=$root ]
   )
 ]
 ]
@@ -14,7 +14,7 @@ FROM [  FunctionCall Metadata.dataset@1[
   AS Variable [ Name=$t ]
 ]
 Groupby
-  Variable [ Name=#1 ]
+  Variable [ Name=$root ]
   :=
   FunctionCall null.SQRT@1[
     OperatorExpr [
@@ -29,17 +29,17 @@ Groupby
       ]
     ]
   ]
-  GROUP AS Variable [ Name=#2 ]
+  GROUP AS Variable [ Name=#1 ]
   (
     t:=Variable [ Name=$t ]
   )
 
 Let Variable [ Name=$u ]
   :=
-  Variable [ Name=#1 ]
+  Variable [ Name=$root ]
  HAVING
   OperatorExpr [
-    Variable [ Name=#1 ]
+    Variable [ Name=$root ]
     >
     LiteralExpr [LONG] [0]
   ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/nestedFLWOGR3.ast
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/nestedFLWOGR3.ast b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/nestedFLWOGR3.ast
index d1be6d2..f4fcf1f 100644
--- a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/nestedFLWOGR3.ast
+++ b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/nestedFLWOGR3.ast
@@ -89,12 +89,12 @@ Let Variable [ Name=$by_chapter ]
           (
             SELECT ELEMENT [
             FieldAccessor [
-              Variable [ Name=#3 ]
+              Variable [ Name=#4 ]
               Field=es
             ]
             ]
-            FROM [              Variable [ Name=#1 ]
-              AS Variable [ Name=#3 ]
+            FROM [              Variable [ Name=#3 ]
+              AS Variable [ Name=#4 ]
             ]
           )
         ]
@@ -114,7 +114,7 @@ Let Variable [ Name=$by_chapter ]
         ]
         Field=chapter_name
       ]
-      GROUP AS Variable [ Name=#4 ]
+      GROUP AS Variable [ Name=#3 ]
       (
         e:=Variable [ Name=$e ]
         sig_sponsorship_count:=Variable [ Name=$sig_sponsorship_count ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.1.ddl.sqlpp
new file mode 100644
index 0000000..90482a7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.1.ddl.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+  street : string,
+  city : string,
+  zip : string,
+  latlong : point
+}
+
+create type test.EventType as
+ closed {
+  event_id : int64,
+  name : string,
+  location : AddressType?,
+  organizers : {{{
+          name : string
+      }
+}},
+  sponsoring_sigs : [{
+          sig_id : int64,
+          chapter_name : string
+      }
+],
+  interest_keywords : {{string}},
+  price : double?,
+  start_time : datetime,
+  end_time : datetime
+}
+
+create external  table Event(EventType) using localfs((`path`=`asterix_nc1://data/events/tiny/event.adm`),(`format`=`adm`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.2.update.sqlpp
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.2.update.sqlpp
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.3.query.sqlpp
new file mode 100644
index 0000000..307ad80
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-2/q2-2.3.query.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+/*
+ * This query tests the scoping of the same variable name, i.e., e.
+ */
+
+use test;
+
+
+select element {'sig_id':sig_id,'total_count':sig_sponsorship_count,'chapter_breakdown':by_chapter}
+from  Event as event,
+      event.sponsoring_sigs as sponsor
+with  e as {'event':event,'sponsor':sponsor}
+group by sponsor.sig_id as sig_id
+with  sig_sponsorship_count as count(e),
+      by_chapter as (
+      select element {'chapter_name':chapter_name,'escount':count(e)}
+      from  e as e
+      group by e.sponsor.chapter_name as chapter_name
+  )
+order by sig_sponsorship_count desc
+limit 5
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.1.ddl.sqlpp
new file mode 100644
index 0000000..90482a7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.1.ddl.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+  street : string,
+  city : string,
+  zip : string,
+  latlong : point
+}
+
+create type test.EventType as
+ closed {
+  event_id : int64,
+  name : string,
+  location : AddressType?,
+  organizers : {{{
+          name : string
+      }
+}},
+  sponsoring_sigs : [{
+          sig_id : int64,
+          chapter_name : string
+      }
+],
+  interest_keywords : {{string}},
+  price : double?,
+  start_time : datetime,
+  end_time : datetime
+}
+
+create external  table Event(EventType) using localfs((`path`=`asterix_nc1://data/events/tiny/event.adm`),(`format`=`adm`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.2.update.sqlpp
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.2.update.sqlpp
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.3.query.sqlpp
new file mode 100644
index 0000000..7f3aa7d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-3/q2-3.3.query.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+/*
+ * This query tests the column alias inlining for group-by expression.
+ */
+
+USE test;
+
+
+SELECT sponsor.sig_id, COUNT(1) total_count,
+       (
+         SELECT e.sponsor.chapter_name, COUNT(e) AS escount
+         FROM es AS e
+         GROUP BY chapter_name
+       ) chapter_breakdown
+FROM  Event,
+      Event.sponsoring_sigs AS sponsor
+GROUP BY sig_id GROUP AS es
+ORDER BY total_count DESC
+LIMIT 5
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.1.ddl.sqlpp
new file mode 100644
index 0000000..90482a7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.1.ddl.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+  street : string,
+  city : string,
+  zip : string,
+  latlong : point
+}
+
+create type test.EventType as
+ closed {
+  event_id : int64,
+  name : string,
+  location : AddressType?,
+  organizers : {{{
+          name : string
+      }
+}},
+  sponsoring_sigs : [{
+          sig_id : int64,
+          chapter_name : string
+      }
+],
+  interest_keywords : {{string}},
+  price : double?,
+  start_time : datetime,
+  end_time : datetime
+}
+
+create external  table Event(EventType) using localfs((`path`=`asterix_nc1://data/events/tiny/event.adm`),(`format`=`adm`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.2.update.sqlpp
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.2.update.sqlpp
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.3.query.sqlpp
new file mode 100644
index 0000000..a16706d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-4/q2-4.3.query.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+/*
+ * This query tests the path sugar in the group-by expression.
+ */
+
+
+USE test;
+
+
+SELECT sig_id, COUNT(1) total_count,
+       (
+         SELECT chapter_name, COUNT(e) AS escount
+         FROM es AS e
+         GROUP BY chapter_name
+       ) chapter_breakdown
+FROM  Event,
+      Event.sponsoring_sigs AS sponsor
+GROUP BY sig_id GROUP AS es
+ORDER BY total_count DESC
+LIMIT 5
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.1.ddl.sqlpp
new file mode 100644
index 0000000..90482a7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.1.ddl.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+  street : string,
+  city : string,
+  zip : string,
+  latlong : point
+}
+
+create type test.EventType as
+ closed {
+  event_id : int64,
+  name : string,
+  location : AddressType?,
+  organizers : {{{
+          name : string
+      }
+}},
+  sponsoring_sigs : [{
+          sig_id : int64,
+          chapter_name : string
+      }
+],
+  interest_keywords : {{string}},
+  price : double?,
+  start_time : datetime,
+  end_time : datetime
+}
+
+create external  table Event(EventType) using localfs((`path`=`asterix_nc1://data/events/tiny/event.adm`),(`format`=`adm`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.2.update.sqlpp
new file mode 100644
index 0000000..bd244d0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.2.update.sqlpp
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.3.query.sqlpp
new file mode 100644
index 0000000..7eaaf0f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dapd/q2-5/q2-5.3.query.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+/*
+ * This query tests the auto-generated group-by variable for a group-by expression.
+ */
+
+
+USE test;
+
+
+SELECT sig_id, COUNT(1) total_count,
+       (
+         SELECT chapter_name, COUNT(e) AS escount
+         FROM es AS e
+         GROUP BY e.sponsor.chapter_name
+       ) chapter_breakdown
+FROM  Event,
+      Event.sponsoring_sigs AS sponsor
+GROUP BY sponsor.sig_id GROUP AS es
+ORDER BY total_count DESC
+LIMIT 5
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/varlen-encoding/varlen-encoding.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/varlen-encoding/varlen-encoding.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/varlen-encoding/varlen-encoding.3.query.sqlpp
index 1f34d7e..cf5f211 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/varlen-encoding/varlen-encoding.3.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/string/varlen-encoding/varlen-encoding.3.query.sqlpp
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+set inline_with "false"
+
 let str127 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
 , str128 = `string-concat`([ 'y', str127 ])
 , str256 = `string-concat`([ str128, str128 ])

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.1.ddl.sqlpp
new file mode 100644
index 0000000..c5fcd3f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.1.ddl.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.2.update.sqlpp
new file mode 100644
index 0000000..d996e74
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.2.update.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.3.query.sqlpp
new file mode 100644
index 0000000..2975b74
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/distinct_by/distinct_by.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+SELECT DISTINCT l_returnflag, l_linestatus, l_shipmode
+FROM  LineItem AS l
+ORDER BY l_returnflag, l_linestatus, l_shipmode
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.1.ddl.sqlpp
new file mode 100644
index 0000000..581b684
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.1.ddl.sqlpp
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create  table Regions_group_no_agg(RegionType) primary key r_regionkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.2.update.sqlpp
new file mode 100644
index 0000000..7283894
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/group_no_agg/group_no_agg.2.update.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table Regions_group_no_agg using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+


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

Posted by bu...@apache.org.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
new file mode 100644
index 0000000..f193938
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_large_gby_variant/q17_large_gby_variant.3.query.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+SELECT l_partkey t_partkey,
+       count(1) t_count,
+       0.2 * avg(l_quantity) t_avg_quantity,
+       max(l_suppkey) t_max_suppkey,
+       max(l_linenumber) t_max_linenumber,
+       avg(l_extendedprice) t_avg_extendedprice,
+       avg(l_discount) t_avg_discount,
+       avg(l_tax) t_avg_tax,
+       max(l_shipdate) t_max_shipdate,
+       min(l_commitdate) t_min_commitdate,
+       min(l_receiptdate) t_min_receiptdate,
+       max(l_comment) t_max_comment
+FROM  LineItem
+GROUP BY l_partkey
+ORDER BY l_partkey
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
new file mode 100644
index 0000000..e4f3299
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q17_small_quantity_order_revenue/q17_small_quantity_order_revenue.3.query.sqlpp
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+WITH tmp AS
+(
+    SELECT l_partkey t_partkey, 0.2 * avg(l_quantity) t_avg_quantity
+    FROM LineItem
+    GROUP BY l_partkey
+)
+
+SELECT ELEMENT SUM(l_extendedprice) / 7.0
+FROM  tmp,
+      LineItem,
+      Part
+WHERE p_partkey = l_partkey AND p_container = 'MED BOX'
+            AND l_partkey = t_partkey AND l_quantity < t_avg_quantity
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
new file mode 100644
index 0000000..4f0561c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q18_large_volume_customer/q18_large_volume_customer.3.query.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+WITH tmp AS
+(
+    SELECT l_orderkey, sum(l_quantity) t_sum_quantity
+    FROM  LineItem
+    GROUP BY l_orderkey
+)
+
+SELECT c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice,
+       sum(l_quantity) sum_quantity
+FROM  Customer,
+      Orders,
+      tmp t,
+      LineItem l
+WHERE c_custkey = o_custkey AND o_orderkey = t.l_orderkey
+      AND t.l_orderkey = l.l_orderkey AND t_sum_quantity > 30
+GROUP BY c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice
+ORDER BY o_totalprice DESC,o_orderdate
+LIMIT 100
+;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
new file mode 100644
index 0000000..cb352ea
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q19_discounted_revenue/q19_discounted_revenue.3.query.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 ownershi  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+set `import-private-functions` `true`;
+
+SELECT ELEMENT SUM(l_extendedprice * (1 - l_discount))
+FROM LineItem
+JOIN Part
+ON p_partkey = l_partkey
+  WHERE
+  (
+    p_brand = 'Brand#12'
+    AND `reg-exp`(p_container, 'SM CASE||SM BOX||SM PACK||SM PKG')
+    AND l_quantity >= 1 and l_quantity <= 11
+    AND p_size >= 1 and p_size <= 5
+    AND `reg-exp`(l_shipmode, 'AIR||AIR REG')
+    AND l_shipinstruct = 'DELIVER IN PERSON'
+  )
+  OR
+  (
+    p_brand = 'Brand#23'
+    AND `reg-exp`(p_container, 'MED BAG||MED BOX||MED PKG||MED PACK')
+    AND l_quantity >= 10 and l_quantity <= 20
+    AND p_size >= 1 and p_size <= 10
+    AND `reg-exp`(l_shipmode, 'AIR||AIR REG')
+    AND l_shipinstruct = 'DELIVER IN PERSON'
+  )
+  OR
+  (
+    p_brand = 'Brand#34'
+    AND `reg-exp`(p_container, 'LG CASE||LG BOX||LG PACK||LG PKG')
+    AND l_quantity >= 20 and l_quantity <= 30
+    AND p_size >= 1 and p_size <= 15
+    AND `reg-exp`(l_shipmode, 'AIR||AIR REG')
+    AND l_shipinstruct = 'DELIVER IN PERSON'
+  )
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
new file mode 100644
index 0000000..2c138e8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q20_potential_part_promotion/q20_potential_part_promotion.3.query.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreement  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+WITH q20_tmp1 AS
+(
+  SELECT DISTINCT p_partkey
+  FROM Part
+)
+,
+q20_tmp2 AS
+(
+  SELECT l_partkey, l_suppkey, 0.5 * sum(l_quantity) AS sum_quantity
+  FROM LineItem
+  GROUP BY l_partkey l_partkey, l_suppkey l_suppkey
+)
+,
+q20_tmp3 AS
+(
+  SELECT ps_suppkey, ps_availqty, sum_quantity
+  FROM Partsupp
+  JOIN q20_tmp1
+  ON ps_partkey = p_partkey
+  JOIN q20_tmp2
+  ON ps_partkey = l_partkey and ps_suppkey = l_suppkey
+)
+,
+q20_tmp4 AS
+(
+  SELECT ps_suppkey
+  FROM q20_tmp3
+  WHERE ps_availqty > sum_quantity
+  GROUP BY ps_suppkey
+)
+
+SELECT s_name, s_address
+FROM Supplier
+JOIN Nation
+ON s_nationkey = n_nationkey
+JOIN q20_tmp4
+ON s_suppkey = ps_suppkey
+ORDER BY s_name;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.ddl.sqlpp
new file mode 100644
index 0000000..907be7b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : int64,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int64,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int64,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int64,
+  ps_suppkey : int64,
+  ps_availqty : int64,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
new file mode 100644
index 0000000..62a6d9d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q21_suppliers_who_kept_orders_waiting/q21_suppliers_who_kept_orders_waiting.3.query.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE tpch;
+
+
+WITH tmp1 AS
+(
+    SELECT l_orderkey,
+           count(l_suppkey) AS count_suppkey,
+           max(l_suppkey) AS max_suppkey
+    FROM  (
+            SELECT l_orderkey, l_suppkey
+            from  LineItem AS l
+            GROUP BY l_orderkey, l_suppkey
+          ) AS l2
+    GROUP BY l_orderkey
+),
+tmp2 AS
+(
+    SELECT l_orderkey,
+           count(l_suppkey) AS count_suppkey,
+           max(l_suppkey) AS max_suppkey
+    FROM  (
+            SELECT l_orderkey, l_suppkey
+            FROM LineItem
+            WHERE l_receiptdate > l_commitdate
+            GROUP BY l_orderkey, l_suppkey
+          ) AS l2
+    GROUP BY l_orderkey as l_orderkey
+)
+
+SELECT s_name, count(t4) AS numwait
+FROM  (
+    SELECT s_name, l_suppkey, t2.l_orderkey, count_suppkey, max_suppkey
+    FROM  (
+            SELECT s_name, t1.l_orderkey AS l_orderkey, l_suppkey
+            FROM  LineItem l,
+                  (
+                        SELECT s_name, s_suppkey
+                        FROM Nation,
+                             Supplier
+                        WHERE s_nationkey = n_nationkey
+                   ) AS ns,
+                   Orders,
+                   tmp1 AS t1
+            WHERE s_suppkey = l_suppkey AND l_receiptdate > l_commitdate
+                  AND o_orderkey = t1.l_orderkey AND l.l_orderkey = t1.l_orderkey
+          ) AS t3
+     JOIN tmp2 AS t2 ON count_suppkey >= 0 AND t3.l_orderkey = t2.l_orderkey
+) AS t4
+GROUP BY s_name
+ORDER BY numwait DESC, s_name
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.ddl.sqlpp
new file mode 100644
index 0000000..176cdc2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.1.ddl.sqlpp
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.2.update.sqlpp
new file mode 100644
index 0000000..eb9cb82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.2.update.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
new file mode 100644
index 0000000..f873dc6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q22_global_sales_opportunity/q22_global_sales_opportunity.3.query.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use tpch;
+
+WITH q22_customer_tmp AS
+(
+    SELECT c_acctbal, c_custkey, substring(c_phone,1,2) AS cntrycode
+    FROM  Customer
+)
+,
+avg AS (
+        SELECT ELEMENT AVG(c_acctbal)
+        FROM  Customer
+        WHERE c_acctbal > 0.0
+)[0]
+SELECT  cntrycode, count(ct) AS numcust, SUM(c_acctbal) AS totacctbal
+FROM  q22_customer_tmp AS ct
+WHERE c_acctbal > avg
+GROUP BY cntrycode
+ORDER BY cntrycode
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.1.ddl.sqlpp
new file mode 100644
index 0000000..9447c79
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.1.ddl.sqlpp
@@ -0,0 +1,140 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue562
+ * https://code.google.com/p/asterixdb/issues/detail?id=562
+ * Expected Res : SUCCESS
+ * Date         : 15th Jan. 2015
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Part(PartType) primary key p_partkey;
+
+create  table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.2.update.sqlpp
new file mode 100644
index 0000000..0d86b7f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.2.update.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue562
+ * https://code.google.com/p/asterixdb/issues/detail?id=562
+ * Expected Res : SUCCESS
+ * Date         : 15th Jan. 2015
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Part using localfs ((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Partsupp using localfs ((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.3.query.sqlpp
new file mode 100644
index 0000000..afd3db5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue562/query-issue562.3.query.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue562
+ * https://code.google.com/p/asterixdb/issues/detail?id=562
+ * Expected Res : SUCCESS
+ * Date         : 15th Jan. 2015
+ */
+
+USE tpch;
+
+
+WITH q22_customer_tmp AS
+(
+    SELECT c_acctbal, c_custkey, phone_substr AS cntrycode
+    FROM  Customer
+    LET  phone_substr = substring(c_phone,1,2)
+    WHERE phone_substr = '13' OR phone_substr = '31' OR phone_substr = '23' OR phone_substr = '29'
+          OR phone_substr = '30' OR phone_substr = '18' OR phone_substr = '17'
+)
+
+SELECT cntrycode, count(ct) AS numcust, sum(c_acctbal) AS totacctbal
+FROM  q22_customer_tmp as ct
+WHERE coll_count((
+                SELECT ELEMENT Orders
+                FROM  Orders
+                WHERE c_custkey = o_custkey
+            )) = 0
+GROUP BY cntrycode
+ORDER BY cntrycode
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.1.ddl.sqlpp
new file mode 100644
index 0000000..8a4e320
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.1.ddl.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue601
+ * https://code.google.com/p/asterixdb/issues/detail?id=601
+ * Expected Res : SUCCESS
+ * Date         : 10th Oct 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int64,
+  l_partkey : int64,
+  l_suppkey : int64,
+  l_linenumber : int64,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create  table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.2.update.sqlpp
new file mode 100644
index 0000000..969381e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.2.update.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue601
+ * https://code.google.com/p/asterixdb/issues/detail?id=601
+ * Expected Res : SUCCESS
+ * Date         : 10th Oct 2014
+ */
+
+use tpch;
+
+
+load  table LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.3.query.sqlpp
new file mode 100644
index 0000000..fe70e94
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue601/query-issue601.3.query.sqlpp
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue601
+ * https://code.google.com/p/asterixdb/issues/detail?id=601
+ * Expected Res : SUCCESS
+ * Date         : 10th Oct 2014
+ */
+
+USE tpch;
+
+
+SELECT l_linenumber, count(l) AS count_order
+FROM  LineItem AS l
+GROUP BY l_linenumber
+;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.1.ddl.sqlpp
new file mode 100644
index 0000000..3365a47
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.1.ddl.sqlpp
@@ -0,0 +1,140 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue638
+ * https://code.google.com/p/asterixdb/issues/detail?id=638
+ * Expected Res : SUCCESS
+ * Date         : 24th Oct. 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : int32,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int32,
+  o_custkey : int32,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int32,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int32,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int32,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int32,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int32,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int32,
+  n_name : string,
+  n_regionkey : int32,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int32,
+  r_name : string,
+  r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+  p_partkey : int32,
+  p_name : string,
+  p_mfgr : string,
+  p_brand : string,
+  p_type : string,
+  p_size : int32,
+  p_container : string,
+  p_retailprice : double,
+  p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+  ps_partkey : int32,
+  ps_suppkey : int32,
+  ps_availqty : int32,
+  ps_supplycost : double,
+  ps_comment : string
+}
+
+create external  table LineItem(LineItemType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+create external  table Orders(OrderType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+create external  table Supplier(SupplierType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+create external  table Region(RegionType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+create external  table Nation(NationType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+create external  table Part(PartType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/part.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+create external  table Partsupp(PartSuppType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/partsupp.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+create external  table Customer(CustomerType) using `localfs`((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.2.update.sqlpp
new file mode 100644
index 0000000..86538e8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.2.update.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue638
+ * https://code.google.com/p/asterixdb/issues/detail?id=638
+ * Expected Res : SUCCESS
+ * Date         : 24th Oct. 2014
+ */
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.3.query.sqlpp
new file mode 100644
index 0000000..5dcfead
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue638/query-issue638.3.query.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue638
+ * https://code.google.com/p/asterixdb/issues/detail?id=638
+ * Expected Res : SUCCESS
+ * Date         : 24th Oct. 2014
+ */
+
+USE tpch;
+
+
+SELECT nation, o_year, sum(amount) AS sum_profit
+FROM
+  (
+    SELECT   n_name AS nation,
+             `get-year`(o_orderdate) AS o_year,
+             l_extendedprice * (1 - l_discount) -  ps_supplycost * l_quantity AS amount
+    FROM
+      Orders o JOIN
+      (
+       SELECT l_extendedprice, l_discount, l_quantity, l_orderkey, n_name, ps_supplycost
+       FROM Part p JOIN
+         (SELECT l_extendedprice, l_discount, l_quantity, l_partkey, l_orderkey, n_name, ps_supplycost
+          FROM Partsupp ps join
+            (SELECT l_suppkey, l_extendedprice, l_discount, l_quantity, l_partkey, l_orderkey, n_name
+             FROM
+               (SELECT s_suppkey, n_name
+                FROM Nation n join Supplier s ON n_nationkey = s_nationkey
+               ) s1 JOIN LineItem l ON s_suppkey = l_suppkey
+            ) l1 ON ps_suppkey = l_suppkey and ps_partkey = l_partkey
+         ) l2 ON contains(p_name,'green') AND p_partkey = l_partkey
+     ) l3 ON o_orderkey = l_orderkey
+  ) profit
+GROUP BY nation, o_year
+ORDER BY nation, o_year desc;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.ddl.sqlpp
new file mode 100644
index 0000000..18e3fa1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.1.ddl.sqlpp
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue785
+ * https://code.google.com/p/asterixdb/issues/detail?id=785
+ * Expected Res : SUCCESS
+ * Date         : 2nd Oct. 2014
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+  o_orderkey : int64,
+  o_custkey : int64,
+  o_orderstatus : string,
+  o_totalprice : double,
+  o_orderdate : string,
+  o_orderpriority : string,
+  o_clerk : string,
+  o_shippriority : int64,
+  o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+  c_custkey : int64,
+  c_name : string,
+  c_address : string,
+  c_nationkey : int64,
+  c_phone : string,
+  c_acctbal : double,
+  c_mktsegment : string,
+  c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+  s_suppkey : int64,
+  s_name : string,
+  s_address : string,
+  s_nationkey : int64,
+  s_phone : string,
+  s_acctbal : double,
+  s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+  n_nationkey : int64,
+  n_name : string,
+  n_regionkey : int64,
+  n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+  r_regionkey : int64,
+  r_name : string,
+  r_comment : string
+}
+
+create  table Orders(OrderType) primary key o_orderkey;
+
+create  table Supplier(SupplierType) primary key s_suppkey;
+
+create  table Region(RegionType) primary key r_regionkey;
+
+create  table Nation(NationType) primary key n_nationkey;
+
+create  table Customer(CustomerType) primary key c_custkey;
+
+create  table SelectedNation(NationType) primary key n_nationkey;
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.2.update.sqlpp
new file mode 100644
index 0000000..23539e7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/query-issue785-2/query-issue785-2.2.update.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue785
+ * https://code.google.com/p/asterixdb/issues/detail?id=785
+ * Expected Res : SUCCESS
+ * Date         : 2nd Oct. 2014
+ */
+
+use tpch;
+
+
+load  table Orders using localfs ((`path`=`asterix_nc1://data/tpch0.001/orders.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Supplier using localfs ((`path`=`asterix_nc1://data/tpch0.001/supplier.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Region using localfs ((`path`=`asterix_nc1://data/tpch0.001/region.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Nation using localfs ((`path`=`asterix_nc1://data/tpch0.001/nation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table Customer using localfs ((`path`=`asterix_nc1://data/tpch0.001/customer.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+
+load  table SelectedNation using localfs ((`path`=`asterix_nc1://data/tpch0.001/selectednation.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`));
+


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

Posted by bu...@apache.org.
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 {


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

Posted by bu...@apache.org.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
index afed6c9..e5950e3 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
@@ -114,488 +114,486 @@ public class AsterixBuiltinFunctions {
 
     private static final FunctionInfoRepository registeredFunctions = new FunctionInfoRepository();
 
-    private static final Map<IFunctionInfo, ATypeHierarchy.Domain> registeredFunctionsDomain = new HashMap<IFunctionInfo, ATypeHierarchy.Domain>();
+    private static final Map<IFunctionInfo, ATypeHierarchy.Domain> registeredFunctionsDomain = new HashMap<>();
 
     // it is supposed to be an identity mapping
-    private final static Map<IFunctionInfo, IFunctionInfo> builtinPublicFunctionsSet = new HashMap<IFunctionInfo, IFunctionInfo>();
-    private final static Map<IFunctionInfo, IFunctionInfo> builtinPrivateFunctionsSet = new HashMap<IFunctionInfo, IFunctionInfo>();
-
-    private final static Map<IFunctionInfo, IResultTypeComputer> funTypeComputer = new HashMap<IFunctionInfo, IResultTypeComputer>();
-
-    private final static Set<IFunctionInfo> builtinAggregateFunctions = new HashSet<IFunctionInfo>();
-    private static final Set<IFunctionInfo> datasetFunctions = new HashSet<IFunctionInfo>();
-    private static final Set<IFunctionInfo> similarityFunctions = new HashSet<IFunctionInfo>();
-    private static final Set<IFunctionInfo> globalAggregateFunctions = new HashSet<IFunctionInfo>();
-    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToLocalAggregate = new HashMap<IFunctionInfo, IFunctionInfo>();
-    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToIntermediateAggregate = new HashMap<IFunctionInfo, IFunctionInfo>();
-    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToGlobalAggregate = new HashMap<IFunctionInfo, IFunctionInfo>();
-    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToSerializableAggregate = new HashMap<IFunctionInfo, IFunctionInfo>();
-    private final static Map<IFunctionInfo, Boolean> builtinUnnestingFunctions = new HashMap<IFunctionInfo, Boolean>();
-    private final static Map<IFunctionInfo, IFunctionInfo> scalarToAggregateFunctionMap = new HashMap<IFunctionInfo, IFunctionInfo>();
-    private static final Map<IFunctionInfo, SpatialFilterKind> spatialFilterFunctions = new HashMap<IFunctionInfo, SpatialFilterKind>();
-
-    public final static FunctionIdentifier TYPE_OF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "type-of", 1);
-    public final static FunctionIdentifier GET_HANDLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    private static final Map<IFunctionInfo, IFunctionInfo> builtinPublicFunctionsSet = new HashMap<>();
+    private static final Map<IFunctionInfo, IFunctionInfo> builtinPrivateFunctionsSet = new HashMap<>();
+
+    private static final Map<IFunctionInfo, IResultTypeComputer> funTypeComputer = new HashMap<>();
+
+    private static final Set<IFunctionInfo> builtinAggregateFunctions = new HashSet<>();
+    private static final Set<IFunctionInfo> datasetFunctions = new HashSet<>();
+    private static final Set<IFunctionInfo> similarityFunctions = new HashSet<>();
+    private static final Set<IFunctionInfo> globalAggregateFunctions = new HashSet<>();
+    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToLocalAggregate = new HashMap<>();
+    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToIntermediateAggregate = new HashMap<>();
+    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToGlobalAggregate = new HashMap<>();
+    private static final Map<IFunctionInfo, IFunctionInfo> aggregateToSerializableAggregate = new HashMap<>();
+    private static final Map<IFunctionInfo, Boolean> builtinUnnestingFunctions = new HashMap<>();
+    private static final Map<IFunctionInfo, IFunctionInfo> scalarToAggregateFunctionMap = new HashMap<>();
+    private static final Map<IFunctionInfo, SpatialFilterKind> spatialFilterFunctions = new HashMap<>();
+
+    public static final FunctionIdentifier TYPE_OF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "type-of", 1);
+    public static final FunctionIdentifier GET_HANDLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "get-handle", 2);
-    public final static FunctionIdentifier GET_DATA = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-data",
+    public static final FunctionIdentifier GET_DATA = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-data",
             2);
 
-    public final static FunctionIdentifier GET_ITEM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-item",
+    public static final FunctionIdentifier GET_ITEM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-item",
             2);
-    public final static FunctionIdentifier ANY_COLLECTION_MEMBER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier ANY_COLLECTION_MEMBER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "any-collection-member", 1);
-    public final static FunctionIdentifier LISTIFY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "listify", 1);
-    // public final static FunctionIdentifier BAGIFY = new
-    // FunctionIdentifier(ASTERIX_NS, "bagify", 1, true);
-    public final static FunctionIdentifier LEN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "len", 1);
+    public static final FunctionIdentifier LISTIFY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "listify", 1);
+    public static final FunctionIdentifier LEN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "len", 1);
 
-    public final static FunctionIdentifier CONCAT_NON_NULL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CONCAT_NON_NULL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "concat-non-null", FunctionIdentifier.VARARGS);
-    public final static FunctionIdentifier EMPTY_STREAM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier EMPTY_STREAM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "empty-stream", 0);
-    public final static FunctionIdentifier NON_EMPTY_STREAM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NON_EMPTY_STREAM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "non-empty-stream", 0);
-    public final static FunctionIdentifier ORDERED_LIST_CONSTRUCTOR = new FunctionIdentifier(
+    public static final FunctionIdentifier ORDERED_LIST_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "ordered-list-constructor", FunctionIdentifier.VARARGS);
-    public final static FunctionIdentifier UNORDERED_LIST_CONSTRUCTOR = new FunctionIdentifier(
+    public static final FunctionIdentifier UNORDERED_LIST_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "unordered-list-constructor", FunctionIdentifier.VARARGS);
 
-    public final static FunctionIdentifier DEEP_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DEEP_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "deep-equal", 2);
 
     // records
-    public final static FunctionIdentifier RECORD_MERGE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier RECORD_MERGE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "record-merge", 2);
-    public final static FunctionIdentifier REMOVE_FIELDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier REMOVE_FIELDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "record-remove-fields", 2);
-    public final static FunctionIdentifier ADD_FIELDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier ADD_FIELDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "record-add-fields", 2);
 
-    public final static FunctionIdentifier CLOSED_RECORD_CONSTRUCTOR = new FunctionIdentifier(
+    public static final FunctionIdentifier CLOSED_RECORD_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "closed-record-constructor", FunctionIdentifier.VARARGS);
-    public final static FunctionIdentifier OPEN_RECORD_CONSTRUCTOR = new FunctionIdentifier(
+    public static final FunctionIdentifier OPEN_RECORD_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "open-record-constructor", FunctionIdentifier.VARARGS);
-    public final static FunctionIdentifier FIELD_ACCESS_BY_INDEX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FIELD_ACCESS_BY_INDEX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "field-access-by-index", 2);
-    public final static FunctionIdentifier FIELD_ACCESS_BY_NAME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FIELD_ACCESS_BY_NAME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "field-access-by-name", 2);
-    public final static FunctionIdentifier FIELD_ACCESS_NESTED = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FIELD_ACCESS_NESTED = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "field-access-nested", 2);
-    public final static FunctionIdentifier GET_RECORD_FIELDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier GET_RECORD_FIELDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "get-record-fields", 1);
-    public final static FunctionIdentifier GET_RECORD_FIELD_VALUE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier GET_RECORD_FIELD_VALUE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "get-record-field-value", 2);
 
     // numeric
-    public final static FunctionIdentifier NUMERIC_UNARY_MINUS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NUMERIC_UNARY_MINUS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "numeric-unary-minus", 1);
-    public final static FunctionIdentifier NUMERIC_SUBTRACT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NUMERIC_SUBTRACT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "numeric-subtract", 2);
-    public final static FunctionIdentifier NUMERIC_MULTIPLY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NUMERIC_MULTIPLY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "numeric-multiply", 2);
-    public final static FunctionIdentifier NUMERIC_DIVIDE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NUMERIC_DIVIDE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "numeric-divide", 2);
-    public final static FunctionIdentifier NUMERIC_MOD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NUMERIC_MOD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "numeric-mod", 2);
-    public final static FunctionIdentifier NUMERIC_IDIV = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NUMERIC_IDIV = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "numeric-idiv", 2);
-    public final static FunctionIdentifier CARET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "caret", 2);
-    public final static FunctionIdentifier NUMERIC_ABS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "abs", 1);
-    public final static FunctionIdentifier NUMERIC_CEILING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CARET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "caret", 2);
+    public static final FunctionIdentifier NUMERIC_ABS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "abs", 1);
+    public static final FunctionIdentifier NUMERIC_CEILING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "ceiling", 1);
-    public final static FunctionIdentifier NUMERIC_FLOOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "floor",
+    public static final FunctionIdentifier NUMERIC_FLOOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "floor",
             1);
-    public final static FunctionIdentifier NUMERIC_ROUND = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "round",
+    public static final FunctionIdentifier NUMERIC_ROUND = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "round",
             1);
-    public final static FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN = new FunctionIdentifier(
+    public static final FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "round-half-to-even", 1);
-    public final static FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN2 = new FunctionIdentifier(
+    public static final FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN2 = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "round-half-to-even", 2);
 
     // binary functions
-    public final static FunctionIdentifier BINARY_LENGTH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier BINARY_LENGTH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "binary-length", 1);
-    public final static FunctionIdentifier PARSE_BINARY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PARSE_BINARY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "parse-binary", 2);
-    public final static FunctionIdentifier PRINT_BINARY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PRINT_BINARY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "print-binary", 2);
-    public final static FunctionIdentifier BINARY_CONCAT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier BINARY_CONCAT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "binary-concat", 1);
-    public final static FunctionIdentifier SUBBINARY_FROM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SUBBINARY_FROM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sub-binary", 2);
-    public final static FunctionIdentifier SUBBINARY_FROM_TO = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SUBBINARY_FROM_TO = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sub-binary", 3);
-    public final static FunctionIdentifier FIND_BINARY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FIND_BINARY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "find-binary", 2);
-    public final static FunctionIdentifier FIND_BINARY_FROM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FIND_BINARY_FROM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "find-binary", 3);
     // String funcitons
-    public final static FunctionIdentifier STRING_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string-equal", 2);
-    public final static FunctionIdentifier STRING_MATCHES = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_MATCHES = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "matches", 2);
-    public final static FunctionIdentifier STRING_MATCHES_WITH_FLAG = new FunctionIdentifier(
+    public static final FunctionIdentifier STRING_MATCHES_WITH_FLAG = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "matches", 3);
-    public final static FunctionIdentifier STRING_LOWERCASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_LOWERCASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "lowercase", 1);
-    public final static FunctionIdentifier STRING_UPPERCASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_UPPERCASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "uppercase", 1);
-    public final static FunctionIdentifier STRING_REPLACE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_REPLACE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "replace", 3);
-    public final static FunctionIdentifier STRING_REPLACE_WITH_FLAG = new FunctionIdentifier(
+    public static final FunctionIdentifier STRING_REPLACE_WITH_FLAG = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "replace", 4);
-    public final static FunctionIdentifier STRING_LENGTH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_LENGTH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string-length", 1);
-    public final static FunctionIdentifier STRING_LIKE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "like",
+    public static final FunctionIdentifier STRING_LIKE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "like",
             2);
-    public final static FunctionIdentifier STRING_CONTAINS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_CONTAINS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "contains", 2);
-    public final static FunctionIdentifier STRING_STARTS_WITH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_STARTS_WITH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "starts-with", 2);
-    public final static FunctionIdentifier STRING_ENDS_WITH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_ENDS_WITH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "ends-with", 2);
-    public final static FunctionIdentifier SUBSTRING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "substring",
+    public static final FunctionIdentifier SUBSTRING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "substring",
             3);
-    public final static FunctionIdentifier SUBSTRING2 = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SUBSTRING2 = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "substring", 2);
-    public final static FunctionIdentifier SUBSTRING_BEFORE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SUBSTRING_BEFORE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "substring-before", 2);
-    public final static FunctionIdentifier SUBSTRING_AFTER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SUBSTRING_AFTER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "substring-after", 2);
-    public final static FunctionIdentifier STRING_TO_CODEPOINT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_TO_CODEPOINT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string-to-codepoint", 1);
-    public final static FunctionIdentifier CODEPOINT_TO_STRING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CODEPOINT_TO_STRING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "codepoint-to-string", 1);
-    public final static FunctionIdentifier STRING_CONCAT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_CONCAT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string-concat", 1);
-    public final static FunctionIdentifier STRING_JOIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_JOIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string-join", 2);
 
-    public final static FunctionIdentifier DATASET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "dataset", 1);
-    public final static FunctionIdentifier FEED_COLLECT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DATASET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "dataset", 1);
+    public static final FunctionIdentifier FEED_COLLECT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "feed-collect", 6);
-    public final static FunctionIdentifier FEED_INTERCEPT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FEED_INTERCEPT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "feed-intercept", 1);
 
-    public final static FunctionIdentifier INDEX_SEARCH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INDEX_SEARCH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "index-search", FunctionIdentifier.VARARGS);
 
-    public final static FunctionIdentifier MAKE_FIELD_INDEX_HANDLE = new FunctionIdentifier(
+    public static final FunctionIdentifier MAKE_FIELD_INDEX_HANDLE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "make-field-index-handle", 2);
-    public final static FunctionIdentifier MAKE_FIELD_NESTED_HANDLE = new FunctionIdentifier(
+    public static final FunctionIdentifier MAKE_FIELD_NESTED_HANDLE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "make-field-nested-handle", 3);
-    public final static FunctionIdentifier MAKE_FIELD_NAME_HANDLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier MAKE_FIELD_NAME_HANDLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "make-field-name-handle", 1);
 
-    public final static FunctionIdentifier AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-avg", 1);
-    public final static FunctionIdentifier COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-count", 1);
-    public final static FunctionIdentifier SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sum", 1);
-    public final static FunctionIdentifier LOCAL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-avg", 1);
+    public static final FunctionIdentifier COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-count", 1);
+    public static final FunctionIdentifier SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sum", 1);
+    public static final FunctionIdentifier LOCAL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-sum", 1);
-    public final static FunctionIdentifier MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-max", 1);
-    public final static FunctionIdentifier LOCAL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-max", 1);
+    public static final FunctionIdentifier LOCAL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-max", 1);
-    public final static FunctionIdentifier MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-min", 1);
-    public final static FunctionIdentifier LOCAL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-min", 1);
+    public static final FunctionIdentifier LOCAL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-min", 1);
-    public final static FunctionIdentifier GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-global-avg", 1);
-    public final static FunctionIdentifier INTERMEDIATE_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERMEDIATE_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-intermediate-avg", 1);
-    public final static FunctionIdentifier LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-avg", 1);
 
-    public final static FunctionIdentifier SCALAR_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "avg", 1);
-    public final static FunctionIdentifier SCALAR_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "count",
+    public static final FunctionIdentifier SCALAR_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "avg", 1);
+    public static final FunctionIdentifier SCALAR_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "count",
             1);
-    public final static FunctionIdentifier SCALAR_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sum", 1);
-    public final static FunctionIdentifier SCALAR_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "max", 1);
-    public final static FunctionIdentifier SCALAR_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "min", 1);
-    public final static FunctionIdentifier SCALAR_GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sum", 1);
+    public static final FunctionIdentifier SCALAR_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "max", 1);
+    public static final FunctionIdentifier SCALAR_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "min", 1);
+    public static final FunctionIdentifier SCALAR_GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "global-avg", 1);
-    public final static FunctionIdentifier SCALAR_LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "local-avg", 1);
 
     // serializable aggregate functions
-    public final static FunctionIdentifier SERIAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "avg-serial", 1);
-    public final static FunctionIdentifier SERIAL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "count-serial", 1);
-    public final static FunctionIdentifier SERIAL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sum-serial", 1);
-    public final static FunctionIdentifier SERIAL_LOCAL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_LOCAL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "local-sum-serial", 1);
-    public final static FunctionIdentifier SERIAL_GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "global-avg-serial", 1);
-    public final static FunctionIdentifier SERIAL_LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "local-avg-serial", 1);
-    public final static FunctionIdentifier SERIAL_INTERMEDIATE_AVG = new FunctionIdentifier(
+    public static final FunctionIdentifier SERIAL_INTERMEDIATE_AVG = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "intermediate-avg-serial", 1);
 
     // sql aggregate functions
-    public final static FunctionIdentifier SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-avg",
+    public static final FunctionIdentifier SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-avg",
             1);
-    public final static FunctionIdentifier INTERMEDIATE_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERMEDIATE_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "intermediate-agg-sql-avg", 1);
-    public final static FunctionIdentifier SQL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SQL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-sql-count", 1);
-    public final static FunctionIdentifier SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-sum",
+    public static final FunctionIdentifier SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-sum",
             1);
-    public final static FunctionIdentifier LOCAL_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier LOCAL_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-sql-sum", 1);
-    public final static FunctionIdentifier SQL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-max",
+    public static final FunctionIdentifier SQL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-max",
             1);
-    public final static FunctionIdentifier LOCAL_SQL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier LOCAL_SQL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-sql-max", 1);
-    public final static FunctionIdentifier SQL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-min",
+    public static final FunctionIdentifier SQL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-min",
             1);
-    public final static FunctionIdentifier LOCAL_SQL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier LOCAL_SQL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-sql-min", 1);
-    public final static FunctionIdentifier GLOBAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier GLOBAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-global-sql-avg", 1);
-    public final static FunctionIdentifier LOCAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier LOCAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "agg-local-sql-avg", 1);
 
-    public final static FunctionIdentifier SCALAR_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-avg", 1);
-    public final static FunctionIdentifier SCALAR_SQL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_SQL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-count", 1);
-    public final static FunctionIdentifier SCALAR_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-sum", 1);
-    public final static FunctionIdentifier SCALAR_SQL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_SQL_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-max", 1);
-    public final static FunctionIdentifier SCALAR_SQL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_SQL_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-min", 1);
-    public final static FunctionIdentifier SCALAR_GLOBAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_GLOBAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "global-sql-avg", 1);
-    public final static FunctionIdentifier SCALAR_LOCAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCALAR_LOCAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "local-sql-avg", 1);
 
     // serializable sql aggregate functions
-    public final static FunctionIdentifier SERIAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-avg-serial", 1);
-    public final static FunctionIdentifier SERIAL_SQL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_SQL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-count-serial", 1);
-    public final static FunctionIdentifier SERIAL_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "sql-sum-serial", 1);
-    public final static FunctionIdentifier SERIAL_LOCAL_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_LOCAL_SQL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "local-sql-sum-serial", 1);
-    public final static FunctionIdentifier SERIAL_GLOBAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_GLOBAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "global-sql-avg-serial", 1);
-    public final static FunctionIdentifier SERIAL_INTERMEDIATE_SQL_AVG = new FunctionIdentifier(
+    public static final FunctionIdentifier SERIAL_INTERMEDIATE_SQL_AVG = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "intermediate-sql-avg-serial", 1);
-    public final static FunctionIdentifier SERIAL_LOCAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SERIAL_LOCAL_SQL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "local-sql-avg-serial", 1);
 
-    public final static FunctionIdentifier SCAN_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SCAN_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "scan-collection", 1);
-    public final static FunctionIdentifier SUBSET_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SUBSET_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "subset-collection", 3);
 
-    public final static FunctionIdentifier RANGE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "range", 2);
+    public static final FunctionIdentifier RANGE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "range", 2);
 
     // fuzzy functions:
-    public final static FunctionIdentifier FUZZY_EQ = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "fuzzy-eq",
+    public static final FunctionIdentifier FUZZY_EQ = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "fuzzy-eq",
             2);
 
-    public final static FunctionIdentifier PREFIX_LEN_JACCARD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PREFIX_LEN_JACCARD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "prefix-len-jaccard", 2);
 
-    public final static FunctionIdentifier SIMILARITY_JACCARD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SIMILARITY_JACCARD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "similarity-jaccard", 2);
-    public final static FunctionIdentifier SIMILARITY_JACCARD_CHECK = new FunctionIdentifier(
+    public static final FunctionIdentifier SIMILARITY_JACCARD_CHECK = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "similarity-jaccard-check", 3);
-    public final static FunctionIdentifier SIMILARITY_JACCARD_SORTED = new FunctionIdentifier(
+    public static final FunctionIdentifier SIMILARITY_JACCARD_SORTED = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "similarity-jaccard-sorted", 2);
-    public final static FunctionIdentifier SIMILARITY_JACCARD_SORTED_CHECK = new FunctionIdentifier(
+    public static final FunctionIdentifier SIMILARITY_JACCARD_SORTED_CHECK = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "similarity-jaccard-sorted-check", 3);
-    public final static FunctionIdentifier SIMILARITY_JACCARD_PREFIX = new FunctionIdentifier(
+    public static final FunctionIdentifier SIMILARITY_JACCARD_PREFIX = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "similarity-jaccard-prefix", 6);
-    public final static FunctionIdentifier SIMILARITY_JACCARD_PREFIX_CHECK = new FunctionIdentifier(
+    public static final FunctionIdentifier SIMILARITY_JACCARD_PREFIX_CHECK = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "similarity-jaccard-prefix-check", 6);
 
-    public final static FunctionIdentifier EDIT_DISTANCE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier EDIT_DISTANCE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "edit-distance", 2);
-    public final static FunctionIdentifier EDIT_DISTANCE_CHECK = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier EDIT_DISTANCE_CHECK = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "edit-distance-check", 3);
-    public final static FunctionIdentifier EDIT_DISTANCE_LIST_IS_FILTERABLE = new FunctionIdentifier(
+    public static final FunctionIdentifier EDIT_DISTANCE_LIST_IS_FILTERABLE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "edit-distance-list-is-filterable", 2);
-    public final static FunctionIdentifier EDIT_DISTANCE_STRING_IS_FILTERABLE = new FunctionIdentifier(
+    public static final FunctionIdentifier EDIT_DISTANCE_STRING_IS_FILTERABLE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "edit-distance-string-is-filterable", 4);
-    public final static FunctionIdentifier EDIT_DISTANCE_CONTAINS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier EDIT_DISTANCE_CONTAINS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "edit-distance-contains", 3);
 
     // tokenizers:
-    public final static FunctionIdentifier WORD_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier WORD_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "word-tokens", 1);
-    public final static FunctionIdentifier HASHED_WORD_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier HASHED_WORD_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "hashed-word-tokens", 1);
-    public final static FunctionIdentifier COUNTHASHED_WORD_TOKENS = new FunctionIdentifier(
+    public static final FunctionIdentifier COUNTHASHED_WORD_TOKENS = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "counthashed-word-tokens", 1);
-    public final static FunctionIdentifier GRAM_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier GRAM_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "gram-tokens", 3);
-    public final static FunctionIdentifier HASHED_GRAM_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier HASHED_GRAM_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "hashed-gram-tokens", 3);
-    public final static FunctionIdentifier COUNTHASHED_GRAM_TOKENS = new FunctionIdentifier(
+    public static final FunctionIdentifier COUNTHASHED_GRAM_TOKENS = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "counthashed-gram-tokens", 3);
 
-    public final static FunctionIdentifier TID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tid", 0);
-    public final static FunctionIdentifier GTID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "gtid", 0);
+    public static final FunctionIdentifier TID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tid", 0);
+    public static final FunctionIdentifier GTID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "gtid", 0);
 
     // constructors:
-    public final static FunctionIdentifier BOOLEAN_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier BOOLEAN_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "boolean", 1);
-    public final static FunctionIdentifier NULL_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier NULL_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "null", 1);
-    public final static FunctionIdentifier STRING_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier STRING_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string", 1);
-    public final static FunctionIdentifier BINARY_HEX_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier BINARY_HEX_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "hex", 1);
-    public final static FunctionIdentifier BINARY_BASE64_CONSTRUCTOR = new FunctionIdentifier(
+    public static final FunctionIdentifier BINARY_BASE64_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "base64", 1);
-    public final static FunctionIdentifier INT8_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INT8_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "int8", 1);
-    public final static FunctionIdentifier INT16_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INT16_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "int16", 1);
-    public final static FunctionIdentifier INT32_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INT32_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "int32", 1);
-    public final static FunctionIdentifier INT64_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INT64_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "int64", 1);
-    public final static FunctionIdentifier FLOAT_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FLOAT_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "float", 1);
-    public final static FunctionIdentifier DOUBLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DOUBLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "double", 1);
-    public final static FunctionIdentifier POINT_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier POINT_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "point", 1);
-    public final static FunctionIdentifier POINT3D_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier POINT3D_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "point3d", 1);
-    public final static FunctionIdentifier LINE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier LINE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "line", 1);
-    public final static FunctionIdentifier CIRCLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CIRCLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "circle", 1);
-    public final static FunctionIdentifier RECTANGLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier RECTANGLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "rectangle", 1);
-    public final static FunctionIdentifier POLYGON_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier POLYGON_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "polygon", 1);
-    public final static FunctionIdentifier TIME_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier TIME_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "time", 1);
-    public final static FunctionIdentifier DATE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DATE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "date", 1);
-    public final static FunctionIdentifier DATETIME_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DATETIME_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "datetime", 1);
-    public final static FunctionIdentifier DURATION_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DURATION_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "duration", 1);
-    public final static FunctionIdentifier UUID_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier UUID_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "uuid", 1);
 
-    public final static FunctionIdentifier YEAR_MONTH_DURATION_CONSTRUCTOR = new FunctionIdentifier(
+    public static final FunctionIdentifier YEAR_MONTH_DURATION_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "year-month-duration", 1);
-    public final static FunctionIdentifier DAY_TIME_DURATION_CONSTRUCTOR = new FunctionIdentifier(
+    public static final FunctionIdentifier DAY_TIME_DURATION_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "day-time-duration", 1);
 
-    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval", 2);
-    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_DATE = new FunctionIdentifier(
+    public static final FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_DATE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "interval-start-from-date", 2);
-    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_TIME = new FunctionIdentifier(
+    public static final FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_TIME = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "interval-start-from-time", 2);
-    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_DATETIME = new FunctionIdentifier(
+    public static final FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_DATETIME = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "interval-start-from-datetime", 2);
-    public final static FunctionIdentifier INTERVAL_BEFORE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_BEFORE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-before", 2);
-    public final static FunctionIdentifier INTERVAL_AFTER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_AFTER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-after", 2);
-    public final static FunctionIdentifier INTERVAL_MEETS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_MEETS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-meets", 2);
-    public final static FunctionIdentifier INTERVAL_MET_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_MET_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-met-by", 2);
-    public final static FunctionIdentifier INTERVAL_OVERLAPS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_OVERLAPS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-overlaps", 2);
-    public final static FunctionIdentifier INTERVAL_OVERLAPPED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_OVERLAPPED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-overlapped-by", 2);
-    public final static FunctionIdentifier INTERVAL_OVERLAPPING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_OVERLAPPING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-overlapping", 2);
-    public final static FunctionIdentifier INTERVAL_STARTS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_STARTS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-starts", 2);
-    public final static FunctionIdentifier INTERVAL_STARTED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_STARTED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-started-by", 2);
-    public final static FunctionIdentifier INTERVAL_COVERS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_COVERS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-covers", 2);
-    public final static FunctionIdentifier INTERVAL_COVERED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_COVERED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-covered-by", 2);
-    public final static FunctionIdentifier INTERVAL_ENDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_ENDS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-ends", 2);
-    public final static FunctionIdentifier INTERVAL_ENDED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INTERVAL_ENDED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "interval-ended-by", 2);
-    public final static FunctionIdentifier CURRENT_TIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CURRENT_TIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "current-time", 0);
-    public final static FunctionIdentifier CURRENT_DATE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CURRENT_DATE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "current-date", 0);
-    public final static FunctionIdentifier CURRENT_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CURRENT_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "current-datetime", 0);
-    public final static FunctionIdentifier DURATION_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DURATION_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "duration-equal", 2);
-    public final static FunctionIdentifier YEAR_MONTH_DURATION_GREATER_THAN = new FunctionIdentifier(
+    public static final FunctionIdentifier YEAR_MONTH_DURATION_GREATER_THAN = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "year-month-duration-greater-than", 2);
-    public final static FunctionIdentifier YEAR_MONTH_DURATION_LESS_THAN = new FunctionIdentifier(
+    public static final FunctionIdentifier YEAR_MONTH_DURATION_LESS_THAN = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "year-month-duration-less-than", 2);
-    public final static FunctionIdentifier DAY_TIME_DURATION_GREATER_THAN = new FunctionIdentifier(
+    public static final FunctionIdentifier DAY_TIME_DURATION_GREATER_THAN = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "day-time-duration-greater-than", 2);
-    public final static FunctionIdentifier DAY_TIME_DURATION_LESS_THAN = new FunctionIdentifier(
+    public static final FunctionIdentifier DAY_TIME_DURATION_LESS_THAN = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "day-time-duration-less-than", 2);
-    public final static FunctionIdentifier DURATION_FROM_MONTHS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DURATION_FROM_MONTHS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "duration-from-months", 1);
-    public final static FunctionIdentifier MONTHS_FROM_YEAR_MONTH_DURATION = new FunctionIdentifier(
+    public static final FunctionIdentifier MONTHS_FROM_YEAR_MONTH_DURATION = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "months-from-year-month-duration", 1);
-    public final static FunctionIdentifier DURATION_FROM_MILLISECONDS = new FunctionIdentifier(
+    public static final FunctionIdentifier DURATION_FROM_MILLISECONDS = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "duration-from-ms", 1);
-    public final static FunctionIdentifier MILLISECONDS_FROM_DAY_TIME_DURATION = new FunctionIdentifier(
+    public static final FunctionIdentifier MILLISECONDS_FROM_DAY_TIME_DURATION = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "ms-from-day-time-duration", 1);
 
-    public final static FunctionIdentifier GET_YEAR_MONTH_DURATION = new FunctionIdentifier(
+    public static final FunctionIdentifier GET_YEAR_MONTH_DURATION = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "get-year-month-duration", 1);
-    public final static FunctionIdentifier GET_DAY_TIME_DURATION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier GET_DAY_TIME_DURATION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "get-day-time-duration", 1);
-    public final static FunctionIdentifier DURATION_FROM_INTERVAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DURATION_FROM_INTERVAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "duration-from-interval", 1);
 
     // spatial
-    public final static FunctionIdentifier CREATE_POINT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_POINT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-point", 2);
-    public final static FunctionIdentifier CREATE_LINE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_LINE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-line", 2);
-    public final static FunctionIdentifier CREATE_POLYGON = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_POLYGON = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-polygon", 1);
-    public final static FunctionIdentifier CREATE_CIRCLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_CIRCLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-circle", 2);
-    public final static FunctionIdentifier CREATE_RECTANGLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_RECTANGLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-rectangle", 2);
-    public final static FunctionIdentifier SPATIAL_INTERSECT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SPATIAL_INTERSECT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "spatial-intersect", 2);
-    public final static FunctionIdentifier SPATIAL_AREA = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SPATIAL_AREA = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "spatial-area", 1);
-    public final static FunctionIdentifier SPATIAL_DISTANCE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SPATIAL_DISTANCE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "spatial-distance", 2);
-    public final static FunctionIdentifier CREATE_MBR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_MBR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-mbr", 3);
-    public final static FunctionIdentifier SPATIAL_CELL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SPATIAL_CELL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "spatial-cell", 4);
-    public final static FunctionIdentifier SWITCH_CASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier SWITCH_CASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "switch-case", FunctionIdentifier.VARARGS);
-    public final static FunctionIdentifier REG_EXP = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "reg-exp", 2);
+    public static final FunctionIdentifier REG_EXP = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "reg-exp", 2);
 
-    public final static FunctionIdentifier INJECT_FAILURE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier INJECT_FAILURE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "inject-failure", 2);
-    public final static FunctionIdentifier CAST_RECORD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CAST_RECORD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "cast-record", 1);
-    public final static FunctionIdentifier FLOW_RECORD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier FLOW_RECORD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "flow-record", 1);
-    public final static FunctionIdentifier CAST_LIST = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "cast-list",
+    public static final FunctionIdentifier CAST_LIST = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "cast-list",
             1);
 
-    public final static FunctionIdentifier CREATE_UUID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_UUID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-uuid", 0);
-    public final static FunctionIdentifier CREATE_QUERY_UID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier CREATE_QUERY_UID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "create-query-uid", 0);
 
     // Spatial and temporal type accessors
@@ -649,48 +647,48 @@ public class AsterixBuiltinFunctions {
             FunctionConstants.ASTERIX_NS, "date-from-unix-time-in-days", 1);
     public static final FunctionIdentifier DATE_FROM_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "get-date-from-datetime", 1);
-    public final static FunctionIdentifier TIME_FROM_UNIX_TIME_IN_MS = new FunctionIdentifier(
+    public static final FunctionIdentifier TIME_FROM_UNIX_TIME_IN_MS = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "time-from-unix-time-in-ms", 1);
-    public final static FunctionIdentifier TIME_FROM_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier TIME_FROM_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "get-time-from-datetime", 1);
-    public final static FunctionIdentifier DATETIME_FROM_UNIX_TIME_IN_MS = new FunctionIdentifier(
+    public static final FunctionIdentifier DATETIME_FROM_UNIX_TIME_IN_MS = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "datetime-from-unix-time-in-ms", 1);
-    public final static FunctionIdentifier DATETIME_FROM_UNIX_TIME_IN_SECS = new FunctionIdentifier(
+    public static final FunctionIdentifier DATETIME_FROM_UNIX_TIME_IN_SECS = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "datetime-from-unix-time-in-secs", 1);
-    public final static FunctionIdentifier DATETIME_FROM_DATE_TIME = new FunctionIdentifier(
+    public static final FunctionIdentifier DATETIME_FROM_DATE_TIME = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "datetime-from-date-time", 2);
-    public final static FunctionIdentifier CALENDAR_DURATION_FROM_DATETIME = new FunctionIdentifier(
+    public static final FunctionIdentifier CALENDAR_DURATION_FROM_DATETIME = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "calendar-duration-from-datetime", 2);
-    public final static FunctionIdentifier CALENDAR_DURATION_FROM_DATE = new FunctionIdentifier(
+    public static final FunctionIdentifier CALENDAR_DURATION_FROM_DATE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "calendar-duration-from-date", 2);
-    public final static FunctionIdentifier ADJUST_TIME_FOR_TIMEZONE = new FunctionIdentifier(
+    public static final FunctionIdentifier ADJUST_TIME_FOR_TIMEZONE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "adjust-time-for-timezone", 2);
-    public final static FunctionIdentifier ADJUST_DATETIME_FOR_TIMEZONE = new FunctionIdentifier(
+    public static final FunctionIdentifier ADJUST_DATETIME_FOR_TIMEZONE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "adjust-datetime-for-timezone", 2);
-    public final static FunctionIdentifier DAY_OF_WEEK = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier DAY_OF_WEEK = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "day-of-week");
-    public final static FunctionIdentifier PARSE_DATE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PARSE_DATE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "parse-date", 2);
-    public final static FunctionIdentifier PARSE_TIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PARSE_TIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "parse-time", 2);
-    public final static FunctionIdentifier PARSE_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PARSE_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "parse-datetime", 2);
-    public final static FunctionIdentifier PRINT_DATE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PRINT_DATE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "print-date", 2);
-    public final static FunctionIdentifier PRINT_TIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PRINT_TIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "print-time", 2);
-    public final static FunctionIdentifier PRINT_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+    public static final FunctionIdentifier PRINT_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "print-datetime", 2);
 
-    public final static FunctionIdentifier GET_POINT_X_COORDINATE_ACCESSOR = new FunctionIdentifier(
+    public static final FunctionIdentifier GET_POINT_X_COORDINATE_ACCESSOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "get-x", 1);
-    public final static FunctionIdentifier GET_POINT_Y_COORDINATE_ACCESSOR = new FunctionIdentifier(
+    public static final FunctionIdentifier GET_POINT_Y_COORDINATE_ACCESSOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "get-y", 1);
-    public final static FunctionIdentifier GET_CIRCLE_RADIUS_ACCESSOR = new FunctionIdentifier(
+    public static final FunctionIdentifier GET_CIRCLE_RADIUS_ACCESSOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "get-radius", 1);
-    public final static FunctionIdentifier GET_CIRCLE_CENTER_ACCESSOR = new FunctionIdentifier(
+    public static final FunctionIdentifier GET_CIRCLE_CENTER_ACCESSOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "get-center", 1);
-    public final static FunctionIdentifier GET_POINTS_LINE_RECTANGLE_POLYGON_ACCESSOR = new FunctionIdentifier(
+    public static final FunctionIdentifier GET_POINTS_LINE_RECTANGLE_POLYGON_ACCESSOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "get-points", 1);
 
     public static final FunctionIdentifier EQ = AlgebricksBuiltinFunctions.EQ;
@@ -722,6 +720,8 @@ public class AsterixBuiltinFunctions {
             FunctionIdentifier.VARARGS);
     public static final FunctionIdentifier META_KEY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "meta-key",
             FunctionIdentifier.VARARGS);
+    public static final FunctionIdentifier RESOLVE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "resolve",
+            FunctionIdentifier.VARARGS);
 
     public static IFunctionInfo getAsterixFunctionInfo(FunctionIdentifier fid) {
         return registeredFunctions.get(fid);
@@ -787,9 +787,9 @@ public class AsterixBuiltinFunctions {
 
         addFunction(FLOAT_CONSTRUCTOR, AFloatTypeComputer.INSTANCE, true);
         addPrivateFunction(FUZZY_EQ, BooleanFunctionTypeComputer.INSTANCE, true);
-        addPrivateFunction(GET_HANDLE, null, true); // TODO
+        addPrivateFunction(GET_HANDLE, null, true);
         addPrivateFunction(GET_ITEM, NonTaggedGetItemResultType.INSTANCE, true);
-        addPrivateFunction(GET_DATA, null, true); // TODO
+        addPrivateFunction(GET_DATA, null, true);
         addPrivateFunction(GRAM_TOKENS, OrderedListOfAStringTypeComputer.INSTANCE, true);
         addPrivateFunction(HASHED_GRAM_TOKENS, OrderedListOfAInt32TypeComputer.INSTANCE, true);
         addPrivateFunction(HASHED_WORD_TOKENS, OrderedListOfAInt32TypeComputer.INSTANCE, true);
@@ -801,8 +801,8 @@ public class AsterixBuiltinFunctions {
         addFunction(LEN, AInt64TypeComputer.INSTANCE, true);
         addFunction(LINE_CONSTRUCTOR, ALineTypeComputer.INSTANCE, true);
         addPrivateFunction(LISTIFY, OrderedListConstructorTypeComputer.INSTANCE, true);
-        addPrivateFunction(MAKE_FIELD_INDEX_HANDLE, null, true); // TODO
-        addPrivateFunction(MAKE_FIELD_NAME_HANDLE, null, true); // TODO
+        addPrivateFunction(MAKE_FIELD_INDEX_HANDLE, null, true);
+        addPrivateFunction(MAKE_FIELD_NAME_HANDLE, null, true);
         addFunction(NULL_CONSTRUCTOR, AMissingTypeComputer.INSTANCE, true);
 
         addPrivateFunction(NUMERIC_UNARY_MINUS, UnaryMinusTypeComputer.INSTANCE, true);
@@ -1044,6 +1044,7 @@ public class AsterixBuiltinFunctions {
         // meta() function
         addFunction(META, OpenARecordTypeComputer.INSTANCE, true);
         addPrivateFunction(META_KEY, AnyTypeComputer.INSTANCE, false);
+        addFunction(RESOLVE, AnyTypeComputer.INSTANCE, false);
 
         addPrivateFunction(COLLECTION_TO_SEQUENCE, CollectionToSequenceTypeComputer.INSTANCE, true);
 
@@ -1238,13 +1239,7 @@ public class AsterixBuiltinFunctions {
         return datasetFunctions.contains(getAsterixFunctionInfo(fi));
     }
 
-    /*
-    public static boolean isBuiltinCompilerFunction(FunctionIdentifier fi, boolean includePrivateFunctions) {
-        return builtinPublicFunctionsSet.keySet().contains(getAsterixFunctionInfo(fi));
-    }*/
-
     public static boolean isBuiltinCompilerFunction(FunctionSignature signature, boolean includePrivateFunctions) {
-
         FunctionIdentifier fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, signature.getName(),
                 signature.getArity());
         IFunctionInfo finfo = getAsterixFunctionInfo(fi);
@@ -1273,11 +1268,7 @@ public class AsterixBuiltinFunctions {
 
     public static boolean returnsUniqueValues(FunctionIdentifier fi) {
         Boolean ruv = builtinUnnestingFunctions.get(getAsterixFunctionInfo(fi));
-        if (ruv != null && ruv.booleanValue()) {
-            return true;
-        } else {
-            return false;
-        }
+        return ruv != null && ruv.booleanValue();
     }
 
     public static FunctionIdentifier getLocalAggregateFunction(FunctionIdentifier fi) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
index 714048e..4834269 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
@@ -48,8 +48,7 @@ public class CollectionMemberResultType extends AbstractResultTypeComputer {
         if (type.getTypeTag() == ATypeTag.ANY) {
             return BuiltinType.ANY;
         }
-        IAType itemType = ((AbstractCollectionType) type).getItemType();
-        return itemType;
+        return ((AbstractCollectionType) type).getItemType();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java
index 3e1955d..04d879f 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java
@@ -20,8 +20,10 @@
 package org.apache.asterix.om.typecomputer.impl;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.asterix.om.base.AString;
 import org.apache.asterix.om.constants.AsterixConstantValue;
@@ -52,29 +54,45 @@ public class OpenRecordConstructorResultType implements IResultTypeComputer {
          * if type has been top-down propagated, use the enforced type
          */
         ARecordType type = (ARecordType) TypeCastUtils.getRequiredType(f);
-        if (type != null)
+        if (type != null) {
             return type;
+        }
 
-        int n = 0;
         Iterator<Mutable<ILogicalExpression>> argIter = f.getArguments().iterator();
-        List<String> namesList = new ArrayList<String>();
-        List<IAType> typesList = new ArrayList<IAType>();
+        List<String> namesList = new ArrayList<>();
+        List<IAType> typesList = new ArrayList<>();
+        // The following set of names do not belong to the closed part,
+        // but are additional possible field names. For example, a field "foo" with type
+        // ANY cannot be in the closed part, but "foo" is a possible field name.
+        Set<String> allPossibleAdditionalFieldNames = new HashSet<>();
+        boolean canProvideAdditionFieldInfo = true;
+        boolean isOpen = false;
         while (argIter.hasNext()) {
             ILogicalExpression e1 = argIter.next().getValue();
             ILogicalExpression e2 = argIter.next().getValue();
             IAType t2 = (IAType) env.getType(e2);
-            if (e1.getExpressionTag() == LogicalExpressionTag.CONSTANT && t2 != null && TypeHelper.isClosed(t2)) {
+            String fieldName = null;
+            if (e1.getExpressionTag() == LogicalExpressionTag.CONSTANT) {
                 ConstantExpression nameExpr = (ConstantExpression) e1;
                 AsterixConstantValue acv = (AsterixConstantValue) nameExpr.getValue();
-                namesList.add(((AString) acv.getObject()).getStringValue());
+                fieldName = ((AString) acv.getObject()).getStringValue();
+            }
+            if (fieldName != null && t2 != null && TypeHelper.isClosed(t2)) {
+                namesList.add(fieldName);
                 typesList.add(t2);
-                n++;
+            } else {
+                if (canProvideAdditionFieldInfo && fieldName != null) {
+                    allPossibleAdditionalFieldNames.add(fieldName);
+                } else {
+                    canProvideAdditionFieldInfo = false;
+                }
+                isOpen = true;
             }
         }
-        String[] fieldNames = new String[n];
-        IAType[] fieldTypes = new IAType[n];
-        fieldNames = namesList.toArray(fieldNames);
-        fieldTypes = typesList.toArray(fieldTypes);
-        return new ARecordType(null, fieldNames, fieldTypes, true);
+        String[] fieldNames = namesList.toArray(new String[0]);
+        IAType[] fieldTypes = typesList.toArray(new IAType[0]);
+        return canProvideAdditionFieldInfo
+                ? new ARecordType(null, fieldNames, fieldTypes, isOpen, allPossibleAdditionalFieldNames)
+                : new ARecordType(null, fieldNames, fieldTypes, isOpen);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java
index a66976c..ebee611 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ScalarVersionOfAggregateResultType.java
@@ -45,11 +45,14 @@ public class ScalarVersionOfAggregateResultType extends AbstractResultTypeComput
 
     @Override
     protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
-        AbstractCollectionType act = (AbstractCollectionType) strippedInputTypes[0];
-        ATypeTag tag = act.getTypeTag();
+        ATypeTag tag = strippedInputTypes[0].getTypeTag();
         if (tag == ATypeTag.ANY) {
             return BuiltinType.ANY;
         }
+        if (tag != ATypeTag.ORDEREDLIST && tag != ATypeTag.UNORDEREDLIST) {
+            return strippedInputTypes[0];
+        }
+        AbstractCollectionType act = (AbstractCollectionType) strippedInputTypes[0];
         IAType t = act.getItemType();
         return AUnionType.createUnknownableType(t);
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
index dec3ea9..f2379ef 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.asterix.common.annotations.IRecordTypeAnnotation;
 import org.apache.asterix.common.exceptions.AsterixException;
@@ -49,9 +50,16 @@ public class ARecordType extends AbstractComplexType {
     private static final long serialVersionUID = 1L;
     private final String[] fieldNames;
     private final IAType[] fieldTypes;
-    private final Map<String, Integer> fieldNameToIndexMap = new HashMap<String, Integer>();
+    private final Map<String, Integer> fieldNameToIndexMap = new HashMap<>();
     private final boolean isOpen;
-    private final List<IRecordTypeAnnotation> annotations = new ArrayList<IRecordTypeAnnotation>();
+    private final transient List<IRecordTypeAnnotation> annotations = new ArrayList<>();
+    // The following set of names do not belong to the closed part,
+    // but are additional possible field names. For example, a field "foo" with type
+    // ANY cannot be in the closed part, but "foo" is a possible field name.
+    // This is used for resolve a field access with prefix path missing.
+    // If allPossibleAdditionalFieldNames is null, that means compiler does not know
+    // the bounded set of all possible additional field names.
+    private final Set<String> allPossibleAdditionalFieldNames;
 
     /**
      * @param typeName
@@ -64,6 +72,23 @@ public class ARecordType extends AbstractComplexType {
      *            whether the record is open
      */
     public ARecordType(String typeName, String[] fieldNames, IAType[] fieldTypes, boolean isOpen) {
+        this(typeName, fieldNames, fieldTypes, isOpen, null);
+    }
+
+    /**
+     * @param typeName
+     *            the name of the type
+     * @param fieldNames
+     *            the names of the closed fields
+     * @param fieldTypes
+     *            the types of the closed fields
+     * @param isOpen
+     *            whether the record is open
+     * @param allPossibleAdditionalFieldNames,
+     *            all possible additional field names.
+     */
+    public ARecordType(String typeName, String[] fieldNames, IAType[] fieldTypes, boolean isOpen,
+            Set<String> allPossibleAdditionalFieldNames) {
         super(typeName);
         this.fieldNames = fieldNames;
         this.fieldTypes = fieldTypes;
@@ -73,6 +98,22 @@ public class ARecordType extends AbstractComplexType {
         for (int index = 0; index < fieldNames.length; ++index) {
             fieldNameToIndexMap.put(fieldNames[index], index);
         }
+        this.allPossibleAdditionalFieldNames = allPossibleAdditionalFieldNames;
+    }
+
+    public boolean canContainField(String fieldName) {
+        if (this.isOpen && allPossibleAdditionalFieldNames == null) {
+            // An open record type without information on possible additional fields can potentially contain
+            // a field with any name.
+            return true;
+        }
+        if (isOpen) {
+            // An open record type with information on possible additional fields can determine whether
+            // a field can potentially be contained in a record.
+            return fieldNameToIndexMap.containsKey(fieldName) || allPossibleAdditionalFieldNames.contains(fieldName);
+        } else {
+            return fieldNameToIndexMap.containsKey(fieldName);
+        }
     }
 
     public String[] getFieldNames() {
@@ -248,7 +289,7 @@ public class ARecordType extends AbstractComplexType {
         for (int i = 0; i < fieldTypes.length; i++) {
             IAType fieldType = fieldTypes[i];
             if (fieldType.getTypeTag().isDerivedType() && (fieldType.getTypeName() == null)) {
-                AbstractComplexType nestedType = ((AbstractComplexType) fieldType);
+                AbstractComplexType nestedType = (AbstractComplexType) fieldType;
                 nestedType.setTypeName(getTypeName() + "_" + fieldNames[i]);
                 nestedType.generateNestedDerivedTypeNames();
             }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/SubplanOperator.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/SubplanOperator.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/SubplanOperator.java
index 9dcc402..b805761 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/SubplanOperator.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/SubplanOperator.java
@@ -24,7 +24,6 @@ import java.util.List;
 
 import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.commons.lang3.mutable.MutableObject;
-
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
@@ -109,7 +108,7 @@ public class SubplanOperator extends AbstractOperatorWithNestedPlans {
             }
         }
         return new PropagatingTypeEnvironment(ctx.getExpressionTypeComputer(), ctx.getMissableTypeComputer(),
-                ctx.getMetadataProvider(), TypePropagationPolicy.LEFT_OUTER, envPointers);
+                ctx.getMetadataProvider(), TypePropagationPolicy.ALL, envPointers);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
index e85c35c..647c9ee 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
@@ -143,7 +143,7 @@ public class LogicalOperatorPrettyPrintVisitor implements ILogicalOperatorVisito
     @Override
     public String visitNestedTupleSourceOperator(NestedTupleSourceOperator op, Integer indent) {
         StringBuilder buffer = new StringBuilder();
-        addIndent(buffer, indent).append("nested tuple source");
+        addIndent(buffer, indent).append("nested tuple source" + op.getDataSourceReference().getValue());
         return buffer.toString();
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/9e3f9bef/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/BroadcastPartitioningProperty.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/BroadcastPartitioningProperty.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/BroadcastPartitioningProperty.java
index 9d76c1b..bc6a45d 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/BroadcastPartitioningProperty.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/BroadcastPartitioningProperty.java
@@ -39,8 +39,9 @@ public class BroadcastPartitioningProperty implements IPartitioningProperty {
     }
 
     @Override
-    public void normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses, List<FunctionalDependency> fds) {
-        // do nothing
+    public IPartitioningProperty normalize(Map<LogicalVariable, EquivalenceClass> equivalenceClasses,
+            List<FunctionalDependency> fds) {
+        return this;
     }
 
     @Override