asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject incubator-asterixdb git commit: ASTERIXDB-1382: add examples for SQL++ group-by visitors.
Date Fri, 08 Apr 2016 00:34:19 GMT
Repository: incubator-asterixdb
Updated Branches:
  refs/heads/master d3d24af45 -> bce00de83


ASTERIXDB-1382: add examples for SQL++ group-by visitors.

Change-Id: I4c125e286bd53126685a0d91a1f4526ebccf9335
Reviewed-on: https://asterix-gerrit.ics.uci.edu/790
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>


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

Branch: refs/heads/master
Commit: bce00de839d8446666e41de2958e1494a63efdde
Parents: d3d24af
Author: Yingyi Bu <yingyi@couchbase.com>
Authored: Thu Apr 7 13:43:56 2016 -0700
Committer: Yingyi Bu <buyingyi@gmail.com>
Committed: Thu Apr 7 17:25:44 2016 -0700

----------------------------------------------------------------------
 .../group-by/sugar-02/sugar-02.3.query.sqlpp    |  2 +-
 .../visitor/SqlppGroupBySugarVisitor.java       | 32 ++++++++++++++++++--
 .../rewrites/visitor/SqlppGroupByVisitor.java   | 32 ++++++++++++++++++++
 3 files changed, 63 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/bce00de8/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-02/sugar-02.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-02/sugar-02.3.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-02/sugar-02.3.query.sqlpp
index e9c3326..e315533 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-02/sugar-02.3.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-02/sugar-02.3.query.sqlpp
@@ -23,5 +23,5 @@ FROM Employee e
     JOIN Incentive i ON e.job_category = i.job_category
     JOIN SuperStars s ON e.id = s.id
 GROUP BY e.department_id AS deptId
-SELECT deptId as deptId, coll_sum(e.salary + i.bonus) AS star_cost;
+SELECT deptId as deptId, SUM(e.salary + i.bonus) AS star_cost;
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/bce00de8/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 ae47264..be9c697 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
@@ -50,8 +50,35 @@ import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
 import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppExpressionScopingVisitor;
 
 /**
- * An AST pre-processor to rewrite group-by sugar queries.
+ * An AST pre-processor to rewrite group-by sugar queries, which does the following transformations:
+ * 1. Rewrite the argument expression of an aggregation function into a subquery if the argument
+ * expression is not a subquery;
+ * 2. Turn a SQL-92 aggregate function into a SQL++ core aggregate function when performing
1.
  */
+
+// For example, this visitor turns the following query
+//
+// FROM Employee e
+// JOIN Incentive i ON e.job_category = i.job_category
+// JOIN SuperStars s ON e.id = s.id
+// GROUP BY e.department_id AS deptId
+// GROUP AS eis(e AS e, i AS i, s AS s)
+// SELECT deptId as deptId, SUM(e.salary + i.bonus) AS star_cost;
+//
+// into the following core-version query:
+//
+// FROM Employee e
+// JOIN Incentive i ON e.job_category = i.job_category
+// JOIN SuperStars s ON e.id = s.id
+// GROUP BY e.department_id AS deptId
+// GROUP AS eis(e AS e, i AS i, s AS s)
+// SELECT ELEMENT {
+//          'deptId': deptId,
+//          'star_cost': coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus)
)
+// };
+//
+// where SUM(e.salary + i.bonus) is turned into coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary
+ p.i.bonus) ).
+
 public class SqlppGroupBySugarVisitor extends AbstractSqlppExpressionScopingVisitor {
 
     private final Expression groupVar;
@@ -77,7 +104,8 @@ public class SqlppGroupBySugarVisitor extends AbstractSqlppExpressionScopingVisi
             newExprList.add(newExpr.accept(this, arg));
         }
         if (rewritten) {
-            // Rewrites the SQL-92 function name to core functions.
+            // Rewrites the SQL-92 function name to core functions,
+            // e.g., SUM --> coll_sum
             callExpr.setFunctionSignature(FunctionMapUtil.sql92ToCoreAggregateFunction(signature));
         }
         callExpr.setExprList(newExprList);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/bce00de8/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 c9e7a6e..16e967c 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
@@ -45,6 +45,38 @@ import org.apache.hyracks.algebricks.common.utils.Pair;
  * A pre-processor that adds the group variable as well as its group field
  * list into the AST. It will also invoke SQL group-by aggregation sugar rewritings.
  */
+// This visitor rewrites non-core SQL++ group-by queries into their SQL++ core version
+// queries. For example, for the non-core query in
+// asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-01/sugar-01.3.query.sqlpp,
+//
+// FROM Employee e
+// JOIN Incentive i ON e.job_category = i.job_category
+// JOIN SuperStars s ON e.id = s.id
+// GROUP BY e.department_id AS deptId
+// SELECT deptId as deptId, SUM(e.salary + i.bonus) AS star_cost;
+//
+// this visitor transforms it into the core version in
+// asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-01/sugar-01.3.query.sqlpp,
+//
+// FROM Employee e
+// JOIN Incentive i ON e.job_category = i.job_category
+// JOIN SuperStars s ON e.id = s.id
+// GROUP BY e.department_id AS deptId
+// GROUP AS eis(e AS e, i AS i, s AS s)
+// SELECT ELEMENT {
+//  'deptId': deptId,
+//  'star_cost': coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) )
+// };
+/**
+ * The transformation include three things:
+ * 1. Add a group variable as well as its definition, e.g., GROUP AS eis(e AS e, i AS i,
s AS s);
+ * 2. Rewrite the argument expression of an aggregation function into a subquery if the argument
+ * expression is not a subquery;
+ * 3. Turn a SQL-92 aggregate function into a SQL++ core aggregate function when performing
2, e.g.,
+ * SUM(e.salary + i.bonus) becomes
+ * coll_sum( (FROM eis AS p SELECT ELEMENT p.e.salary + p.i.bonus) ).
+ */
+
 public class SqlppGroupByVisitor extends AbstractSqlppExpressionScopingVisitor {
 
     public SqlppGroupByVisitor(LangRewritingContext context) {


Mime
View raw message