Search in sources :

Example 1 with RelWriterImpl

use of org.apache.calcite.rel.externalize.RelWriterImpl in project calcite by apache.

the class RelOptUtil method toString.

/**
 * Converts a relational expression to a string.
 */
public static String toString(final RelNode rel, SqlExplainLevel detailLevel) {
    if (rel == null) {
        return null;
    }
    final StringWriter sw = new StringWriter();
    final RelWriter planWriter = new RelWriterImpl(new PrintWriter(sw), detailLevel, false);
    rel.explain(planWriter);
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) RelWriterImpl(org.apache.calcite.rel.externalize.RelWriterImpl) RelWriter(org.apache.calcite.rel.RelWriter) PrintWriter(java.io.PrintWriter)

Example 2 with RelWriterImpl

use of org.apache.calcite.rel.externalize.RelWriterImpl in project calcite by apache.

the class RexProgram method toString.

// description of this calc, chiefly intended for debugging
public String toString() {
    // Intended to produce similar output to explainCalc,
    // but without requiring a RelNode or RelOptPlanWriter.
    final RelWriterImpl pw = new RelWriterImpl(new PrintWriter(new StringWriter()));
    collectExplainTerms("", pw);
    return pw.simple();
}
Also used : StringWriter(java.io.StringWriter) RelWriterImpl(org.apache.calcite.rel.externalize.RelWriterImpl) PrintWriter(java.io.PrintWriter)

Example 3 with RelWriterImpl

use of org.apache.calcite.rel.externalize.RelWriterImpl in project calcite by apache.

the class RelOptUtil method dumpPlan.

/**
 * Dumps a plan as a string.
 *
 * @param header      Header to print before the plan. Ignored if the format
 *                    is XML
 * @param rel         Relational expression to explain
 * @param format      Output format
 * @param detailLevel Detail level
 * @return Plan
 */
public static String dumpPlan(String header, RelNode rel, SqlExplainFormat format, SqlExplainLevel detailLevel) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    if (!header.equals("")) {
        pw.println(header);
    }
    RelWriter planWriter;
    switch(format) {
        case XML:
            planWriter = new RelXmlWriter(pw, detailLevel);
            break;
        case JSON:
            planWriter = new RelJsonWriter();
            rel.explain(planWriter);
            return ((RelJsonWriter) planWriter).asString();
        default:
            planWriter = new RelWriterImpl(pw, detailLevel, false);
    }
    rel.explain(planWriter);
    pw.flush();
    return sw.toString();
}
Also used : RelXmlWriter(org.apache.calcite.rel.externalize.RelXmlWriter) StringWriter(java.io.StringWriter) RelWriterImpl(org.apache.calcite.rel.externalize.RelWriterImpl) RelJsonWriter(org.apache.calcite.rel.externalize.RelJsonWriter) RelWriter(org.apache.calcite.rel.RelWriter) PrintWriter(java.io.PrintWriter)

Example 4 with RelWriterImpl

use of org.apache.calcite.rel.externalize.RelWriterImpl in project calcite by apache.

the class AbstractRelNode method computeDigest.

/**
 * Computes the digest. Does not modify this object.
 *
 * @return Digest
 */
protected String computeDigest() {
    StringWriter sw = new StringWriter();
    RelWriter pw = new RelWriterImpl(new PrintWriter(sw), SqlExplainLevel.DIGEST_ATTRIBUTES, false) {

        protected void explain_(RelNode rel, List<Pair<String, Object>> values) {
            pw.write(getRelTypeName());
            for (RelTrait trait : traitSet) {
                pw.write(".");
                pw.write(trait.toString());
            }
            pw.write("(");
            int j = 0;
            for (Pair<String, Object> value : values) {
                if (j++ > 0) {
                    pw.write(",");
                }
                pw.write(value.left + "=" + value.right);
            }
            pw.write(")");
        }
    };
    explain(pw);
    return sw.toString();
}
Also used : RelTrait(org.apache.calcite.plan.RelTrait) StringWriter(java.io.StringWriter) RelWriterImpl(org.apache.calcite.rel.externalize.RelWriterImpl) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 RelWriterImpl (org.apache.calcite.rel.externalize.RelWriterImpl)4 RelWriter (org.apache.calcite.rel.RelWriter)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RelTrait (org.apache.calcite.plan.RelTrait)1 RelJsonWriter (org.apache.calcite.rel.externalize.RelJsonWriter)1 RelXmlWriter (org.apache.calcite.rel.externalize.RelXmlWriter)1