Search in sources :

Example 1 with FunctionNotExistException

use of org.apache.flink.table.catalog.exceptions.FunctionNotExistException in project flink by apache.

the class TableEnvironmentImpl method alterCatalogFunction.

private TableResultInternal alterCatalogFunction(AlterCatalogFunctionOperation alterCatalogFunctionOperation) {
    String exMsg = getDDLOpExecuteErrorMsg(alterCatalogFunctionOperation.asSummaryString());
    try {
        CatalogFunction function = alterCatalogFunctionOperation.getCatalogFunction();
        if (alterCatalogFunctionOperation.isTemporary()) {
            throw new ValidationException("Alter temporary catalog function is not supported");
        } else {
            Catalog catalog = getCatalogOrThrowException(alterCatalogFunctionOperation.getFunctionIdentifier().getCatalogName());
            catalog.alterFunction(alterCatalogFunctionOperation.getFunctionIdentifier().toObjectPath(), function, alterCatalogFunctionOperation.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);
    }
}
Also used : FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) 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)

Example 2 with FunctionNotExistException

use of org.apache.flink.table.catalog.exceptions.FunctionNotExistException in project flink by apache.

the class GenericInMemoryCatalog method alterFunction.

@Override
public void alterFunction(ObjectPath path, CatalogFunction newFunction, boolean ignoreIfNotExists) throws FunctionNotExistException {
    checkNotNull(path);
    checkNotNull(newFunction);
    ObjectPath functionPath = normalize(path);
    CatalogFunction existingFunction = functions.get(functionPath);
    if (existingFunction != null) {
        if (existingFunction.getClass() != newFunction.getClass()) {
            throw new CatalogException(String.format("Function types don't match. Existing function is '%s' and new function is '%s'.", existingFunction.getClass().getName(), newFunction.getClass().getName()));
        }
        functions.put(functionPath, newFunction.copy());
    } else if (!ignoreIfNotExists) {
        throw new FunctionNotExistException(getName(), functionPath);
    }
}
Also used : FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException)

Example 3 with FunctionNotExistException

use of org.apache.flink.table.catalog.exceptions.FunctionNotExistException in project flink by apache.

the class HiveCatalog method alterFunction.

@Override
public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
    checkNotNull(functionPath, "functionPath cannot be null");
    checkNotNull(newFunction, "newFunction cannot be null");
    try {
        // check if function exists
        getFunction(functionPath);
        Function hiveFunction;
        if (newFunction instanceof CatalogFunctionImpl) {
            hiveFunction = instantiateHiveFunction(functionPath, newFunction);
        } else {
            throw new CatalogException(String.format("Unsupported catalog function type %s", newFunction.getClass().getName()));
        }
        client.alterFunction(functionPath.getDatabaseName(), functionPath.getObjectName(), hiveFunction);
    } catch (FunctionNotExistException e) {
        if (!ignoreIfNotExists) {
            throw e;
        }
    } catch (TException e) {
        throw new CatalogException(String.format("Failed to alter function %s", functionPath.getFullName()), e);
    }
}
Also used : FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) TException(org.apache.thrift.TException) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) Function(org.apache.hadoop.hive.metastore.api.Function) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl)

Example 4 with FunctionNotExistException

use of org.apache.flink.table.catalog.exceptions.FunctionNotExistException in project flink by apache.

the class FunctionCatalog method resolvePreciseFunctionReference.

private Optional<ContextResolvedFunction> resolvePreciseFunctionReference(ObjectIdentifier oi) {
    // resolve order:
    // 1. Temporary functions
    // 2. Catalog functions
    ObjectIdentifier normalizedIdentifier = FunctionIdentifier.normalizeObjectIdentifier(oi);
    CatalogFunction potentialResult = tempCatalogFunctions.get(normalizedIdentifier);
    if (potentialResult != null) {
        return Optional.of(ContextResolvedFunction.temporary(FunctionIdentifier.of(oi), getFunctionDefinition(oi.getObjectName(), potentialResult)));
    }
    Optional<Catalog> catalogOptional = catalogManager.getCatalog(oi.getCatalogName());
    if (catalogOptional.isPresent()) {
        Catalog catalog = catalogOptional.get();
        try {
            CatalogFunction catalogFunction = catalog.getFunction(new ObjectPath(oi.getDatabaseName(), oi.getObjectName()));
            FunctionDefinition fd;
            if (catalog.getFunctionDefinitionFactory().isPresent() && catalogFunction.getFunctionLanguage() != FunctionLanguage.PYTHON) {
                fd = catalog.getFunctionDefinitionFactory().get().createFunctionDefinition(oi.getObjectName(), catalogFunction);
            } else {
                fd = getFunctionDefinition(oi.asSummaryString(), catalogFunction);
            }
            return Optional.of(ContextResolvedFunction.permanent(FunctionIdentifier.of(oi), fd));
        } catch (FunctionNotExistException e) {
        // Ignore
        }
    }
    return Optional.empty();
}
Also used : FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition)

Example 5 with FunctionNotExistException

use of org.apache.flink.table.catalog.exceptions.FunctionNotExistException in project flink by apache.

the class GenericInMemoryCatalog method dropFunction.

@Override
public void dropFunction(ObjectPath path, boolean ignoreIfNotExists) throws FunctionNotExistException {
    checkNotNull(path);
    ObjectPath functionPath = normalize(path);
    if (functionExists(functionPath)) {
        functions.remove(functionPath);
    } else if (!ignoreIfNotExists) {
        throw new FunctionNotExistException(getName(), functionPath);
    }
}
Also used : FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException)

Aggregations

FunctionNotExistException (org.apache.flink.table.catalog.exceptions.FunctionNotExistException)6 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)4 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 SqlParserException (org.apache.flink.table.api.SqlParserException)2 TableException (org.apache.flink.table.api.TableException)2 ValidationException (org.apache.flink.table.api.ValidationException)2 Catalog (org.apache.flink.table.catalog.Catalog)2 CatalogFunction (org.apache.flink.table.catalog.CatalogFunction)2 FunctionCatalog (org.apache.flink.table.catalog.FunctionCatalog)2 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)2 DatabaseAlreadyExistException (org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException)2 DatabaseNotEmptyException (org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException)2 DatabaseNotExistException (org.apache.flink.table.catalog.exceptions.DatabaseNotExistException)2 FunctionAlreadyExistException (org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException)2 TableAlreadyExistException (org.apache.flink.table.catalog.exceptions.TableAlreadyExistException)2 TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)2 CatalogFunctionImpl (org.apache.flink.table.catalog.CatalogFunctionImpl)1 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)1 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)1