use of org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException in project flink by apache.
the class HiveCatalog method createFunction.
// ------ functions ------
@Override
public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists) throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
checkNotNull(functionPath, "functionPath cannot be null");
checkNotNull(function, "function cannot be null");
Function hiveFunction;
if (function instanceof CatalogFunctionImpl) {
hiveFunction = instantiateHiveFunction(functionPath, function);
} else {
throw new CatalogException(String.format("Unsupported catalog function type %s", function.getClass().getName()));
}
try {
client.createFunction(hiveFunction);
} catch (NoSuchObjectException e) {
throw new DatabaseNotExistException(getName(), functionPath.getDatabaseName(), e);
} catch (AlreadyExistsException e) {
if (!ignoreIfExists) {
throw new FunctionAlreadyExistException(getName(), functionPath, e);
}
} catch (TException e) {
throw new CatalogException(String.format("Failed to create function %s", functionPath.getFullName()), e);
}
}
use of org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException 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);
}
}
Aggregations