use of org.apache.calcite.plan.RelOptSchema in project calcite by apache.
the class RelMetadataTest method testPredicates.
/**
* Unit test for
* {@link org.apache.calcite.rel.metadata.RelMdPredicates#getPredicates(Join, RelMetadataQuery)}.
*/
@Test
public void testPredicates() {
final Project rel = (Project) convertSql("select * from emp, dept");
final Join join = (Join) rel.getInput();
final RelOptTable empTable = join.getInput(0).getTable();
final RelOptTable deptTable = join.getInput(1).getTable();
Frameworks.withPlanner(new Frameworks.PlannerAction<Void>() {
public Void apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
checkPredicates(cluster, empTable, deptTable);
return null;
}
});
}
use of org.apache.calcite.plan.RelOptSchema in project calcite by apache.
the class EmptyScope method resolve_.
private void resolve_(final CalciteSchema rootSchema, List<String> names, List<String> schemaNames, SqlNameMatcher nameMatcher, Path path, Resolved resolved) {
final List<String> concat = ImmutableList.<String>builder().addAll(schemaNames).addAll(names).build();
CalciteSchema schema = rootSchema;
SqlValidatorNamespace namespace = null;
List<String> remainingNames = concat;
for (String schemaName : concat) {
if (schema == rootSchema && nameMatcher.matches(schemaName, schema.name)) {
remainingNames = Util.skip(remainingNames);
continue;
}
final CalciteSchema subSchema = schema.getSubSchema(schemaName, nameMatcher.isCaseSensitive());
if (subSchema != null) {
path = path.plus(null, -1, subSchema.name, StructKind.NONE);
remainingNames = Util.skip(remainingNames);
schema = subSchema;
namespace = new SchemaNamespace(validator, ImmutableList.copyOf(path.stepNames()));
continue;
}
CalciteSchema.TableEntry entry = schema.getTable(schemaName, nameMatcher.isCaseSensitive());
if (entry == null) {
entry = schema.getTableBasedOnNullaryFunction(schemaName, nameMatcher.isCaseSensitive());
}
if (entry != null) {
path = path.plus(null, -1, entry.name, StructKind.NONE);
remainingNames = Util.skip(remainingNames);
final Table table = entry.getTable();
SqlValidatorTable table2 = null;
if (table instanceof Wrapper) {
table2 = ((Wrapper) table).unwrap(Prepare.PreparingTable.class);
}
if (table2 == null) {
final RelOptSchema relOptSchema = validator.catalogReader.unwrap(RelOptSchema.class);
final RelDataType rowType = table.getRowType(validator.typeFactory);
table2 = RelOptTableImpl.create(relOptSchema, rowType, entry, null);
}
namespace = new TableNamespace(validator, table2);
resolved.found(namespace, false, this, path, remainingNames);
return;
}
// neither sub-schema nor table
if (namespace != null && !remainingNames.equals(names)) {
resolved.found(namespace, false, this, path, remainingNames);
}
return;
}
}
use of org.apache.calcite.plan.RelOptSchema 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