use of org.apache.calcite.rel.externalize.RelJsonReader in project calcite by apache.
the class RelWriterTest method testReader.
/**
* Unit test for {@link org.apache.calcite.rel.externalize.RelJsonReader}.
*/
@Test
public void testReader() {
String s = Frameworks.withPlanner(new Frameworks.PlannerAction<String>() {
public String apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
SchemaPlus schema = rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
final RelJsonReader reader = new RelJsonReader(cluster, relOptSchema, schema);
RelNode node;
try {
node = reader.read(XX);
} catch (IOException e) {
throw new RuntimeException(e);
}
return RelOptUtil.dumpPlan("", node, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
}
});
assertThat(s, isLinux("LogicalAggregate(group=[{0}], agg#0=[COUNT(DISTINCT $1)], agg#1=[COUNT()])\n" + " LogicalFilter(condition=[=($1, 10)])\n" + " LogicalTableScan(table=[[hr, emps]])\n"));
}
use of org.apache.calcite.rel.externalize.RelJsonReader in project calcite by apache.
the class SqlToRelConverterExtendedTest method foo.
public static void foo(RelNode rel) {
// Convert rel tree to JSON.
final RelJsonWriter writer = new RelJsonWriter();
rel.explain(writer);
final String json = writer.asString();
// Find the schema. If there are no tables in the plan, we won't need one.
final RelOptSchema[] schemas = { null };
rel.accept(new RelShuttleImpl() {
@Override
public RelNode visit(TableScan scan) {
schemas[0] = scan.getTable().getRelOptSchema();
return super.visit(scan);
}
});
// Convert JSON back to rel tree.
Frameworks.withPlanner(new Frameworks.PlannerAction<Object>() {
public Object apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
final RelJsonReader reader = new RelJsonReader(cluster, schemas[0], rootSchema);
try {
RelNode x = reader.read(json);
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
});
}
Aggregations