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()));
}
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();
}
Aggregations