use of org.apache.calcite.schema.Table in project beam by apache.
the class TableResolutionTest method testResolveNestedWithDots.
/**
* Unit test for resolving a table with dots in the subschema names and the table name.
*/
@Test
public void testResolveNestedWithDots() {
String subSchema = "fake.schema";
String tableName = "fake.table";
when(mockSchemaPlus.getSubSchema(subSchema)).thenReturn(innerSchemaPlus);
when(innerSchemaPlus.getTable(tableName)).thenReturn(mockTable);
Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(subSchema, tableName));
assertThat(table, Matchers.is(mockTable));
}
use of org.apache.calcite.schema.Table in project beam by apache.
the class TableResolutionTest method testResolveFlat.
/**
* Unit test for resolving a table with no hierarchy.
*/
@Test
public void testResolveFlat() {
String tableName = "fake_table";
when(mockSchemaPlus.getTable(tableName)).thenReturn(mockTable);
Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(tableName));
assertThat(table, Matchers.is(mockTable));
}
use of org.apache.calcite.schema.Table in project beam by apache.
the class TableResolutionTest method testMissingTableInSubschema.
/**
* Unit test for resolving a table with some hierarchy and the table is missing.
*/
@Test
public void testMissingTableInSubschema() {
String subSchema = "fake_schema";
String tableName = "fake_table";
when(mockSchemaPlus.getSubSchema(subSchema)).thenReturn(innerSchemaPlus);
when(innerSchemaPlus.getTable(tableName)).thenReturn(null);
Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(subSchema, tableName));
assertThat(table, Matchers.nullValue());
}
use of org.apache.calcite.schema.Table in project beam by apache.
the class TableResolutionTest method testResolveWithDots.
/**
* Unit test for resolving a table with no hierarchy but dots in its actual name.
*/
@Test
public void testResolveWithDots() {
String tableName = "fake.table";
when(mockSchemaPlus.getTable(tableName)).thenReturn(mockTable);
Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(tableName));
assertThat(table, Matchers.is(mockTable));
}
use of org.apache.calcite.schema.Table in project beam by apache.
the class TableScanConverter method convert.
@Override
public RelNode convert(ResolvedTableScan zetaNode, List<RelNode> inputs) {
List<String> tablePath = getTablePath(zetaNode.getTable());
SchemaPlus defaultSchemaPlus = getConfig().getDefaultSchema();
if (defaultSchemaPlus == null) {
throw new AssertionError("Default schema is null.");
}
// TODO: reject incorrect top-level schema
Table calciteTable = TableResolution.resolveCalciteTable(defaultSchemaPlus, tablePath);
// we already resolved the table before passing the query to Analyzer, so it should be there
checkNotNull(calciteTable, "Unable to resolve the table path %s in schema %s", tablePath, defaultSchemaPlus.getName());
String defaultSchemaName = defaultSchemaPlus.getName();
final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(defaultSchemaPlus), ImmutableList.of(defaultSchemaName), getCluster().getTypeFactory(), new CalciteConnectionConfigImpl(new Properties()));
RelOptTableImpl relOptTable = RelOptTableImpl.create(catalogReader, calciteTable.getRowType(getCluster().getTypeFactory()), calciteTable, ImmutableList.<String>builder().add(defaultSchemaName).addAll(tablePath).build());
if (calciteTable instanceof TranslatableTable) {
return ((TranslatableTable) calciteTable).toRel(createToRelContext(), relOptTable);
} else {
throw new UnsupportedOperationException("Does not support non TranslatableTable type table!");
}
}
Aggregations