asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yingyi Bu (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: ASTERIXDB-1382: add examples for SQL++ group-by visitors.
Date Fri, 08 Apr 2016 00:25:45 GMT
Yingyi Bu has submitted this change and it was merged.

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


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>
---
M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/sugar-02/sugar-02.3.query.sqlpp
M asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
M asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
3 files changed, 63 insertions(+), 3 deletions(-)

Approvals:
  Till Westmann: Looks good to me, approved
  Jenkins: Verified



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 @@
     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;
 
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.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 @@
             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);
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 @@
  * 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) {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/790
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4c125e286bd53126685a0d91a1f4526ebccf9335
Gerrit-PatchSet: 5
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Yingyi Bu <buyingyi@gmail.com>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>
Gerrit-Reviewer: Yingyi Bu <buyingyi@gmail.com>

Mime
View raw message