asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [11/11] asterixdb git commit: Support implicit variable name and column name.
Date Fri, 01 Jul 2016 19:41:19 GMT
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 <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@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 <yingyi@couchbase.com>
Authored: Fri Jul 1 10:07:37 2016 -0700
Committer: Yingyi Bu <buyingyi@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;
+


Mime
View raw message