add toString() to debug the SQL++ compiler
Change-Id: I32cf6b5c3be0211c10b1e379d19a6014350fc798
Reviewed-on: https://asterix-gerrit.ics.uci.edu/799
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
index c7d48b6..44a40c4 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
@@ -65,4 +65,9 @@
public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
return visitor.visit(this, arg);
}
+
+ @Override
+ public String toString() {
+ return "call " + String.valueOf(functionSignature);
+ }
}
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java
index 2517add..e23c799 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java
@@ -49,4 +49,8 @@
return visitor.visit(this, arg);
}
+ @Override
+ public String toString() {
+ return String.valueOf(expr) + "." + ident.toString();
+ }
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java
index 802869d..da6c512 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.lang.common.base.Clause;
@@ -48,4 +49,9 @@
public List<FromTerm> getFromTerms() {
return fromTerms;
}
+
+ @Override
+ public String toString() {
+ return fromTerms.stream().map(String::valueOf).collect(Collectors.joining(", "));
+ }
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
index 5e8cd9c..8a756c7 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
@@ -82,4 +82,8 @@
return posVar != null;
}
+ @Override
+ public String toString() {
+ return String.valueOf(leftExpr) + " AS " + String.valueOf(leftVar);
+ }
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java
index 6ca9b71..f73ec1e 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java
@@ -76,4 +76,9 @@
public boolean exprStar() {
return exprStar;
}
+
+ @Override
+ public String toString() {
+ return star ? "*" : (String.valueOf(expr) + (exprStar ? ".*" : (hasName() ? " as " + getName() : "")));
+ }
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java
index c6b4e24..42c8b29 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java
@@ -66,4 +66,9 @@
return distinct;
}
+ @Override
+ public String toString() {
+ return "select " + (distinct ? "distinct " : "")
+ + (selectElement() ? "element " + String.valueOf(selectElement) : String.valueOf(selectRegular));
+ }
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java
index e13506a..14efd0f 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java
@@ -50,4 +50,9 @@
public void setExpression(Expression expr) {
this.expr = expr;
}
+
+ @Override
+ public String toString() {
+ return String.valueOf(expr);
+ }
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java
index e8a14ea..4703e01 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java
@@ -20,6 +20,7 @@
package org.apache.asterix.lang.sqlpp.clause;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.lang.common.base.Clause;
@@ -47,4 +48,9 @@
public List<Projection> getProjections() {
return projections;
}
+
+ @Override
+ public String toString() {
+ return projections.stream().map(String::valueOf).collect(Collectors.joining(", "));
+ }
}
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 be9c697..6db1ea3 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
@@ -135,8 +135,7 @@
// Construct the select expression.
SelectBlock selectBlock = new SelectBlock(selectClause, fromClause, null, null, null, null, null);
SelectSetOperation selectSetOperation = new SelectSetOperation(new SetOperationInput(selectBlock, null), null);
- SelectExpression selectExpression = new SelectExpression(null, selectSetOperation, null, null, false);
- selectExpression.setSubquery(true);
+ SelectExpression selectExpression = new SelectExpression(null, selectSetOperation, null, null, true);
// replace variable expressions with field access
Map<VariableExpr, Expression> varExprMap = new HashMap<>();