pretty print more expressions
get the LogicalOperatorPrettyPrintVisitor from the IOptimizationContext
move supporting methods in LogicalOperatorPrettyPrintVisitor to the end
diff --git a/algebricks/algebricks-compiler/src/main/java/edu/uci/ics/hyracks/algebricks/compiler/api/HeuristicCompilerFactoryBuilder.java b/algebricks/algebricks-compiler/src/main/java/edu/uci/ics/hyracks/algebricks/compiler/api/HeuristicCompilerFactoryBuilder.java
index 39587b9..26dc343 100644
--- a/algebricks/algebricks-compiler/src/main/java/edu/uci/ics/hyracks/algebricks/compiler/api/HeuristicCompilerFactoryBuilder.java
+++ b/algebricks/algebricks-compiler/src/main/java/edu/uci/ics/hyracks/algebricks/compiler/api/HeuristicCompilerFactoryBuilder.java
@@ -22,6 +22,7 @@
import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IMergeAggregationExpressionFactory;
import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.INullableTypeComputer;
import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor;
import edu.uci.ics.hyracks.algebricks.core.config.AlgebricksConfig;
import edu.uci.ics.hyracks.algebricks.core.jobgen.impl.JobGenContext;
import edu.uci.ics.hyracks.algebricks.core.jobgen.impl.PlanCompiler;
@@ -47,9 +48,10 @@
IMergeAggregationExpressionFactory mergeAggregationExpressionFactory,
IExpressionTypeComputer expressionTypeComputer, INullableTypeComputer nullableTypeComputer,
PhysicalOptimizationConfig physicalOptimizationConfig) {
+ LogicalOperatorPrettyPrintVisitor prettyPrintVisitor = new LogicalOperatorPrettyPrintVisitor();
return new AlgebricksOptimizationContext(varCounter, expressionEvalSizeComputer,
mergeAggregationExpressionFactory, expressionTypeComputer, nullableTypeComputer,
- physicalOptimizationConfig);
+ physicalOptimizationConfig, prettyPrintVisitor);
}
}
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/base/IOptimizationContext.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/base/IOptimizationContext.java
index 8537702..9b9273a 100644
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/base/IOptimizationContext.java
+++ b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/base/IOptimizationContext.java
@@ -22,6 +22,7 @@
import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IMergeAggregationExpressionFactory;
import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment;
import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.FunctionalDependency;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector;
import edu.uci.ics.hyracks.algebricks.core.algebra.typing.ITypingContext;
@@ -84,4 +85,6 @@
public abstract void computeAndSetTypeEnvironmentForOperator(ILogicalOperator op) throws AlgebricksException;
public abstract void updatePrimaryKeys(Map<LogicalVariable, LogicalVariable> mappedVars);
+
+ public abstract LogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor();
}
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
index d364d87..5a2619d 100644
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
+++ b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
@@ -96,8 +96,11 @@
@Override
public String visitGroupByOperator(GroupByOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("group by (").append(op.gByListToString()).append(") decor (")
- .append(op.decorListToString()).append(") {");
+ addIndent(buffer, indent).append("group by (");
+ pprintVeList(buffer, op.getGroupByList(), indent);
+ buffer.append(") decor (");
+ pprintVeList(buffer, op.getDecorList(), indent);
+ buffer.append(") {");
printNestedPlans(op, indent, buffer);
return buffer.toString();
}
@@ -112,16 +115,18 @@
}
@Override
- public String visitInnerJoinOperator(InnerJoinOperator op, Integer indent) {
+ public String visitInnerJoinOperator(InnerJoinOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("join (").append(op.getCondition().getValue()).append(")");
+ addIndent(buffer, indent).append("join (").append(op.getCondition().getValue().accept(exprVisitor, indent))
+ .append(")");
return buffer.toString();
}
@Override
- public String visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Integer indent) {
+ public String visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("left outer join (").append(op.getCondition().getValue()).append(")");
+ addIndent(buffer, indent).append("left outer join (")
+ .append(op.getCondition().getValue().accept(exprVisitor, indent)).append(")");
return buffer.toString();
}
@@ -133,7 +138,7 @@
}
@Override
- public String visitOrderOperator(OrderOperator op, Integer indent) {
+ public String visitOrderOperator(OrderOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
addIndent(buffer, indent).append("order ");
for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p : op.getOrderExpressions()) {
@@ -151,7 +156,7 @@
fst = p.first.getExpressionRef().toString();
}
}
- buffer.append("(" + fst + ", " + p.second.getValue() + ") ");
+ buffer.append("(" + fst + ", " + p.second.getValue().accept(exprVisitor, indent) + ") ");
}
return buffer.toString();
}
@@ -165,31 +170,35 @@
}
@Override
- public String visitWriteOperator(WriteOperator op, Integer indent) {
+ public String visitWriteOperator(WriteOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("write ").append(op.getExpressions());
+ addIndent(buffer, indent).append("write ");
+ pprintExprList(op.getExpressions(), buffer, indent);
return buffer.toString();
}
@Override
- public String visitDistributeResultOperator(DistributeResultOperator op, Integer indent) {
+ public String visitDistributeResultOperator(DistributeResultOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("distribute result ").append(op.getExpressions());
+ addIndent(buffer, indent).append("distribute result ");
+ pprintExprList(op.getExpressions(), buffer, indent);
return buffer.toString();
}
@Override
- public String visitWriteResultOperator(WriteResultOperator op, Integer indent) {
+ public String visitWriteResultOperator(WriteResultOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
addIndent(buffer, indent).append("load ").append(op.getDataSource()).append(" from ")
- .append(op.getPayloadExpression()).append(" partitioned by ").append(op.getKeyExpressions().toString());
+ .append(op.getPayloadExpression().getValue().accept(exprVisitor, indent)).append(" partitioned by ");
+ pprintExprList(op.getKeyExpressions(), buffer, indent);
return buffer.toString();
}
@Override
- public String visitSelectOperator(SelectOperator op, Integer indent) {
+ public String visitSelectOperator(SelectOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("select " + "(" + op.getCondition().getValue() + ")");
+ addIndent(buffer, indent).append("select (").append(op.getCondition().getValue().accept(exprVisitor, indent))
+ .append(")");
return buffer.toString();
}
@@ -201,9 +210,12 @@
}
@Override
- public String visitPartitioningSplitOperator(PartitioningSplitOperator op, Integer indent) {
+ public String visitPartitioningSplitOperator(PartitioningSplitOperator op, Integer indent)
+ throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("partitioning-split (" + op.getExpressions() + ")");
+ addIndent(buffer, indent).append("partitioning-split (");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ buffer.append(")");
return buffer.toString();
}
@@ -226,20 +238,22 @@
}
@Override
- public String visitUnnestOperator(UnnestOperator op, Integer indent) {
+ public String visitUnnestOperator(UnnestOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
addIndent(buffer, indent).append("unnest " + op.getVariable());
if (op.getPositionalVariable() != null) {
buffer.append(" at " + op.getPositionalVariable());
}
- buffer.append(" <- " + op.getExpressionRef().getValue());
+ buffer.append(" <- " + op.getExpressionRef().getValue().accept(exprVisitor, indent));
return buffer.toString();
}
@Override
- public String visitUnnestMapOperator(UnnestMapOperator op, Integer indent) {
+ public String visitUnnestMapOperator(UnnestMapOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("unnest-map " + op.getVariables() + " <- " + op.getExpressionRef().getValue());
+ addIndent(buffer, indent).append(
+ "unnest-map " + op.getVariables() + " <- "
+ + op.getExpressionRef().getValue().accept(exprVisitor, indent));
return buffer.toString();
}
@@ -252,12 +266,12 @@
}
@Override
- public String visitLimitOperator(LimitOperator op, Integer indent) {
+ public String visitLimitOperator(LimitOperator op, Integer indent) throws AlgebricksException {
StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("limit " + op.getMaxObjects().getValue());
+ addIndent(buffer, indent).append("limit " + op.getMaxObjects().getValue().accept(exprVisitor, indent));
ILogicalExpression offset = op.getOffset().getValue();
if (offset != null) {
- buffer.append(", " + offset);
+ buffer.append(", " + offset.accept(exprVisitor, indent));
}
return buffer.toString();
}
@@ -269,6 +283,57 @@
return buffer.toString();
}
+ @Override
+ public String visitScriptOperator(ScriptOperator op, Integer indent) {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append(
+ "script (in: " + op.getInputVariables() + ") (out: " + op.getOutputVariables() + ")");
+ return buffer.toString();
+ }
+
+ @Override
+ public String visitReplicateOperator(ReplicateOperator op, Integer indent) throws AlgebricksException {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("replicate ");
+ return buffer.toString();
+ }
+
+ @Override
+ public String visitInsertDeleteOperator(InsertDeleteOperator op, Integer indent) throws AlgebricksException {
+ StringBuilder buffer = new StringBuilder();
+ String header = op.getOperation() == Kind.INSERT ? "insert into " : "delete from ";
+ addIndent(buffer, indent).append(header).append(op.getDataSource()).append(" from ")
+ .append(op.getPayloadExpression().getValue().accept(exprVisitor, indent)).append(" partitioned by ");
+ pprintExprList(op.getPrimaryKeyExpressions(), buffer, indent);
+ return buffer.toString();
+ }
+
+ @Override
+ public String visitIndexInsertDeleteOperator(IndexInsertDeleteOperator op, Integer indent)
+ throws AlgebricksException {
+ StringBuilder buffer = new StringBuilder();
+ String header = op.getOperation() == Kind.INSERT ? "insert into " : "delete from ";
+ addIndent(buffer, indent).append(header).append(op.getDataSourceIndex()).append(" from ");
+ pprintExprList(op.getSecondaryKeyExpressions(), buffer, indent);
+ buffer.append(" ");
+ pprintExprList(op.getPrimaryKeyExpressions(), buffer, indent);
+ return buffer.toString();
+ }
+
+ @Override
+ public String visitSinkOperator(SinkOperator op, Integer indent) throws AlgebricksException {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("sink");
+ return buffer.toString();
+ }
+
+ @Override
+ public String visitExtensionOperator(ExtensionOperator op, Integer indent) throws AlgebricksException {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append(op.toString());
+ return buffer.toString();
+ }
+
protected static final StringBuilder addIndent(StringBuilder buffer, int level) {
for (int i = 0; i < level; ++i) {
buffer.append(' ');
@@ -276,7 +341,7 @@
return buffer;
}
- private void printNestedPlans(AbstractOperatorWithNestedPlans op, Integer indent, StringBuilder buffer)
+ protected void printNestedPlans(AbstractOperatorWithNestedPlans op, Integer indent, StringBuilder buffer)
throws AlgebricksException {
boolean first = true;
if (op.getNestedPlans().isEmpty()) {
@@ -297,15 +362,8 @@
}
}
- @Override
- public String visitScriptOperator(ScriptOperator op, Integer indent) {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append(
- "script (in: " + op.getInputVariables() + ") (out: " + op.getOutputVariables() + ")");
- return buffer.toString();
- }
-
- private void pprintExprList(List<Mutable<ILogicalExpression>> expressions, StringBuilder buffer, Integer indent) throws AlgebricksException {
+ protected void pprintExprList(List<Mutable<ILogicalExpression>> expressions, StringBuilder buffer, Integer indent)
+ throws AlgebricksException {
buffer.append("[");
boolean first = true;
for (Mutable<ILogicalExpression> exprRef : expressions) {
@@ -319,46 +377,23 @@
buffer.append("]");
}
- @Override
- public String visitReplicateOperator(ReplicateOperator op, Integer indent) throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("replicate ");
- return buffer.toString();
- }
-
- @Override
- public String visitInsertDeleteOperator(InsertDeleteOperator op, Integer indent) throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- String header = op.getOperation() == Kind.INSERT ? "insert into " : "delete from ";
- addIndent(buffer, indent).append(header).append(op.getDataSource()).append(" from ")
- .append(op.getPayloadExpression()).append(" partitioned by ")
- .append(op.getPrimaryKeyExpressions().toString());
- return buffer.toString();
- }
-
- @Override
- public String visitIndexInsertDeleteOperator(IndexInsertDeleteOperator op, Integer indent)
- throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- String header = op.getOperation() == Kind.INSERT ? "insert into " : "delete from ";
- addIndent(buffer, indent).append(header).append(op.getDataSourceIndex()).append(" from ")
- .append(op.getSecondaryKeyExpressions().toString()).append(" ")
- .append(op.getPrimaryKeyExpressions().toString());
- return buffer.toString();
- }
-
- @Override
- public String visitSinkOperator(SinkOperator op, Integer indent) throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("sink");
- return buffer.toString();
- }
-
- @Override
- public String visitExtensionOperator(ExtensionOperator op, Integer indent) throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append(op.toString());
- return buffer.toString();
+ protected void pprintVeList(StringBuilder sb, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> vePairList,
+ Integer indent) throws AlgebricksException {
+ sb.append("[");
+ boolean fst = true;
+ for (Pair<LogicalVariable, Mutable<ILogicalExpression>> ve : vePairList) {
+ if (fst) {
+ fst = false;
+ } else {
+ sb.append("; ");
+ }
+ if (ve.first != null) {
+ sb.append(ve.first + " := " + ve.second);
+ } else {
+ sb.append(ve.second.getValue().accept(exprVisitor, indent));
+ }
+ }
+ sb.append("]");
}
}
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java
index 77d8d40..974685f 100644
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java
+++ b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java
@@ -32,6 +32,7 @@
import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment;
import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.FunctionalDependency;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector;
@@ -72,17 +73,19 @@
protected final Map<ILogicalOperator, ILogicalPropertiesVector> logicalProps = new HashMap<ILogicalOperator, ILogicalPropertiesVector>();
private final IExpressionTypeComputer expressionTypeComputer;
private final INullableTypeComputer nullableTypeComputer;
+ private final LogicalOperatorPrettyPrintVisitor prettyPrintVisitor;
public AlgebricksOptimizationContext(int varCounter, IExpressionEvalSizeComputer expressionEvalSizeComputer,
IMergeAggregationExpressionFactory mergeAggregationExpressionFactory,
IExpressionTypeComputer expressionTypeComputer, INullableTypeComputer nullableTypeComputer,
- PhysicalOptimizationConfig physicalOptimizationConfig) {
+ PhysicalOptimizationConfig physicalOptimizationConfig, LogicalOperatorPrettyPrintVisitor prettyPrintVisitor) {
this.varCounter = varCounter;
this.expressionEvalSizeComputer = expressionEvalSizeComputer;
this.mergeAggregationExpressionFactory = mergeAggregationExpressionFactory;
this.expressionTypeComputer = expressionTypeComputer;
this.nullableTypeComputer = nullableTypeComputer;
this.physicalOptimizationConfig = physicalOptimizationConfig;
+ this.prettyPrintVisitor = prettyPrintVisitor;
}
public int getVarCounter() {
@@ -280,4 +283,9 @@
me.setValue(new FunctionalDependency(hd, tl));
}
}
+
+ @Override
+ public LogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor() {
+ return prettyPrintVisitor;
+ }
}
\ No newline at end of file
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
index f684c8a..9035ca5 100644
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
+++ b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
@@ -54,7 +54,6 @@
private List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> logicalRewrites;
private List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> physicalRewrites;
private ILogicalPlan plan;
- private LogicalOperatorPrettyPrintVisitor ppvisitor = new LogicalOperatorPrettyPrintVisitor();
public HeuristicOptimizer(ILogicalPlan plan,
List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> logicalRewrites,
@@ -75,13 +74,13 @@
}
StringBuilder sb = new StringBuilder();
- PlanPrettyPrinter.printPlan(plan, sb, ppvisitor, 0);
+ PlanPrettyPrinter.printPlan(plan, sb, context.getPrettyPrintVisitor(), 0);
AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Logical Plan:\n" + sb.toString());
runOptimizationSets(plan, logicalRewrites);
computeSchemaBottomUpForPlan(plan);
runPhysicalOptimizations(plan, physicalRewrites);
StringBuilder sb2 = new StringBuilder();
- PlanPrettyPrinter.printPlan(plan, sb2, ppvisitor, 0);
+ PlanPrettyPrinter.printPlan(plan, sb2, context.getPrettyPrintVisitor(), 0);
AlgebricksConfig.ALGEBRICKS_LOGGER.info("Optimized Plan:\n" + sb2.toString());
}