Search in sources :

Example 1 with RelXmlWriter

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

the class SqlToRelConverterTest method testExplainAsXml.

@Test
public void testExplainAsXml() {
    String sql = "select 1 + 2, 3 from (values (true))";
    final RelNode rel = tester.convertSqlToRel(sql).rel;
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    RelXmlWriter planWriter = new RelXmlWriter(pw, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
    rel.explain(planWriter);
    pw.flush();
    TestUtil.assertEqualsVerbose("<RelNode type=\"LogicalProject\">\n" + "\t<Property name=\"EXPR$0\">\n" + "\t\t+(1, 2)\t</Property>\n" + "\t<Property name=\"EXPR$1\">\n" + "\t\t3\t</Property>\n" + "\t<Inputs>\n" + "\t\t<RelNode type=\"LogicalValues\">\n" + "\t\t\t<Property name=\"tuples\">\n" + "\t\t\t\t[{ true }]\t\t\t</Property>\n" + "\t\t\t<Inputs/>\n" + "\t\t</RelNode>\n" + "\t</Inputs>\n" + "</RelNode>\n", Util.toLinux(sw.toString()));
}
Also used : RelXmlWriter(org.apache.calcite.rel.externalize.RelXmlWriter) RelNode(org.apache.calcite.rel.RelNode) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with RelXmlWriter

use of org.apache.calcite.rel.externalize.RelXmlWriter 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)

Aggregations

PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 RelXmlWriter (org.apache.calcite.rel.externalize.RelXmlWriter)2 RelNode (org.apache.calcite.rel.RelNode)1 RelWriter (org.apache.calcite.rel.RelWriter)1 RelJsonWriter (org.apache.calcite.rel.externalize.RelJsonWriter)1 RelWriterImpl (org.apache.calcite.rel.externalize.RelWriterImpl)1 Test (org.junit.Test)1