Till Westmann has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/1004
Change subject: some pretty printing refactoring
......................................................................
some pretty printing refactoring
- use Appendable instead of PrintWriter and StringBuilder for plan printing
- only log plans in the optimizer if the log-level requires it
- change param to indent output JSON from INDENT to PRETTY
Change-Id: Ied0203adc51e9710690ace74fe1e152eb7a716e8
---
M
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/SessionConfig.java
M
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
M asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.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/PlanPrettyPrinter.java
M
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
6 files changed, 426 insertions(+), 265 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/04/1004/1
diff --git
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/SessionConfig.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/SessionConfig.java
index c09b424..5b28848 100644
---
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/SessionConfig.java
+++
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/SessionConfig.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.api.common;
+import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
@@ -103,7 +104,7 @@
public static final String FORMAT_QUOTE_RECORD = "quote-record";
public interface ResultDecorator {
- PrintWriter print(PrintWriter pw);
+ Appendable append(Appendable app) throws IOException;
}
// Standard execution flags.
@@ -193,12 +194,12 @@
return this.fmt;
}
- public PrintWriter resultPrefix(PrintWriter pw) {
- return this.preResultDecorator != null ?
this.preResultDecorator.print(pw) : pw;
+ public Appendable resultPrefix(Appendable app) throws IOException {
+ return this.preResultDecorator != null ?
this.preResultDecorator.append(app) : app;
};
- public PrintWriter resultPostfix(PrintWriter pw) {
- return this.postResultDecorator != null ?
this.postResultDecorator.print(pw) : pw;
+ public Appendable resultPostfix(Appendable app) throws IOException {
+ return this.postResultDecorator != null ?
this.postResultDecorator.append(app) : app;
};
/**
diff --git
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
index 8fa09a4..baa3c05 100644
---
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
+++
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
@@ -66,7 +66,7 @@
STATEMENT("statement"),
FORMAT("format"),
// Asterix
- INDENT("indent");
+ PRETTY("pretty");
private final String str;
@@ -244,23 +244,23 @@
* output-format based on the Accept: header and other servlet parameters.
*/
private static SessionConfig createSessionConfig(HttpServletRequest
request, PrintWriter resultWriter) {
- SessionConfig.ResultDecorator resultPrefix = (PrintWriter pw) -> {
- pw.print("\t\"");
- pw.print(ResultFields.RESULTS.str());
- pw.print("\": ");
- return pw;
+ SessionConfig.ResultDecorator resultPrefix = (Appendable app) -> {
+ app.append("\t\"");
+ app.append(ResultFields.RESULTS.str());
+ app.append("\": ");
+ return app;
};
- SessionConfig.ResultDecorator resultPostfix = (PrintWriter pw) -> {
- pw.print("\t,\n");
- return pw;
+ SessionConfig.ResultDecorator resultPostfix = (Appendable app) -> {
+ app.append("\t,\n");
+ return app;
};
String formatstr =
request.getParameter(Parameter.FORMAT.str()).toLowerCase();
SessionConfig.OutputFormat format = getFormat(formatstr);
SessionConfig sessionConfig = new SessionConfig(resultWriter, format,
resultPrefix, resultPostfix);
sessionConfig.set(SessionConfig.FORMAT_WRAPPER_ARRAY, true);
- boolean indentJson =
Boolean.parseBoolean(request.getParameter(Parameter.INDENT.str()));
+ boolean indentJson =
Boolean.parseBoolean(request.getParameter(Parameter.PRETTY.str()));
sessionConfig.set(SessionConfig.FORMAT_INDENT_JSON, indentJson);
sessionConfig.set(SessionConfig.FORMAT_QUOTE_RECORD,
format != SessionConfig.OutputFormat.CLEAN_JSON && format !=
SessionConfig.OutputFormat.LOSSLESS_JSON);
diff --git
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java
index 73dd706..ec9e2d0 100644
---
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java
+++
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/result/ResultUtils.java
@@ -104,7 +104,11 @@
conf.out().println("<pre>");
}
- conf.resultPrefix(conf.out());
+ try {
+ conf.resultPrefix(conf.out());
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ }
if (conf.is(SessionConfig.FORMAT_WRAPPER_ARRAY)) {
conf.out().print("[ ");
@@ -178,7 +182,11 @@
conf.out().println(" ]");
}
- conf.resultPostfix(conf.out());
+ try {
+ conf.resultPostfix(conf.out());
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ }
if (conf.is(SessionConfig.FORMAT_HTML)) {
conf.out().println("</pre>");
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 f961bd9..f0d3c1d 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
@@ -18,6 +18,7 @@
*/
package org.apache.hyracks.algebricks.core.algebra.prettyprint;
+import java.io.IOException;
import java.util.List;
import org.apache.commons.lang3.mutable.Mutable;
@@ -79,231 +80,322 @@
this.exprVisitor = exprVisitor;
}
+ CharSequence str(Object o) {
+ return String.valueOf(o);
+ }
+
@Override
public String visitAggregateOperator(AggregateOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("aggregate
").append(op.getVariables()).append(" <- ");
- pprintExprList(op.getExpressions(), buffer, indent);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("aggregate
").append(str(op.getVariables())).append(" <- ");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitRunningAggregateOperator(RunningAggregateOperator op,
Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("running-aggregate
").append(op.getVariables()).append(" <- ");
- pprintExprList(op.getExpressions(), buffer, indent);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("running-aggregate
").append(str(op.getVariables())).append(" <- ");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
- public String visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op,
Integer indent) {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("empty-tuple-source");
- return buffer.toString();
+ public String visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op,
Integer indent)
+ throws AlgebricksException {
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("empty-tuple-source");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitGroupByOperator(GroupByOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- 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();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ 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();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitDistinctOperator(DistinctOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("distinct " + "(");
- pprintExprList(op.getExpressions(), buffer, indent);
- buffer.append(")");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("distinct " + "(");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ buffer.append(")");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitInnerJoinOperator(InnerJoinOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("join
(").append(op.getCondition().getValue().accept(exprVisitor, indent))
- .append(")");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("join
(").append(op.getCondition().getValue().accept(exprVisitor, indent))
+ .append(")");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Integer
indent) throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("left outer join (")
- .append(op.getCondition().getValue().accept(exprVisitor,
indent)).append(")");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("left outer join (")
+ .append(op.getCondition().getValue().accept(exprVisitor,
indent)).append(")");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
- public String visitNestedTupleSourceOperator(NestedTupleSourceOperator op,
Integer indent) {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("nested tuple source");
- return buffer.toString();
+ public String visitNestedTupleSourceOperator(NestedTupleSourceOperator op,
Integer indent)
+ throws AlgebricksException {
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("nested tuple source");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
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()) {
- String fst;
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("order ");
+ for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p :
op.getOrderExpressions()) {
+ String fst;
- if (op.getTopK() != -1) {
- buffer.append("(topK: " + op.getTopK() + ") ");
+ if (op.getTopK() != -1) {
+ buffer.append("(topK: " + op.getTopK() + ") ");
+ }
+
+ switch (p.first.getKind()) {
+ case ASC: {
+ fst = "ASC";
+ break;
+ }
+ case DESC: {
+ fst = "DESC";
+ break;
+ }
+ default: {
+ fst = p.first.getExpressionRef().toString();
+ }
+ }
+ buffer.append("(" + fst + ", " +
p.second.getValue().accept(exprVisitor, indent) + ") ");
+
}
-
- switch (p.first.getKind()) {
- case ASC: {
- fst = "ASC";
- break;
- }
- case DESC: {
- fst = "DESC";
- break;
- }
- default: {
- fst = p.first.getExpressionRef().toString();
- }
- }
- buffer.append("(" + fst + ", " +
p.second.getValue().accept(exprVisitor, indent) + ") ");
-
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- return buffer.toString();
}
@Override
public String visitAssignOperator(AssignOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("assign
").append(op.getVariables()).append(" <- ");
- pprintExprList(op.getExpressions(), buffer, indent);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("assign
").append(str(op.getVariables())).append(" <- ");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitWriteOperator(WriteOperator op, Integer indent) throws
AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("write ");
- pprintExprList(op.getExpressions(), buffer, indent);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("write ");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitDistributeResultOperator(DistributeResultOperator op,
Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("distribute result ");
- pprintExprList(op.getExpressions(), buffer, indent);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("distribute result ");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
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().getValue().accept(exprVisitor,
indent)).append(" partitioned by ");
- pprintExprList(op.getKeyExpressions(), buffer, indent);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("load
").append(str(op.getDataSource())).append(" from ")
+
.append(op.getPayloadExpression().getValue().accept(exprVisitor, indent))
+ .append(" partitioned by ");
+ pprintExprList(op.getKeyExpressions(), buffer, indent);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitSelectOperator(SelectOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("select
(").append(op.getCondition().getValue().accept(exprVisitor, indent))
- .append(")");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("select (")
+ .append(op.getCondition().getValue().accept(exprVisitor,
indent)).append(")");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
- public String visitProjectOperator(ProjectOperator op, Integer indent) {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("project " + "(" + op.getVariables()
+ ")");
- return buffer.toString();
+ public String visitProjectOperator(ProjectOperator op, Integer indent)
throws AlgebricksException {
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("project " + "(" +
op.getVariables() + ")");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitPartitioningSplitOperator(PartitioningSplitOperator op,
Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("partitioning-split (");
- pprintExprList(op.getExpressions(), buffer, indent);
- buffer.append(")");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("partitioning-split (");
+ pprintExprList(op.getExpressions(), buffer, indent);
+ buffer.append(")");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitSubplanOperator(SubplanOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("subplan {");
- printNestedPlans(op, indent, buffer);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("subplan {");
+ printNestedPlans(op, indent, buffer);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
- public String visitUnionOperator(UnionAllOperator op, Integer indent) {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("union");
- for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> v :
op.getVariableMappings()) {
- buffer.append(" (" + v.first + ", " + v.second + ", " + v.third +
")");
+ public String visitUnionOperator(UnionAllOperator op, Integer indent)
throws AlgebricksException {
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("union");
+ for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> v :
op.getVariableMappings()) {
+ buffer.append(" (" + v.first + ", " + v.second + ", " +
v.third + ")");
+ }
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- return buffer.toString();
}
@Override
public String visitIntersectOperator(IntersectOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder builder = new StringBuilder();
- addIndent(builder, indent).append("intersect (");
+ try {
+ StringBuilder builder = new StringBuilder();
+ addIndent(builder, indent).append("intersect (");
- builder.append('[');
- for (int i = 0; i < op.getOutputVars().size(); i++) {
- if (i > 0) {
- builder.append(", ");
- }
- builder.append(op.getOutputVars().get(i));
- }
- builder.append("] <- [");
- for (int i = 0; i < op.getNumInput(); i++) {
- if (i > 0) {
- builder.append(", ");
- }
builder.append('[');
- for (int j = 0; j < op.getInputVariables(i).size(); j++) {
- if (j > 0) {
+ for (int i = 0; i < op.getOutputVars().size(); i++) {
+ if (i > 0) {
builder.append(", ");
}
- builder.append(op.getInputVariables(i).get(j));
+ builder.append(op.getOutputVars().get(i));
}
- builder.append(']');
+ builder.append("] <- [");
+ for (int i = 0; i < op.getNumInput(); i++) {
+ if (i > 0) {
+ builder.append(", ");
+ }
+ builder.append('[');
+ for (int j = 0; j < op.getInputVariables(i).size(); j++) {
+ if (j > 0) {
+ builder.append(", ");
+ }
+ builder.append(op.getInputVariables(i).get(j));
+ }
+ builder.append(']');
+ }
+ builder.append("])");
+ return builder.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- builder.append("])");
- return builder.toString();
}
@Override
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());
+ try {
+ 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().accept(exprVisitor, indent));
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- buffer.append(" <- " +
op.getExpressionRef().getValue().accept(exprVisitor, indent));
- return buffer.toString();
}
@Override
public String visitLeftOuterUnnestOperator(LeftOuterUnnestOperator op,
Integer indent) throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("outer-unnest " + op.getVariable());
- if (op.getPositionalVariable() != null) {
- buffer.append(" at " + op.getPositionalVariable());
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("outer-unnest " +
op.getVariable());
+ if (op.getPositionalVariable() != null) {
+ buffer.append(" at " + op.getPositionalVariable());
+ }
+ buffer.append(" <- " +
op.getExpressionRef().getValue().accept(exprVisitor, indent));
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- buffer.append(" <- " +
op.getExpressionRef().getValue().accept(exprVisitor, indent));
- return buffer.toString();
}
@Override
@@ -319,105 +411,140 @@
private String printAbstractUnnestMapOperator(AbstractUnnestMapOperator
op, Integer indent, String opSignature)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append(opSignature + " " + op.getVariables()
+ " <- "
- + op.getExpressionRef().getValue().accept(exprVisitor,
indent));
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append(opSignature + " " +
op.getVariables() + " <- "
+ + op.getExpressionRef().getValue().accept(exprVisitor,
indent));
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
- public String visitDataScanOperator(DataSourceScanOperator op, Integer
indent) {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append(
- "data-scan " + op.getProjectVariables() + "<-" +
op.getVariables() + " <- " + op.getDataSource());
- return buffer.toString();
+ public String visitDataScanOperator(DataSourceScanOperator op, Integer
indent) throws AlgebricksException {
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append(
+ "data-scan " + op.getProjectVariables() + "<-" +
op.getVariables() + " <- " + op.getDataSource());
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitLimitOperator(LimitOperator op, Integer indent) throws
AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("limit " +
op.getMaxObjects().getValue().accept(exprVisitor, indent));
- ILogicalExpression offset = op.getOffset().getValue();
- if (offset != null) {
- buffer.append(", " + offset.accept(exprVisitor, indent));
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("limit " +
op.getMaxObjects().getValue().accept(exprVisitor, indent));
+ ILogicalExpression offset = op.getOffset().getValue();
+ if (offset != null) {
+ buffer.append(", " + offset.accept(exprVisitor, indent));
+ }
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- return buffer.toString();
}
@Override
- public String visitExchangeOperator(ExchangeOperator op, Integer indent) {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("exchange ");
- return buffer.toString();
+ public String visitExchangeOperator(ExchangeOperator op, Integer indent)
throws AlgebricksException {
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("exchange ");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@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();
+ public String visitScriptOperator(ScriptOperator op, Integer indent)
throws AlgebricksException {
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent)
+ .append("script (in: " + op.getInputVariables() + ") (out:
" + op.getOutputVariables() + ")");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitReplicateOperator(ReplicateOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("replicate ");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("replicate ");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitMaterializeOperator(MaterializeOperator op, Integer
indent) throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("materialize ");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("materialize ");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitInsertDeleteUpsertOperator(InsertDeleteUpsertOperator
op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- String header = getIndexOpString(op.getOperation());
- addIndent(buffer,
indent).append(header).append(op.getDataSource()).append(" from record: ")
-
.append(op.getPayloadExpression().getValue().accept(exprVisitor, indent));
- if (op.getAdditionalNonFilteringExpressions() != null) {
- buffer.append(", meta: ");
- pprintExprList(op.getAdditionalNonFilteringExpressions(), buffer,
indent);
+ try {
+ StringBuilder buffer = new StringBuilder();
+ String header = getIndexOpString(op.getOperation());
+ addIndent(buffer,
indent).append(header).append(str(op.getDataSource())).append(" from record: ")
+
.append(op.getPayloadExpression().getValue().accept(exprVisitor, indent));
+ if (op.getAdditionalNonFilteringExpressions() != null) {
+ buffer.append(", meta: ");
+ pprintExprList(op.getAdditionalNonFilteringExpressions(),
buffer, indent);
+ }
+ buffer.append(" partitioned by ");
+ pprintExprList(op.getPrimaryKeyExpressions(), buffer, indent);
+ if (op.getOperation() == Kind.UPSERT) {
+ buffer.append(" out: ([record-before-upsert:" +
op.getPrevRecordVar()
+ + ((op.getPrevAdditionalNonFilteringVars() != null)
+ ? (", additional-before-upsert: " +
op.getPrevAdditionalNonFilteringVars()) : "")
+ + "]) ");
+ }
+ if (op.isBulkload()) {
+ buffer.append(" [bulkload]");
+ }
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- buffer.append(" partitioned by ");
- pprintExprList(op.getPrimaryKeyExpressions(), buffer, indent);
- if (op.getOperation() == Kind.UPSERT) {
- buffer.append(
- " out: ([record-before-upsert:" + op.getPrevRecordVar()
- + ((op.getPrevAdditionalNonFilteringVars() != null)
- ? (", additional-before-upsert: " +
op.getPrevAdditionalNonFilteringVars()) : "")
- + "]) ");
- }
- if (op.isBulkload()) {
- buffer.append(" [bulkload]");
- }
- return buffer.toString();
}
@Override
public String
visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op,
Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- String header = getIndexOpString(op.getOperation());
- addIndent(buffer,
indent).append(header).append(op.getIndexName()).append(" on ")
- .append(op.getDataSourceIndex().getDataSource()).append(" from
");
- if (op.getOperation() == Kind.UPSERT) {
- buffer.append(" replace:");
- pprintExprList(op.getPrevSecondaryKeyExprs(), buffer, indent);
- buffer.append(" with:");
- pprintExprList(op.getSecondaryKeyExpressions(), buffer, indent);
- } else {
- pprintExprList(op.getSecondaryKeyExpressions(), buffer, indent);
+ try {
+ StringBuilder buffer = new StringBuilder();
+ String header = getIndexOpString(op.getOperation());
+ addIndent(buffer,
indent).append(header).append(op.getIndexName()).append(" on ")
+
.append(str(op.getDataSourceIndex().getDataSource())).append(" from ");
+ if (op.getOperation() == Kind.UPSERT) {
+ buffer.append(" replace:");
+ pprintExprList(op.getPrevSecondaryKeyExprs(), buffer, indent);
+ buffer.append(" with:");
+ pprintExprList(op.getSecondaryKeyExpressions(), buffer,
indent);
+ } else {
+ pprintExprList(op.getSecondaryKeyExpressions(), buffer,
indent);
+ }
+ if (op.isBulkload()) {
+ buffer.append(" [bulkload]");
+ }
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
- if (op.isBulkload()) {
- buffer.append(" [bulkload]");
- }
- return buffer.toString();
}
public String getIndexOpString(Kind opKind) {
@@ -434,35 +561,47 @@
@Override
public String visitTokenizeOperator(TokenizeOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("tokenize
").append(op.getTokenizeVars()).append(" <- ");
- pprintExprList(op.getSecondaryKeyExpressions(), buffer, indent);
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("tokenize
").append(str(op.getTokenizeVars())).append(" <- ");
+ pprintExprList(op.getSecondaryKeyExpressions(), buffer, indent);
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitSinkOperator(SinkOperator op, Integer indent) throws
AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append("sink");
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append("sink");
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
@Override
public String visitExtensionOperator(ExtensionOperator op, Integer indent)
throws AlgebricksException {
- StringBuilder buffer = new StringBuilder();
- addIndent(buffer, indent).append(op.toString());
- return buffer.toString();
+ try {
+ StringBuilder buffer = new StringBuilder();
+ addIndent(buffer, indent).append(op.toString());
+ return buffer.toString();
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
- protected static StringBuilder addIndent(StringBuilder buffer, int level) {
+ protected static Appendable addIndent(Appendable buffer, int level) throws
IOException {
for (int i = 0; i < level; ++i) {
buffer.append(' ');
}
return buffer;
}
- protected void printNestedPlans(AbstractOperatorWithNestedPlans op,
Integer indent, StringBuilder buffer)
- throws AlgebricksException {
+ protected void printNestedPlans(AbstractOperatorWithNestedPlans op,
Integer indent, Appendable buffer)
+ throws AlgebricksException, IOException {
boolean first = true;
if (op.getNestedPlans().isEmpty()) {
buffer.append("}");
@@ -482,8 +621,8 @@
}
}
- protected void pprintExprList(List<Mutable<ILogicalExpression>>
expressions, StringBuilder buffer, Integer indent)
- throws AlgebricksException {
+ protected void pprintExprList(List<Mutable<ILogicalExpression>>
expressions, Appendable buffer, Integer indent)
+ throws AlgebricksException, IOException {
buffer.append("[");
boolean first = true;
for (Mutable<ILogicalExpression> exprRef : expressions) {
@@ -497,8 +636,8 @@
buffer.append("]");
}
- protected void pprintVeList(StringBuilder sb, List<Pair<LogicalVariable,
Mutable<ILogicalExpression>>> vePairList,
- Integer indent) throws AlgebricksException {
+ protected void pprintVeList(Appendable sb, List<Pair<LogicalVariable,
Mutable<ILogicalExpression>>> vePairList,
+ Integer indent) throws AlgebricksException, IOException {
sb.append("[");
boolean fst = true;
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> ve :
vePairList) {
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 fcf53ec..c8303f5 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
@@ -18,8 +18,9 @@
*/
package org.apache.hyracks.algebricks.core.algebra.prettyprint;
-import org.apache.commons.lang3.mutable.Mutable;
+import java.io.IOException;
+import org.apache.commons.lang3.mutable.Mutable;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
@@ -28,39 +29,47 @@
import
org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
public class PlanPrettyPrinter {
- public static void printPlan(ILogicalPlan plan, StringBuilder out,
LogicalOperatorPrettyPrintVisitor pvisitor,
+ public static void printPlan(ILogicalPlan plan, Appendable out,
LogicalOperatorPrettyPrintVisitor pvisitor,
int indent) throws AlgebricksException {
for (Mutable<ILogicalOperator> root : plan.getRoots()) {
printOperator((AbstractLogicalOperator) root.getValue(), out,
pvisitor, indent);
}
}
- public static void printPhysicalOps(ILogicalPlan plan, StringBuilder out,
int indent) {
- for (Mutable<ILogicalOperator> root : plan.getRoots()) {
- printPhysicalOperator((AbstractLogicalOperator) root.getValue(),
indent, out);
+ public static void printPhysicalOps(ILogicalPlan plan, Appendable out, int
indent) throws AlgebricksException {
+ try {
+ for (Mutable<ILogicalOperator> root : plan.getRoots()) {
+ printPhysicalOperator((AbstractLogicalOperator)
root.getValue(), indent, out);
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
}
- public static void printOperator(AbstractLogicalOperator op, StringBuilder
out,
+ public static void printOperator(AbstractLogicalOperator op, Appendable
out,
LogicalOperatorPrettyPrintVisitor pvisitor, int indent) throws
AlgebricksException {
- out.append(op.accept(pvisitor, indent));
- IPhysicalOperator pOp = op.getPhysicalOperator();
+ try {
+ out.append(op.accept(pvisitor, indent));
+ IPhysicalOperator pOp = op.getPhysicalOperator();
- if (pOp != null) {
- out.append("\n");
- pad(out, indent);
- appendln(out, "-- " + pOp.toString() + " |" +
op.getExecutionMode() + "|");
- } else {
- appendln(out, " -- |" + op.getExecutionMode() + "|");
+ if (pOp != null) {
+ out.append("\n");
+ pad(out, indent);
+ appendln(out, "-- " + pOp.toString() + " |" +
op.getExecutionMode() + "|");
+ } else {
+ appendln(out, " -- |" + op.getExecutionMode() + "|");
+ }
+
+ for (Mutable<ILogicalOperator> i : op.getInputs()) {
+ printOperator((AbstractLogicalOperator) i.getValue(), out,
pvisitor, indent + 2);
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
}
-
- for (Mutable<ILogicalOperator> i : op.getInputs()) {
- printOperator((AbstractLogicalOperator) i.getValue(), out,
pvisitor, indent + 2);
- }
-
}
- public static void printPhysicalOperator(AbstractLogicalOperator op, int
indent, StringBuilder out) {
+ private static void printPhysicalOperator(AbstractLogicalOperator op, int
indent, Appendable out)
+ throws AlgebricksException, IOException {
IPhysicalOperator pOp = op.getPhysicalOperator();
pad(out, indent);
appendln(out, "-- " + pOp.toString() + " |" + op.getExecutionMode() +
"|");
@@ -74,19 +83,17 @@
appendln(out, "}");
}
}
-
for (Mutable<ILogicalOperator> i : op.getInputs()) {
printPhysicalOperator((AbstractLogicalOperator) i.getValue(),
indent + 2, out);
}
-
}
- private static void appendln(StringBuilder buf, String s) {
+ private static void appendln(Appendable buf, String s) throws IOException {
buf.append(s);
buf.append("\n");
}
- private static void pad(StringBuilder buf, int indent) {
+ private static void pad(Appendable buf, int indent) throws IOException {
for (int i = 0; i < indent; ++i) {
buf.append(' ');
}
diff --git
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
index 2a28d2e..0adf539 100644
---
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
+++
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
@@ -19,6 +19,8 @@
package org.apache.hyracks.algebricks.core.rewriter.base;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.commons.lang3.mutable.Mutable;
@@ -53,10 +55,10 @@
return false;
}
- private IOptimizationContext context;
- private List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>>
logicalRewrites;
- private List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>>
physicalRewrites;
- private ILogicalPlan plan;
+ private final IOptimizationContext context;
+ private final List<Pair<AbstractRuleController,
List<IAlgebraicRewriteRule>>> logicalRewrites;
+ private final List<Pair<AbstractRuleController,
List<IAlgebraicRewriteRule>>> physicalRewrites;
+ private final ILogicalPlan plan;
public HeuristicOptimizer(ILogicalPlan plan,
List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>>
logicalRewrites,
@@ -76,15 +78,19 @@
AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Starting logical
optimizations.\n");
}
- StringBuilder sb = new StringBuilder();
- PlanPrettyPrinter.printPlan(plan, sb, context.getPrettyPrintVisitor(),
0);
- AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Logical Plan:\n" +
sb.toString());
+ logPlanAt("Logical Plan", Level.FINE);
runOptimizationSets(plan, logicalRewrites);
computeSchemaBottomUpForPlan(plan);
runPhysicalOptimizations(plan, physicalRewrites);
- StringBuilder sb2 = new StringBuilder();
- PlanPrettyPrinter.printPlan(plan, sb2,
context.getPrettyPrintVisitor(), 0);
- AlgebricksConfig.ALGEBRICKS_LOGGER.info("Optimized Plan:\n" +
sb2.toString());
+ logPlanAt("Optimized Plan", Level.INFO);
+ }
+
+ private void logPlanAt(String name, Level lvl) throws AlgebricksException {
+ if (AlgebricksConfig.ALGEBRICKS_LOGGER.isLoggable(lvl)) {
+ StringBuilder sb = new StringBuilder();
+ PlanPrettyPrinter.printPlan(plan, sb,
context.getPrettyPrintVisitor(), 0);
+ AlgebricksConfig.ALGEBRICKS_LOGGER.info(name + ":\n" +
sb.toString());
+ }
}
private void runOptimizationSets(ILogicalPlan plan,
--
To view, visit https://asterix-gerrit.ics.uci.edu/1004
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ied0203adc51e9710690ace74fe1e152eb7a716e8
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <[email protected]>