Till Westmann has submitted this change and it was merged. Change subject: [NO ISSUE] some plan printing improvements ......................................................................
[NO ISSUE] some plan printing improvements Change-Id: Iea5a32a63e65636599dbc2a3674c1741d10e1d17 Reviewed-on: https://asterix-gerrit.ics.uci.edu/2117 Tested-by: Jenkins <[email protected]> Contrib: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> --- 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/operators/logical/AbstractLogicalOperator.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 6 files changed, 161 insertions(+), 250 deletions(-) Approvals: Anon. E. Moose #1000171: No violations found Jenkins: Verified; No violations found; Verified Murtadha Hubail: Looks good to me, approved Objections: Jenkins: Violations found 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 f7ecefc..1257a61 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 @@ -230,14 +230,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); } @@ -290,14 +283,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); } @@ -379,6 +366,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/operators/logical/AbstractLogicalOperator.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/AbstractLogicalOperator.java index 8b38a2b..4686f32 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/AbstractLogicalOperator.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/AbstractLogicalOperator.java @@ -19,7 +19,7 @@ package org.apache.hyracks.algebricks.core.algebra.operators.logical; import java.util.ArrayList; -import java.util.IdentityHashMap; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -63,7 +63,7 @@ private AbstractLogicalOperator.ExecutionMode mode = AbstractLogicalOperator.ExecutionMode.UNPARTITIONED; protected IPhysicalOperator physicalOperator; - private final Map<String, Object> annotations = new IdentityHashMap<String, Object>(); + private final Map<String, Object> annotations = new HashMap<>(); private boolean bJobGenEnabled = true; protected final List<Mutable<ILogicalOperator>> inputs; 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..4283198 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,40 +342,29 @@ @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\":["); + 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(']'); + appendVars(op.getInputVariables(i)); } buffer.append("]"); return null; @@ -400,28 +372,28 @@ @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 +411,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 +422,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 +443,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 +456,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 +467,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 +516,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 +572,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 +592,7 @@ addIndent(indent).append("}"); if (op.isBulkload()) { buffer.append(",\n"); - buffer.append("\"bulkload\":\"true\""); + buffer.append("\"bulkload\": true"); } return null; } @@ -663,7 +611,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 +622,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 +640,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 +666,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..67640c5 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, LogicalOperatorPrettyPrintVisitor pvisitor, + public static void printOperator(AbstractLogicalOperator op, AbstractLogicalOperatorPrettyPrintVisitor pvisitor, int indent) throws AlgebricksException { - print<AbstractLogicalOperator, LogicalOperatorPrettyPrintVisitor, Integer> printOperator = - LogicalOperatorPrettyPrintVisitor::printOperator; - printOperator.apply(op, pvisitor, indent); + pvisitor.printOperator(op, 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: merged Gerrit-Change-Id: Iea5a32a63e65636599dbc2a3674c1741d10e1d17 Gerrit-PatchSet: 9 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Till Westmann <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Dmitry Lychagin <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Murtadha Hubail <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]>
