Search in sources :

Example 1 with FunctionAlreadyExistException

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);
    }
}
Also used : TException(org.apache.thrift.TException) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) Function(org.apache.hadoop.hive.metastore.api.Function) FunctionAlreadyExistException(org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) PartitionAlreadyExistsException(org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) DatabaseNotExistException(org.apache.flink.table.catalog.exceptions.DatabaseNotExistException) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl)

Example 2 with FunctionAlreadyExistException

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);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException) FunctionAlreadyExistException(org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException) Catalog(org.apache.flink.table.catalog.Catalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) FunctionAlreadyExistException(org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException) DatabaseNotExistException(org.apache.flink.table.catalog.exceptions.DatabaseNotExistException) TableAlreadyExistException(org.apache.flink.table.catalog.exceptions.TableAlreadyExistException) TableException(org.apache.flink.table.api.TableException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) DatabaseNotEmptyException(org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException) DatabaseAlreadyExistException(org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException) SqlParserException(org.apache.flink.table.api.SqlParserException) ValidationException(org.apache.flink.table.api.ValidationException) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException)

Aggregations

CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)2 DatabaseNotExistException (org.apache.flink.table.catalog.exceptions.DatabaseNotExistException)2 FunctionAlreadyExistException (org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 SqlParserException (org.apache.flink.table.api.SqlParserException)1 TableException (org.apache.flink.table.api.TableException)1 ValidationException (org.apache.flink.table.api.ValidationException)1 Catalog (org.apache.flink.table.catalog.Catalog)1 CatalogFunction (org.apache.flink.table.catalog.CatalogFunction)1 CatalogFunctionImpl (org.apache.flink.table.catalog.CatalogFunctionImpl)1 FunctionCatalog (org.apache.flink.table.catalog.FunctionCatalog)1 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)1 DatabaseAlreadyExistException (org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException)1 DatabaseNotEmptyException (org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException)1 FunctionNotExistException (org.apache.flink.table.catalog.exceptions.FunctionNotExistException)1 PartitionAlreadyExistsException (org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException)1 TableAlreadyExistException (org.apache.flink.table.catalog.exceptions.TableAlreadyExistException)1 TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1