use of org.apache.flink.table.catalog.CatalogBaseTable in project flink by apache.
the class HiveDialectITCase method testView.
@Test
public void testView() throws Exception {
tableEnv.executeSql("create table tbl (x int,y string)");
// create
tableEnv.executeSql("create view v(vx) comment 'v comment' tblproperties ('k1'='v1') as select x from tbl");
ObjectPath viewPath = new ObjectPath("default", "v");
CatalogBaseTable catalogBaseTable = hiveCatalog.getTable(viewPath);
assertTrue(catalogBaseTable instanceof CatalogView);
assertEquals("vx", catalogBaseTable.getUnresolvedSchema().getColumns().get(0).getName());
assertEquals("v1", catalogBaseTable.getOptions().get("k1"));
// change properties
tableEnv.executeSql("alter view v set tblproperties ('k1'='v11')");
catalogBaseTable = hiveCatalog.getTable(viewPath);
assertEquals("v11", catalogBaseTable.getOptions().get("k1"));
// change query
tableEnv.executeSql("alter view v as select y from tbl");
catalogBaseTable = hiveCatalog.getTable(viewPath);
assertEquals("y", catalogBaseTable.getUnresolvedSchema().getColumns().get(0).getName());
// rename
tableEnv.executeSql("alter view v rename to v1");
viewPath = new ObjectPath("default", "v1");
assertTrue(hiveCatalog.tableExists(viewPath));
// drop
tableEnv.executeSql("drop view v1");
assertFalse(hiveCatalog.tableExists(viewPath));
}
use of org.apache.flink.table.catalog.CatalogBaseTable in project flink by apache.
the class HiveCatalog method getTable.
// ------ tables ------
@Override
public CatalogBaseTable getTable(ObjectPath tablePath) throws TableNotExistException, CatalogException {
checkNotNull(tablePath, "tablePath cannot be null");
Table hiveTable = getHiveTable(tablePath);
return instantiateCatalogTable(hiveTable);
}
use of org.apache.flink.table.catalog.CatalogBaseTable in project flink by apache.
the class PostgresCatalogTest method testPrimitiveDataTypes.
@Test
public void testPrimitiveDataTypes() throws TableNotExistException {
CatalogBaseTable table = catalog.getTable(new ObjectPath(PostgresCatalog.DEFAULT_DATABASE, TABLE_PRIMITIVE_TYPE));
assertEquals(getPrimitiveTable().schema, table.getUnresolvedSchema());
}
use of org.apache.flink.table.catalog.CatalogBaseTable in project flink by apache.
the class PostgresCatalogTest method testGetTable.
@Test
public void testGetTable() throws org.apache.flink.table.catalog.exceptions.TableNotExistException {
// test postgres.public.user1
Schema schema = getSimpleTable().schema;
CatalogBaseTable table = catalog.getTable(new ObjectPath("postgres", TABLE1));
assertEquals(schema, table.getUnresolvedSchema());
table = catalog.getTable(new ObjectPath("postgres", "public.t1"));
assertEquals(schema, table.getUnresolvedSchema());
// test testdb.public.user2
table = catalog.getTable(new ObjectPath(TEST_DB, TABLE2));
assertEquals(schema, table.getUnresolvedSchema());
table = catalog.getTable(new ObjectPath(TEST_DB, "public.t2"));
assertEquals(schema, table.getUnresolvedSchema());
// test testdb.testschema.user2
table = catalog.getTable(new ObjectPath(TEST_DB, TEST_SCHEMA + ".t3"));
assertEquals(schema, table.getUnresolvedSchema());
}
use of org.apache.flink.table.catalog.CatalogBaseTable in project flink by apache.
the class FlinkCalciteCatalogReader method toPreparingTable.
/**
* Translate this {@link CatalogSchemaTable} into Flink source table.
*/
private static FlinkPreparingTableBase toPreparingTable(RelOptSchema relOptSchema, List<String> names, RelDataType rowType, CatalogSchemaTable schemaTable) {
final ResolvedCatalogBaseTable<?> resolvedBaseTable = schemaTable.getContextResolvedTable().getResolvedTable();
final CatalogBaseTable originTable = resolvedBaseTable.getOrigin();
if (originTable instanceof QueryOperationCatalogView) {
return convertQueryOperationView(relOptSchema, names, rowType, (QueryOperationCatalogView) originTable);
} else if (originTable instanceof ConnectorCatalogTable) {
ConnectorCatalogTable<?, ?> connectorTable = (ConnectorCatalogTable<?, ?>) originTable;
if ((connectorTable).getTableSource().isPresent()) {
return convertLegacyTableSource(relOptSchema, rowType, schemaTable.getContextResolvedTable().getIdentifier(), connectorTable, schemaTable.getStatistic(), schemaTable.isStreamingMode());
} else {
throw new ValidationException("Cannot convert a connector table " + "without source.");
}
} else if (originTable instanceof CatalogView) {
return convertCatalogView(relOptSchema, names, rowType, schemaTable.getStatistic(), (CatalogView) originTable);
} else if (originTable instanceof CatalogTable) {
return convertCatalogTable(relOptSchema, names, rowType, schemaTable);
} else {
throw new ValidationException("Unsupported table type: " + originTable);
}
}
Aggregations