use of org.apache.flink.table.catalog.Catalog in project flink by apache.
the class HiveCatalogITCase method testCreateTableLike.
@Test
public void testCreateTableLike() throws Exception {
TableEnvironment tableEnv = HiveTestUtils.createTableEnvInBatchMode();
tableEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
tableEnv.useCatalog(hiveCatalog.getName());
tableEnv.executeSql("create table generic_table (x int) with ('connector'='COLLECTION')");
tableEnv.useCatalog(EnvironmentSettings.DEFAULT_BUILTIN_CATALOG);
tableEnv.executeSql(String.format("create table copy like `%s`.`default`.generic_table", hiveCatalog.getName()));
Catalog builtInCat = tableEnv.getCatalog(EnvironmentSettings.DEFAULT_BUILTIN_CATALOG).get();
CatalogBaseTable catalogTable = builtInCat.getTable(new ObjectPath(EnvironmentSettings.DEFAULT_BUILTIN_DATABASE, "copy"));
assertThat(catalogTable.getOptions()).hasSize(1);
assertThat(catalogTable.getOptions()).containsEntry(FactoryUtil.CONNECTOR.key(), "COLLECTION");
assertThat(catalogTable.getSchema().getFieldCount()).isEqualTo(1);
assertThat(catalogTable.getSchema().getFieldNames()).hasSameElementsAs(Collections.singletonList("x"));
assertThat(catalogTable.getSchema().getFieldDataTypes()).hasSameElementsAs(Collections.singletonList(DataTypes.INT()));
}
use of org.apache.flink.table.catalog.Catalog in project flink by apache.
the class TableEnvironmentImpl method createCatalog.
private TableResultInternal createCatalog(CreateCatalogOperation operation) {
String exMsg = getDDLOpExecuteErrorMsg(operation.asSummaryString());
try {
String catalogName = operation.getCatalogName();
Map<String, String> properties = operation.getProperties();
Catalog catalog = FactoryUtil.createCatalog(catalogName, properties, tableConfig.getConfiguration(), userClassLoader);
catalogManager.registerCatalog(catalogName, catalog);
return TableResultImpl.TABLE_RESULT_OK;
} catch (CatalogException e) {
throw new ValidationException(exMsg, e);
}
}
use of org.apache.flink.table.catalog.Catalog in project flink by apache.
the class TableEnvironmentImpl method createCatalogFunction.
private TableResultInternal createCatalogFunction(CreateCatalogFunctionOperation createCatalogFunctionOperation) {
String exMsg = getDDLOpExecuteErrorMsg(createCatalogFunctionOperation.asSummaryString());
try {
if (createCatalogFunctionOperation.isTemporary()) {
functionCatalog.registerTemporaryCatalogFunction(UnresolvedIdentifier.of(createCatalogFunctionOperation.getFunctionIdentifier().toList()), createCatalogFunctionOperation.getCatalogFunction(), createCatalogFunctionOperation.isIgnoreIfExists());
} else {
Catalog catalog = getCatalogOrThrowException(createCatalogFunctionOperation.getFunctionIdentifier().getCatalogName());
catalog.createFunction(createCatalogFunctionOperation.getFunctionIdentifier().toObjectPath(), createCatalogFunctionOperation.getCatalogFunction(), createCatalogFunctionOperation.isIgnoreIfExists());
}
return TableResultImpl.TABLE_RESULT_OK;
} catch (ValidationException e) {
throw e;
} catch (FunctionAlreadyExistException e) {
throw new ValidationException(e.getMessage(), e);
} catch (Exception e) {
throw new TableException(exMsg, e);
}
}
use of org.apache.flink.table.catalog.Catalog in project flink by apache.
the class TableEnvironmentImpl method dropCatalogFunction.
private TableResultInternal dropCatalogFunction(DropCatalogFunctionOperation dropCatalogFunctionOperation) {
String exMsg = getDDLOpExecuteErrorMsg(dropCatalogFunctionOperation.asSummaryString());
try {
if (dropCatalogFunctionOperation.isTemporary()) {
functionCatalog.dropTempCatalogFunction(dropCatalogFunctionOperation.getFunctionIdentifier(), dropCatalogFunctionOperation.isIfExists());
} else {
Catalog catalog = getCatalogOrThrowException(dropCatalogFunctionOperation.getFunctionIdentifier().getCatalogName());
catalog.dropFunction(dropCatalogFunctionOperation.getFunctionIdentifier().toObjectPath(), dropCatalogFunctionOperation.isIfExists());
}
return TableResultImpl.TABLE_RESULT_OK;
} catch (ValidationException e) {
throw e;
} catch (FunctionNotExistException e) {
throw new ValidationException(e.getMessage(), e);
} catch (Exception e) {
throw new TableException(exMsg, e);
}
}
use of org.apache.flink.table.catalog.Catalog in project flink by apache.
the class FunctionITCase method testAlterFunction.
@Test
public void testAlterFunction() throws Exception {
String create = "create function f3 as 'org.apache.flink.function.TestFunction'";
String alter = "alter function f3 as 'org.apache.flink.function.TestFunction2'";
ObjectPath objectPath = new ObjectPath("default_database", "f3");
assertTrue(tEnv().getCatalog("default_catalog").isPresent());
Catalog catalog = tEnv().getCatalog("default_catalog").get();
tEnv().executeSql(create);
CatalogFunction beforeUpdate = catalog.getFunction(objectPath);
assertEquals("org.apache.flink.function.TestFunction", beforeUpdate.getClassName());
tEnv().executeSql(alter);
CatalogFunction afterUpdate = catalog.getFunction(objectPath);
assertEquals("org.apache.flink.function.TestFunction2", afterUpdate.getClassName());
}
Aggregations