use of org.apache.flink.table.catalog.CatalogFunction in project flink by apache.
the class HiveCatalogGenericMetadataTest method testFunctionCompatibility.
@Test
public void testFunctionCompatibility() throws Exception {
catalog.createDatabase(db1, createDb(), false);
// create a function with old prefix 'flink:' and make sure we can properly retrieve it
((HiveCatalog) catalog).client.createFunction(new Function(path1.getObjectName().toLowerCase(), path1.getDatabaseName(), "flink:class.name", null, PrincipalType.GROUP, (int) (System.currentTimeMillis() / 1000), FunctionType.JAVA, new ArrayList<>()));
CatalogFunction catalogFunction = catalog.getFunction(path1);
assertEquals("class.name", catalogFunction.getClassName());
assertEquals(FunctionLanguage.JAVA, catalogFunction.getFunctionLanguage());
}
use of org.apache.flink.table.catalog.CatalogFunction 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.CatalogFunction 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);
}
}
use of org.apache.flink.table.catalog.CatalogFunction in project flink by apache.
the class SqlToOperationConverter method convertCreateFunction.
/**
* Convert CREATE FUNCTION statement.
*/
private Operation convertCreateFunction(SqlCreateFunction sqlCreateFunction) {
UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlCreateFunction.getFunctionIdentifier());
if (sqlCreateFunction.isSystemFunction()) {
return new CreateTempSystemFunctionOperation(unresolvedIdentifier.getObjectName(), sqlCreateFunction.getFunctionClassName().getValueAs(String.class), sqlCreateFunction.isIfNotExists(), parseLanguage(sqlCreateFunction.getFunctionLanguage()));
} else {
FunctionLanguage language = parseLanguage(sqlCreateFunction.getFunctionLanguage());
CatalogFunction catalogFunction = new CatalogFunctionImpl(sqlCreateFunction.getFunctionClassName().getValueAs(String.class), language);
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
return new CreateCatalogFunctionOperation(identifier, catalogFunction, sqlCreateFunction.isIfNotExists(), sqlCreateFunction.isTemporary());
}
}
use of org.apache.flink.table.catalog.CatalogFunction in project flink by apache.
the class SqlToOperationConverter method convertAlterFunction.
/**
* Convert ALTER FUNCTION statement.
*/
private Operation convertAlterFunction(SqlAlterFunction sqlAlterFunction) {
if (sqlAlterFunction.isSystemFunction()) {
throw new ValidationException("Alter temporary system function is not supported");
}
FunctionLanguage language = parseLanguage(sqlAlterFunction.getFunctionLanguage());
CatalogFunction catalogFunction = new CatalogFunctionImpl(sqlAlterFunction.getFunctionClassName().getValueAs(String.class), language);
UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlAlterFunction.getFunctionIdentifier());
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
return new AlterCatalogFunctionOperation(identifier, catalogFunction, sqlAlterFunction.isIfExists(), sqlAlterFunction.isTemporary());
}
Aggregations