use of org.apache.calcite.rel.externalize.RelJson in project calcite by apache.
the class RelOptPlanReaderTest method testTypeToClass.
@Test
public void testTypeToClass() {
RelJson relJson = new RelJson(null);
// in org.apache.calcite.rel package
assertThat(relJson.classToTypeName(LogicalProject.class), is("LogicalProject"));
assertThat(relJson.typeNameToClass("LogicalProject"), sameInstance((Class) LogicalProject.class));
// in org.apache.calcite.adapter.jdbc.JdbcRules outer class
assertThat(relJson.classToTypeName(JdbcRules.JdbcProject.class), is("JdbcProject"));
assertThat(relJson.typeNameToClass("JdbcProject"), equalTo((Class) JdbcRules.JdbcProject.class));
try {
Class clazz = relJson.typeNameToClass("NonExistentRel");
fail("expected exception, got " + clazz);
} catch (RuntimeException e) {
assertThat(e.getMessage(), is("unknown type NonExistentRel"));
}
try {
Class clazz = relJson.typeNameToClass("org.apache.calcite.rel.NonExistentRel");
fail("expected exception, got " + clazz);
} catch (RuntimeException e) {
assertThat(e.getMessage(), is("unknown type org.apache.calcite.rel.NonExistentRel"));
}
// In this class; no special treatment. Note: '$MyRel' not '.MyRel'.
assertThat(relJson.classToTypeName(MyRel.class), is("org.apache.calcite.plan.RelOptPlanReaderTest$MyRel"));
assertThat(relJson.typeNameToClass(MyRel.class.getName()), equalTo((Class) MyRel.class));
// Using canonical name (with '$'), not found
try {
Class clazz = relJson.typeNameToClass(MyRel.class.getCanonicalName());
fail("expected exception, got " + clazz);
} catch (RuntimeException e) {
assertThat(e.getMessage(), is("unknown type org.apache.calcite.plan.RelOptPlanReaderTest.MyRel"));
}
}
Aggregations