Till Westmann has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/2117
Change subject: [NO ISSUE] some plan printing improvements
......................................................................
[NO ISSUE] some plan printing improvements
Change-Id: Iea5a32a63e65636599dbc2a3674c1741d10e1d17
---
M
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
M
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java
M
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
M
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java
M
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
5 files changed, 159 insertions(+), 254 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/17/2117/1
diff --git
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index 8290446..3f09f97 100644
---
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -229,14 +229,7 @@
printPlanPrefix(output, "Logical plan");
if (rwQ != null || (statement != null && statement.getKind() ==
Statement.Kind.LOAD)) {
- AbstractLogicalOperatorPrettyPrintVisitor pvisitor;
- if
(output.config().getLpfmt().equals(SessionConfig.PlanFormat.JSON)) {
- pvisitor = new
LogicalOperatorPrettyPrintVisitorJson(output.out());
- } else {
- pvisitor = new
LogicalOperatorPrettyPrintVisitor(output.out());
-
- }
- PlanPrettyPrinter.printPlan(plan, pvisitor, 0);
+ PlanPrettyPrinter.printPlan(plan,
getPrettyPrintVisitor(output.config().getLpfmt(), output.out()), 0);
}
printPlanPostfix(output);
}
@@ -289,14 +282,8 @@
} else {
printPlanPrefix(output, "Optimized logical plan");
if (rwQ != null || (statement != null &&
statement.getKind() == Statement.Kind.LOAD)) {
- AbstractLogicalOperatorPrettyPrintVisitor pvisitor;
- if
(output.config().getLpfmt().equals(SessionConfig.PlanFormat.JSON)) {
- pvisitor = new
LogicalOperatorPrettyPrintVisitorJson(output.out());
-
- } else {
- pvisitor = new
LogicalOperatorPrettyPrintVisitor(output.out());
- }
- PlanPrettyPrinter.printPlan(plan, pvisitor, 0);
+ PlanPrettyPrinter.printPlan(plan,
+
getPrettyPrintVisitor(output.config().getLpfmt(), output.out()), 0);
}
printPlanPostfix(output);
}
@@ -377,6 +364,12 @@
return spec;
}
+ private AbstractLogicalOperatorPrettyPrintVisitor
getPrettyPrintVisitor(SessionConfig.PlanFormat planFormat,
+ PrintWriter out) {
+ return planFormat.equals(SessionConfig.PlanFormat.JSON) ? new
LogicalOperatorPrettyPrintVisitorJson(out)
+ : new LogicalOperatorPrettyPrintVisitor(out);
+ }
+
public void executeJobArray(IHyracksClientConnection hcc,
JobSpecification[] specs, PrintWriter out)
throws Exception {
for (JobSpecification spec : specs) {
diff --git
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java
index 140ba80..460f4d0 100644
---
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java
+++
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/AbstractLogicalOperatorPrettyPrintVisitor.java
@@ -84,6 +84,21 @@
}
}
+ protected AlgebricksAppendable addIndent(int level) throws
AlgebricksException {
+ for (int i = 0; i < level; ++i) {
+ buffer.append(' ');
+ }
+ return buffer;
+ }
+
+ public void printPlan(ILogicalPlan plan, int indent) throws
AlgebricksException {
+ for (Mutable<ILogicalOperator> root : plan.getRoots()) {
+ printOperator((AbstractLogicalOperator) root.getValue(), indent);
+ }
+ }
+
+ public abstract void printOperator(AbstractLogicalOperator op, int indent)
throws AlgebricksException;
+
public static void printPhysicalOperator(AbstractLogicalOperator op, int
indent, AlgebricksAppendable out)
throws AlgebricksException {
IPhysicalOperator pOp = op.getPhysicalOperator();
diff --git
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
index fe63b89..3e75c66 100644
---
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
+++
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
@@ -88,17 +88,10 @@
super(app);
}
- public static void printPlan(ILogicalPlan plan,
LogicalOperatorPrettyPrintVisitor pvisitor, int indent)
- throws AlgebricksException {
- for (Mutable<ILogicalOperator> root : plan.getRoots()) {
- printOperator((AbstractLogicalOperator) root.getValue(), pvisitor,
indent);
- }
- }
-
- public static void printOperator(AbstractLogicalOperator op,
LogicalOperatorPrettyPrintVisitor pvisitor, int indent)
- throws AlgebricksException {
- final AlgebricksAppendable out = pvisitor.get();
- op.accept(pvisitor, indent);
+ @Override
+ public void printOperator(AbstractLogicalOperator op, int indent) throws
AlgebricksException {
+ final AlgebricksAppendable out = this.get();
+ op.accept(this, indent);
IPhysicalOperator pOp = op.getPhysicalOperator();
if (pOp != null) {
@@ -110,7 +103,7 @@
}
for (Mutable<ILogicalOperator> i : op.getInputs()) {
- printOperator((AbstractLogicalOperator) i.getValue(), pvisitor,
indent + 2);
+ printOperator((AbstractLogicalOperator) i.getValue(), indent + 2);
}
}
@@ -155,8 +148,7 @@
@Override
public Void visitInnerJoinOperator(InnerJoinOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("join
(").append(op.getCondition().getValue().accept(exprVisitor, indent)).
- append(")");
+ addIndent(indent).append("join
(").append(op.getCondition().getValue().accept(exprVisitor,
indent)).append(")");
return null;
}
@@ -400,12 +392,11 @@
buffer.append(" partitioned by ");
pprintExprList(op.getPrimaryKeyExpressions(), indent);
if (op.getOperation() == Kind.UPSERT) {
- buffer.append(
- " out: ([record-before-upsert:" + op.getBeforeOpRecordVar()
- + ((op.getBeforeOpAdditionalNonFilteringVars() !=
null)
- ? (", additional-before-upsert: " +
op.getBeforeOpAdditionalNonFilteringVars())
- : "")
- + "]) ");
+ buffer.append(" out: ([record-before-upsert:" +
op.getBeforeOpRecordVar()
+ + ((op.getBeforeOpAdditionalNonFilteringVars() != null)
+ ? (", additional-before-upsert: " +
op.getBeforeOpAdditionalNonFilteringVars())
+ : "")
+ + "]) ");
}
if (op.isBulkload()) {
buffer.append(" [bulkload]");
@@ -464,13 +455,6 @@
return null;
}
- protected AlgebricksAppendable addIndent(int level) throws
AlgebricksException {
- for (int i = 0; i < level; ++i) {
- buffer.append(' ');
- }
- return buffer;
- }
-
protected void printNestedPlans(AbstractOperatorWithNestedPlans op,
Integer indent) throws AlgebricksException {
boolean first = true;
if (op.getNestedPlans().isEmpty()) {
@@ -485,7 +469,7 @@
} else {
addIndent(indent).append(" {\n");
}
- printPlan(p, this, indent + 10);
+ printPlan(p, indent + 10);
addIndent(indent).append(" }");
}
}
diff --git
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java
index fefb1e9..d01c627 100644
---
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java
+++
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitorJson.java
@@ -71,7 +71,6 @@
import
org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
import
org.apache.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
import
org.apache.hyracks.algebricks.core.algebra.operators.logical.WriteResultOperator;
-import
org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionVisitor;
public class LogicalOperatorPrettyPrintVisitorJson extends
AbstractLogicalOperatorPrettyPrintVisitor {
Map<AbstractLogicalOperator, String> operatorIdentity = new HashMap<>();
@@ -116,50 +115,44 @@
}
}
- public static void printPlanJson(ILogicalPlan plan,
LogicalOperatorPrettyPrintVisitorJson pvisitor, int indent)
- throws AlgebricksException {
- for (Mutable<ILogicalOperator> root : plan.getRoots()) {
- printOperatorJson((AbstractLogicalOperator) root.getValue(),
pvisitor, indent);
- }
- }
-
- public static void printOperatorJson(AbstractLogicalOperator op,
LogicalOperatorPrettyPrintVisitorJson pvisitor,
- int indent) throws AlgebricksException {
+ @Override
+ public void printOperator(AbstractLogicalOperator op, int indent) throws
AlgebricksException {
int currentIndent = indent;
- final AlgebricksAppendable out = pvisitor.get();
+ final AlgebricksAppendable out = get();
pad(out, currentIndent);
appendln(out, "{");
currentIndent++;
- op.accept(pvisitor, currentIndent);
+ op.accept(this, currentIndent);
appendln(out, ",");
pad(out, currentIndent);
- append(out, "\"operatorId\" : \"" +
pvisitor.idCounter.printOperatorId(op) + "\"");
+ append(out, "\"operatorId\": \"" + idCounter.printOperatorId(op) +
"\"");
IPhysicalOperator pOp = op.getPhysicalOperator();
if (pOp != null) {
appendln(out, ",");
pad(out, currentIndent);
- String pOperator = "\"physical-operator\":\"" + pOp.toString() +
"\"";
+ String pOperator = "\"physical-operator\": \"" + pOp.toString() +
"\"";
append(out, pOperator);
}
appendln(out, ",");
pad(out, currentIndent);
- append(out, "\"execution-mode\":\"" + op.getExecutionMode() + '"');
+ append(out, "\"execution-mode\": \"" + op.getExecutionMode() + '"');
if (!op.getInputs().isEmpty()) {
appendln(out, ",");
pad(out, currentIndent);
- appendln(out, "\"inputs\":[");
+ appendln(out, "\"inputs\": [");
boolean moreInputes = false;
for (Mutable<ILogicalOperator> k : op.getInputs()) {
if (moreInputes) {
append(out, ",");
}
- printOperatorJson((AbstractLogicalOperator) k.getValue(),
pvisitor, currentIndent + 4);
+ printOperator((AbstractLogicalOperator) k.getValue(),
currentIndent + 4);
moreInputes = true;
}
pad(out, currentIndent + 2);
appendln(out, "]");
+ } else {
+ out.append("\n");
}
- out.append("\n");
pad(out, currentIndent - 1);
appendln(out, "}");
}
@@ -167,30 +160,22 @@
public void variablePrintHelper(List<LogicalVariable> variables, Integer
indent) throws AlgebricksException {
if (!variables.isEmpty()) {
addIndent(0).append(",\n");
- addIndent(indent).append("\"variables\" :[");
- boolean first = true;
- for (LogicalVariable v : variables) {
- if (!first) {
- buffer.append(",");
- }
- buffer.append("\"" + str(v) + "\"");
- first = false;
- }
+ addIndent(indent).append("\"variables\": [");
+ appendVars(variables);
buffer.append("]");
}
}
@Override
public Void visitAggregateOperator(AggregateOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"aggregate\"");
+ addIndent(indent).append("\"operator\": \"aggregate\"");
variablePrintHelper(op.getVariables(), indent);
-
return null;
}
@Override
public Void visitRunningAggregateOperator(RunningAggregateOperator op,
Integer indent) throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"running-aggregate\"");
+ addIndent(indent).append("\"operator\": \"running-aggregate\"");
variablePrintHelper(op.getVariables(), indent);
if (!op.getExpressions().isEmpty()) {
addIndent(0).append(",\n");
@@ -201,31 +186,31 @@
@Override
public Void visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op,
Integer indent) throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"empty-tuple-source\"");
+ addIndent(indent).append("\"operator\": \"empty-tuple-source\"");
return null;
}
@Override
public Void visitGroupByOperator(GroupByOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"group-by\"");
+ addIndent(indent).append("\"operator\": \"group-by\"");
if (op.isGroupAll()) {
buffer.append(",\n");
- addIndent(indent).append("\"option\":\"all\"");
+ addIndent(indent).append("\"option\": \"all\"");
}
if (!op.getGroupByList().isEmpty()) {
buffer.append(",\n");
- addIndent(indent).append("\"group-by-list\":");
+ addIndent(indent).append("\"group-by-list\": ");
pprintVeList(op.getGroupByList(), indent);
}
if (!op.getDecorList().isEmpty()) {
buffer.append(",\n");
- addIndent(indent).append("\"decor-list\":");
+ addIndent(indent).append("\"decor-list\": ");
pprintVeList(op.getDecorList(), indent);
}
if (!op.getNestedPlans().isEmpty()) {
buffer.append(",\n");
- addIndent(indent).append("\"subplan\":");
+ addIndent(indent).append("\"subplan\": ");
printNestedPlans(op, indent);
}
return null;
@@ -233,7 +218,7 @@
@Override
public Void visitDistinctOperator(DistinctOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"distinct\"");
+ addIndent(indent).append("\"operator\": \"distinct\"");
if (!op.getExpressions().isEmpty()) {
addIndent(0).append(",\n");
pprintExprList(op.getExpressions(), indent);
@@ -243,39 +228,37 @@
@Override
public Void visitInnerJoinOperator(InnerJoinOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"join\",\n");
- addIndent(indent)
- .append("\"condition\":" + "\"" +
op.getCondition().getValue().accept(exprVisitor, indent) + "\"");
+ addIndent(indent).append("\"operator\": \"join\",\n");
+ addIndent(indent).append("\"condition\": \"" +
op.getCondition().getValue().accept(exprVisitor, indent) + "\"");
return null;
}
@Override
public Void visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Integer
indent) throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"left-outer-join\",\n");
- addIndent(indent)
- .append("\"condition\":" + "\"" +
op.getCondition().getValue().accept(exprVisitor, indent) + "\"");
+ addIndent(indent).append("\"operator\": \"left-outer-join\",\n");
+ addIndent(indent).append("\"condition\": \"" +
op.getCondition().getValue().accept(exprVisitor, indent) + "\"");
return null;
}
@Override
public Void visitNestedTupleSourceOperator(NestedTupleSourceOperator op,
Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"nested-tuple-source\"");
+ addIndent(indent).append("\"operator\": \"nested-tuple-source\"");
return null;
}
@Override
public Void visitOrderOperator(OrderOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"order\"");
+ addIndent(indent).append("\"operator\": \"order\"");
for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p :
op.getOrderExpressions()) {
buffer.append(",\n");
if (op.getTopK() != -1) {
- addIndent(indent).append("\"topK\":\"" + op.getTopK() +
"\",\n");
+ addIndent(indent).append("\"topK\": \"" + op.getTopK() +
"\",\n");
}
String fst = getOrderString(p.first);
- addIndent(indent).append("\"first\":" + fst + ",\n");
- addIndent(indent)
- .append("\"second\":\"" +
p.second.getValue().accept(exprVisitor, indent).replace('"', ' ') + "\"");
+ addIndent(indent).append("\"first\": " + fst + ",\n");
+ addIndent(indent).append(
+ "\"second\": \"" + p.second.getValue().accept(exprVisitor,
indent).replace('"', ' ') + "\"");
}
return null;
}
@@ -293,7 +276,7 @@
@Override
public Void visitAssignOperator(AssignOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"assign\"");
+ addIndent(indent).append("\"operator\": \"assign\"");
variablePrintHelper(op.getVariables(), indent);
if (!op.getExpressions().isEmpty()) {
addIndent(0).append(",\n");
@@ -304,7 +287,7 @@
@Override
public Void visitWriteOperator(WriteOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"write\"");
+ addIndent(indent).append("\"operator\": \"write\"");
if (!op.getExpressions().isEmpty()) {
addIndent(0).append(",\n");
pprintExprList(op.getExpressions(), indent);
@@ -314,7 +297,7 @@
@Override
public Void visitDistributeResultOperator(DistributeResultOperator op,
Integer indent) throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"distribute-result\"");
+ addIndent(indent).append("\"operator\": \"distribute-result\"");
if (!op.getExpressions().isEmpty()) {
addIndent(0).append(",\n");
pprintExprList(op.getExpressions(), indent);
@@ -324,10 +307,10 @@
@Override
public Void visitWriteResultOperator(WriteResultOperator op, Integer
indent) throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"load\",\n");
+ addIndent(indent).append("\"operator\": \"load\",\n");
addIndent(indent).append(str(op.getDataSource())).append("\"from\":")
.append(op.getPayloadExpression().getValue().accept(exprVisitor, indent) +
",\n");
- addIndent(indent).append("\"partitioned-by\":{");
+ addIndent(indent).append("\"partitioned-by\": {");
pprintExprList(op.getKeyExpressions(), indent);
addIndent(indent).append("}");
return null;
@@ -335,15 +318,15 @@
@Override
public Void visitSelectOperator(SelectOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"select\",\n");
- addIndent(indent).append("\"expressions\":\""
+ addIndent(indent).append("\"operator\": \"select\",\n");
+ addIndent(indent).append("\"expressions\": \""
+ op.getCondition().getValue().accept(exprVisitor,
indent).replace('"', ' ') + "\"");
return null;
}
@Override
public Void visitProjectOperator(ProjectOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"project\"");
+ addIndent(indent).append("\"operator\": \"project\"");
variablePrintHelper(op.getVariables(), indent);
return null;
}
@@ -351,7 +334,7 @@
@Override
public Void visitSubplanOperator(SubplanOperator op, Integer indent)
throws AlgebricksException {
if (!op.getNestedPlans().isEmpty()) {
- addIndent(indent).append("\"subplan\":");
+ addIndent(indent).append("\"subplan\": ");
printNestedPlans(op, indent);
}
return null;
@@ -359,69 +342,52 @@
@Override
public Void visitUnionOperator(UnionAllOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"union\"");
+ addIndent(indent).append("\"operator\": \"union\"");
for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> v :
op.getVariableMappings()) {
buffer.append(",\n");
- addIndent(indent)
- .append("\"values\":[" + "\"" + v.first + "\"," + "\"" +
v.second + "\"," + "\"" + v.third + "\"]");
+ addIndent(indent).append(
+ "\"values\": [" + "\"" + v.first + "\"," + "\"" + v.second
+ "\"," + "\"" + v.third + "\"]");
}
return null;
}
@Override
public Void visitIntersectOperator(IntersectOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"intersect\",\n");
+ addIndent(indent).append("\"operator\": \"intersect\",\n");
- addIndent(indent).append("\"output-variables\":[");
- for (int i = 0; i < op.getOutputVars().size(); i++) {
- if (i > 0) {
- buffer.append(", ");
- }
- buffer.append("\"" + str(op.getOutputVars().get(i)) + "\"");
- }
+ addIndent(indent).append("\"output-variables\": [");
+ appendVars(op.getOutputVars());
buffer.append("],");
- addIndent(indent).append("\"input_variables\":[");
- for (int i = 0; i < op.getNumInput(); i++) {
- if (i > 0) {
- buffer.append(",\n");
- }
- buffer.append("[");
- for (int j = 0; j < op.getInputVariables(i).size(); j++) {
- if (j > 0) {
- buffer.append(", ");
- }
- buffer.append("\"" + str(op.getInputVariables(i).get(j)) +
"\"");
- }
- buffer.append(']');
- }
+ addIndent(indent).append("\"input_variables\": [");
+ appendVars(op.getOutputVars());
buffer.append("]");
return null;
}
@Override
public Void visitUnnestOperator(UnnestOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"unnest\"");
+ addIndent(indent).append("\"operator\": \"unnest\"");
variablePrintHelper(op.getVariables(), indent);
if (op.getPositionalVariable() != null) {
buffer.append(",\n");
- addIndent(indent).append("\"position\":\"" +
op.getPositionalVariable() + "\"");
+ addIndent(indent).append("\"position\": \"" +
op.getPositionalVariable() + "\"");
}
buffer.append(",\n");
- addIndent(indent).append("\"expressions\":\""
+ addIndent(indent).append("\"expressions\": \""
+ op.getExpressionRef().getValue().accept(exprVisitor,
indent).replace('"', ' ') + "\"");
return null;
}
@Override
public Void visitLeftOuterUnnestOperator(LeftOuterUnnestOperator op,
Integer indent) throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"outer-unnest\",\n");
- addIndent(indent).append("\"variables\":[\"" + op.getVariable() +
"\"]");
+ addIndent(indent).append("\"operator\": \"outer-unnest\",\n");
+ addIndent(indent).append("\"variables\": [\"" + op.getVariable() +
"\"]");
if (op.getPositionalVariable() != null) {
buffer.append(",\n");
- addIndent(indent).append("\"position\":" +
op.getPositionalVariable());
+ addIndent(indent).append("\"position\": " +
op.getPositionalVariable());
}
buffer.append(",\n");
- addIndent(indent).append("\"expressions\":\""
+ addIndent(indent).append("\"expressions\": \""
+ op.getExpressionRef().getValue().accept(exprVisitor,
indent).replace('"', ' ') + "\"");
return null;
}
@@ -439,10 +405,10 @@
private Void printAbstractUnnestMapOperator(AbstractUnnestMapOperator op,
Integer indent, String opSignature)
throws AlgebricksException {
- AlgebricksAppendable plan = addIndent(indent).append("\"operator\":\""
+ opSignature + "\"");
+ AlgebricksAppendable plan = addIndent(indent).append("\"operator\":
\"" + opSignature + "\"");
variablePrintHelper(op.getVariables(), indent);
buffer.append(",\n");
- addIndent(indent).append("\"expressions\":\""
+ addIndent(indent).append("\"expressions\": \""
+ op.getExpressionRef().getValue().accept(exprVisitor,
indent).replace('"', ' ') + "\"");
appendFilterInformation(plan, op.getMinFilterVars(),
op.getMaxFilterVars(), indent);
return null;
@@ -450,24 +416,17 @@
@Override
public Void visitDataScanOperator(DataSourceScanOperator op, Integer
indent) throws AlgebricksException {
- AlgebricksAppendable plan =
addIndent(indent).append("\"operator\":\"data-scan\"");
+ AlgebricksAppendable plan = addIndent(indent).append("\"operator\":
\"data-scan\"");
if (!op.getProjectVariables().isEmpty()) {
addIndent(0).append(",\n");
- addIndent(indent).append("\"project-variables\":[");
- boolean first = true;
- for (LogicalVariable v : op.getProjectVariables()) {
- if (!first) {
- buffer.append(",");
- }
- buffer.append("\"" + str(v) + "\"");
- first = false;
- }
+ addIndent(indent).append("\"project-variables\": [");
+ appendVars(op.getProjectVariables());
buffer.append("]");
}
variablePrintHelper(op.getVariables(), indent);
if (op.getDataSource() != null) {
addIndent(0).append(",\n");
- addIndent(indent).append("\"data-source\":\"" + op.getDataSource()
+ "\"");
+ addIndent(indent).append("\"data-source\": \"" +
op.getDataSource() + "\"");
}
appendFilterInformation(plan, op.getMinFilterVars(),
op.getMaxFilterVars(), indent);
return null;
@@ -478,19 +437,12 @@
if (minFilterVars != null || maxFilterVars != null) {
plan.append(",\n");
addIndent(indent);
- plan.append("\"with-filter-on\":{");
+ plan.append("\"with-filter-on\": {");
}
if (minFilterVars != null) {
buffer.append("\n");
- addIndent(indent).append("\"min\":[");
- boolean first = true;
- for (LogicalVariable v : minFilterVars) {
- if (!first) {
- buffer.append(",");
- }
- buffer.append("\"" + str(v) + "\"");
- first = false;
- }
+ addIndent(indent).append("\"min\": [");
+ appendVars(minFilterVars);
buffer.append("]");
}
if (minFilterVars != null && maxFilterVars != null) {
@@ -498,15 +450,8 @@
}
if (maxFilterVars != null) {
buffer.append("\n");
- addIndent(indent).append("\"max\":[");
- boolean first = true;
- for (LogicalVariable v : maxFilterVars) {
- if (!first) {
- buffer.append(",");
- }
- buffer.append("\"" + str(v) + "\"");
- first = false;
- }
+ addIndent(indent).append("\"max\": [");
+ appendVars(maxFilterVars);
buffer.append("]");
}
if (minFilterVars != null || maxFilterVars != null) {
@@ -516,51 +461,48 @@
return null;
}
+ private void appendVars(List<LogicalVariable> minFilterVars) throws
AlgebricksException {
+ boolean first = true;
+ for (LogicalVariable v : minFilterVars) {
+ if (!first) {
+ buffer.append(",");
+ }
+ buffer.append("\"" + str(v) + "\"");
+ first = false;
+ }
+ }
+
@Override
public Void visitLimitOperator(LimitOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"limit\",\n");
- addIndent(indent).append("\"value\":\"" +
op.getMaxObjects().getValue().accept(exprVisitor, indent) + "\"");
+ addIndent(indent).append("\"operator\": \"limit\",\n");
+ addIndent(indent).append("\"value\": \"" +
op.getMaxObjects().getValue().accept(exprVisitor, indent) + "\"");
ILogicalExpression offset = op.getOffset().getValue();
if (offset != null) {
buffer.append(",\n");
- addIndent(indent).append("\"offset\":\"" +
offset.accept(exprVisitor, indent) + "\"");
+ addIndent(indent).append("\"offset\": \"" +
offset.accept(exprVisitor, indent) + "\"");
}
return null;
}
@Override
public Void visitExchangeOperator(ExchangeOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"exchange\"");
+ addIndent(indent).append("\"operator\": \"exchange\"");
return null;
}
@Override
public Void visitScriptOperator(ScriptOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"script\"");
+ addIndent(indent).append("\"operator\": \"script\"");
if (!op.getInputVariables().isEmpty()) {
addIndent(0).append(",\n");
- addIndent(indent).append("\"in\":[");
- boolean first = true;
- for (LogicalVariable v : op.getInputVariables()) {
- if (!first) {
- buffer.append(",");
- }
- buffer.append("\"" + str(v) + "\"");
- first = false;
- }
+ addIndent(indent).append("\"in\": [");
+ appendVars(op.getInputVariables());
buffer.append("]");
}
if (!op.getOutputVariables().isEmpty()) {
addIndent(0).append(",\n");
- addIndent(indent).append("\"out\":[");
- boolean first = true;
- for (LogicalVariable v : op.getOutputVariables()) {
- if (!first) {
- buffer.append(",");
- }
- buffer.append("\"" + str(v) + "\"");
- first = false;
- }
+ addIndent(indent).append("\"out\": [");
+ appendVars(op.getOutputVariables());
buffer.append("]");
}
return null;
@@ -568,54 +510,54 @@
@Override
public Void visitReplicateOperator(ReplicateOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"replicate\"");
+ addIndent(indent).append("\"operator\": \"replicate\"");
return null;
}
@Override
public Void visitSplitOperator(SplitOperator op, Integer indent) throws
AlgebricksException {
Mutable<ILogicalExpression> branchingExpression =
op.getBranchingExpression();
- addIndent(indent).append("\"operator\":\"split\",\n");
+ addIndent(indent).append("\"operator\": \"split\",\n");
addIndent(indent).append("\"" +
branchingExpression.getValue().accept(exprVisitor, indent) + "\"");
return null;
}
@Override
public Void visitMaterializeOperator(MaterializeOperator op, Integer
indent) throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"materialize\"");
+ addIndent(indent).append("\"operator\": \"materialize\"");
return null;
}
@Override
public Void visitInsertDeleteUpsertOperator(InsertDeleteUpsertOperator op,
Integer indent)
throws AlgebricksException {
- String header = "\"operator\":\"" +
getIndexOpString(op.getOperation()) + "\",\n";
+ String header = "\"operator\": \"" +
getIndexOpString(op.getOperation()) + "\",\n";
addIndent(indent).append(header);
- addIndent(indent).append(str("\"data-source\":\"" + op.getDataSource()
+ "\",\n"));
- addIndent(indent).append("\"from-record\":\"")
+ addIndent(indent).append(str("\"data-source\": \"" +
op.getDataSource() + "\",\n"));
+ addIndent(indent).append("\"from-record\": \"")
.append(op.getPayloadExpression().getValue().accept(exprVisitor, indent) +
"\"");
if (op.getAdditionalNonFilteringExpressions() != null) {
- buffer.append(",\n\"meta\":\"");
+ buffer.append(",\n\"meta\": \"");
pprintExprList(op.getAdditionalNonFilteringExpressions(), 0);
buffer.append("\"");
}
buffer.append(",\n");
- addIndent(indent).append("\"partitioned-by\":{");
+ addIndent(indent).append("\"partitioned-by\": {");
pprintExprList(op.getPrimaryKeyExpressions(), 0);
buffer.append("}");
if (op.getOperation() == Kind.UPSERT) {
- addIndent(indent).append(",\n\"out\":{\n");
- addIndent(indent).append("\"record-before-upsert\":\"" +
op.getBeforeOpRecordVar() + "\"");
+ addIndent(indent).append(",\n\"out\": {\n");
+ addIndent(indent).append("\"record-before-upsert\": \"" +
op.getBeforeOpRecordVar() + "\"");
if (op.getBeforeOpAdditionalNonFilteringVars() != null) {
buffer.append(",\n");
addIndent(indent)
- .append("\"additional-before-upsert\":\"" +
op.getBeforeOpAdditionalNonFilteringVars() + "\"");
+ .append("\"additional-before-upsert\": \"" +
op.getBeforeOpAdditionalNonFilteringVars() + "\"");
}
addIndent(indent).append("}");
}
if (op.isBulkload()) {
buffer.append(",\n");
- addIndent(indent).append("\"bulkload\":\"true\"");
+ addIndent(indent).append("\"bulkload\": true");
}
return null;
}
@@ -624,17 +566,17 @@
public Void
visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op,
Integer indent)
throws AlgebricksException {
String header = getIndexOpString(op.getOperation());
- addIndent(indent).append("\"operator\":\"" + header + "\",\n");
- addIndent(indent).append("\"index\":\"" + op.getIndexName() + "\",\n");
-
addIndent(indent).append("\"on\":\"").append(str(op.getDataSourceIndex().getDataSource())
+ "\",\n");
- addIndent(indent).append("\"from\":{");
+ addIndent(indent).append("\"operator\": \"" + header + "\",\n");
+ addIndent(indent).append("\"index\": \"" + op.getIndexName() +
"\",\n");
+ addIndent(indent).append("\"on\":
\"").append(str(op.getDataSourceIndex().getDataSource()) + "\",\n");
+ addIndent(indent).append("\"from\": {");
if (op.getOperation() == Kind.UPSERT) {
- addIndent(indent).append("[\"replace\":\"");
+ addIndent(indent).append("[\"replace\": \"");
pprintExprList(op.getPrevSecondaryKeyExprs(), 0);
buffer.append("\",\n");
- addIndent(indent).append("\"with\":\"");
+ addIndent(indent).append("\"with\": \"");
pprintExprList(op.getSecondaryKeyExpressions(), 0);
buffer.append("\"}");
} else {
@@ -644,7 +586,7 @@
addIndent(indent).append("}");
if (op.isBulkload()) {
buffer.append(",\n");
- buffer.append("\"bulkload\":\"true\"");
+ buffer.append("\"bulkload\": true");
}
return null;
}
@@ -663,7 +605,7 @@
@Override
public Void visitTokenizeOperator(TokenizeOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"tokenize\"");
+ addIndent(indent).append("\"operator\": \"tokenize\"");
variablePrintHelper(op.getTokenizeVars(), indent);
if (!op.getSecondaryKeyExpressions().isEmpty()) {
addIndent(0).append(",\n");
@@ -674,21 +616,14 @@
@Override
public Void visitSinkOperator(SinkOperator op, Integer indent) throws
AlgebricksException {
- addIndent(indent).append("\"operator\":\"sink\"");
+ addIndent(indent).append("\"operator\": \"sink\"");
return null;
}
@Override
public Void visitDelegateOperator(DelegateOperator op, Integer indent)
throws AlgebricksException {
- addIndent(indent).append("\"operator\":\"" + op.toString() + "\"");
+ addIndent(indent).append("\"operator\": \"" + op.toString() + "\"");
return null;
- }
-
- protected AlgebricksAppendable addIndent(int level) throws
AlgebricksException {
- for (int i = 0; i < level; ++i) {
- buffer.append(' ');
- }
- return buffer;
}
protected void printNestedPlans(AbstractOperatorWithNestedPlans op,
Integer indent) throws AlgebricksException {
@@ -699,19 +634,17 @@
if (!first) {
buffer.append(",");
}
- printPlanJson(p, this, indent + 4);
+ printPlan(p, indent + 4);
first = false;
-
}
addIndent(indent).append("]");
idCounter.previousPrefix();
}
- //Done--Look for exprRef
protected void pprintExprList(List<Mutable<ILogicalExpression>>
expressions, Integer indent)
throws AlgebricksException {
addIndent(indent);
- buffer.append("\"expressions\":\"");
+ buffer.append("\"expressions\": \"");
boolean first = true;
for (Mutable<ILogicalExpression> exprRef : expressions) {
if (first) {
@@ -727,22 +660,21 @@
protected void pprintVeList(List<Pair<LogicalVariable,
Mutable<ILogicalExpression>>> vePairList, Integer indent)
throws AlgebricksException {
buffer.append("[");
- boolean fst = true;
+ boolean first = true;
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> ve :
vePairList) {
- if (fst) {
- fst = false;
+ if (first) {
+ first = false;
} else {
buffer.append(",");
}
if (ve.first != null) {
- buffer.append("{\"variable\":\"" +
ve.first.toString().replace('"', ' ') + "\"," + "\"expression\":\""
+ buffer.append("{\"variable\": \"" +
ve.first.toString().replace('"', ' ') + "\"," + "\"expression\": \""
+ ve.second.toString().replace('"', ' ') + "\"}");
} else {
- buffer.append("{\"expression\":\"" +
ve.second.getValue().accept(exprVisitor, indent).replace('"', ' ')
+ buffer.append("{\"expression\": \"" +
ve.second.getValue().accept(exprVisitor, indent).replace('"', ' ')
+ "\"}");
}
}
buffer.append("]");
}
-
}
diff --git
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
index cf99d3b..63e2e8f 100644
---
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
+++
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
@@ -23,37 +23,18 @@
import
org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
public class PlanPrettyPrinter {
- @FunctionalInterface
- public interface print<T1, T2, T3> {
- void apply(T1 arg1, T2 arg2, T3 arg3) throws AlgebricksException;
+ public static void printOperator(AbstractLogicalOperator op,
AbstractLogicalOperatorPrettyPrintVisitor pvisitor, int indent)
+ throws AlgebricksException {
+ pvisitor.printOperator(op, indent);
}
- public static void printOperator(AbstractLogicalOperator op,
LogicalOperatorPrettyPrintVisitor pvisitor,
- int indent) throws AlgebricksException {
- print<AbstractLogicalOperator, LogicalOperatorPrettyPrintVisitor,
Integer> printOperator =
- LogicalOperatorPrettyPrintVisitor::printOperator;
- printOperator.apply(op, pvisitor, indent);
- }
-
- public static <T extends AbstractLogicalOperatorPrettyPrintVisitor> void
printPlan(ILogicalPlan plan,
- T pvisitor, int indent) throws AlgebricksException {
- if
(pvisitor.getClass().equals(LogicalOperatorPrettyPrintVisitor.class)) {
- print<ILogicalPlan, LogicalOperatorPrettyPrintVisitor, Integer>
printPlan =
- LogicalOperatorPrettyPrintVisitor::printPlan;
- printPlan.apply(plan,(LogicalOperatorPrettyPrintVisitor) pvisitor,
indent);
- }
- else if
(pvisitor.getClass().equals(LogicalOperatorPrettyPrintVisitorJson.class)) {
- print<ILogicalPlan, LogicalOperatorPrettyPrintVisitorJson,
Integer> printPlan =
- LogicalOperatorPrettyPrintVisitorJson::printPlanJson;
- printPlan.apply(plan,
(LogicalOperatorPrettyPrintVisitorJson)pvisitor, indent);
- }
-
+ public static void printPlan(ILogicalPlan plan,
AbstractLogicalOperatorPrettyPrintVisitor pvisitor, int indent)
+ throws AlgebricksException {
+ pvisitor.printPlan(plan, indent);
}
public static void printPhysicalOps(ILogicalPlan plan,
AlgebricksAppendable out, int indent)
throws AlgebricksException {
- print<ILogicalPlan, AlgebricksAppendable, Integer> printOperator =
- AbstractLogicalOperatorPrettyPrintVisitor::printPhysicalOps;
- printOperator.apply(plan, out, indent);
+ AbstractLogicalOperatorPrettyPrintVisitor.printPhysicalOps(plan, out,
indent);
}
}
--
To view, visit https://asterix-gerrit.ics.uci.edu/2117
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea5a32a63e65636599dbc2a3674c1741d10e1d17
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <[email protected]>