org.apache.flink.table.catalog.exceptions.FunctionNotExistException Java Examples

The following examples show how to use org.apache.flink.table.catalog.exceptions.FunctionNotExistException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #2
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists)
		throws FunctionNotExistException {
	checkNotNull(functionPath);
	checkNotNull(newFunction);

	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);
	}
}
 
Example #3
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CatalogFunction getFunction(ObjectPath path) throws FunctionNotExistException {
	checkNotNull(path);

	ObjectPath functionPath = normalize(path);

	if (!functionExists(functionPath)) {
		throw new FunctionNotExistException(getName(), functionPath);
	} else {
		return functions.get(functionPath).copy();
	}
}
 
Example #4
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #5
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFunction_FunctionNotExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);

	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function db1.nonexist does not exist in Catalog");
	catalog.getFunction(nonExistObjectPath);
}
 
Example #6
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFunction_FunctionNotExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);

	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function db1.nonexist does not exist in Catalog");
	catalog.getFunction(nonExistObjectPath);
}
 
Example #7
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists) throws FunctionNotExistException {
	checkNotNull(functionPath);

	if (functionExists(functionPath)) {
		functions.remove(functionPath);
	} else if (!ignoreIfNotExists) {
		throw new FunctionNotExistException(getName(), functionPath);
	}
}
 
Example #8
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException {
	checkNotNull(functionPath);

	if (!functionExists(functionPath)) {
		throw new FunctionNotExistException(getName(), functionPath);
	} else {
		return functions.get(functionPath).copy();
	}
}
 
Example #9
Source File: AbstractReadOnlyCatalog.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
    throw UNSUPPORTED_ERR;
}
 
Example #10
Source File: FunctionCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
private Optional<FunctionLookup.Result> 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(
			new FunctionLookup.Result(
				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 {
				// TODO update the FunctionDefinitionUtil once we drop the old function stack in DDL
				fd = getFunctionDefinition(oi.getObjectName(), catalogFunction);
			}

			return Optional.of(
				new FunctionLookup.Result(FunctionIdentifier.of(oi), fd));
		} catch (FunctionNotExistException e) {
			// Ignore
		}
	}

	return Optional.empty();
}
 
Example #11
Source File: CatalogTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testDropFunction_FunctionNotExistException() throws Exception {
	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function non.exist does not exist in Catalog");
	catalog.dropFunction(nonExistDbPath, false);
}
 
Example #12
Source File: CatalogTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetFunction_FunctionNotExistException_NoDb() throws Exception {
	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function db1.nonexist does not exist in Catalog");
	catalog.getFunction(nonExistObjectPath);
}
 
Example #13
Source File: CatalogTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testAlterFunction_FunctionNotExistException() throws Exception {
	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function db1.nonexist does not exist in Catalog");
	catalog.alterFunction(nonExistObjectPath, createFunction(), false);
}
 
Example #14
Source File: AbstractJdbcCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
	throw new UnsupportedOperationException();
}
 
Example #15
Source File: AbstractJdbcCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
	throw new UnsupportedOperationException();
}
 
Example #16
Source File: AbstractJdbcCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException, CatalogException {
	throw new UnsupportedOperationException();
}
 
Example #17
Source File: KuduCatalog.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException, CatalogException {
    throw new FunctionNotExistException(getName(), functionPath);
}
 
Example #18
Source File: PulsarCatalog.java    From pulsar-flink with Apache License 2.0 4 votes vote down vote up
@Override
public CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException, CatalogException {
    throw new UnsupportedOperationException();
}
 
Example #19
Source File: AbstractReadOnlyCatalog.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
    throw UNSUPPORTED_ERR;
}
 
Example #20
Source File: FunctionCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Optional<FunctionLookup.Result> lookupFunction(String name) {
	String functionName = normalizeName(name);

	FunctionDefinition userCandidate;

	Catalog catalog = catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get();

	try {
		CatalogFunction catalogFunction = catalog.getFunction(
			new ObjectPath(catalogManager.getCurrentDatabase(), functionName));

		if (catalog.getTableFactory().isPresent() &&
			catalog.getTableFactory().get() instanceof FunctionDefinitionFactory) {

			FunctionDefinitionFactory factory = (FunctionDefinitionFactory) catalog.getTableFactory().get();

			userCandidate = factory.createFunctionDefinition(functionName, catalogFunction);

			return Optional.of(
				new FunctionLookup.Result(
					ObjectIdentifier.of(catalogManager.getCurrentCatalog(), catalogManager.getCurrentDatabase(), name),
					userCandidate)
			);
		} else {
			// TODO: should go through function definition discover service
		}
	} catch (FunctionNotExistException e) {
		// Ignore
	}

	// If no corresponding function is found in catalog, check in-memory functions
	userCandidate = userFunctions.get(functionName);

	final Optional<FunctionDefinition> foundDefinition;
	if (userCandidate != null) {
		foundDefinition = Optional.of(userCandidate);
	} else {

		// TODO once we connect this class with the Catalog APIs we need to make sure that
		//  built-in functions are present in "root" built-in catalog. This allows to
		//  overwrite built-in functions but also fallback to the "root" catalog. It should be
		//  possible to disable the "root" catalog if that is desired.

		foundDefinition = BuiltInFunctionDefinitions.getDefinitions()
			.stream()
			.filter(f -> functionName.equals(normalizeName(f.getName())))
			.findFirst()
			.map(Function.identity());
	}

	return foundDefinition.map(definition -> new FunctionLookup.Result(
		ObjectIdentifier.of(
			catalogManager.getBuiltInCatalogName(),
			catalogManager.getBuiltInDatabaseName(),
			name),
		definition)
	);
}
 
Example #21
Source File: CatalogTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testDropFunction_FunctionNotExistException() throws Exception {
	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function non.exist does not exist in Catalog");
	catalog.dropFunction(nonExistDbPath, false);
}
 
Example #22
Source File: CatalogTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetFunction_FunctionNotExistException_NoDb() throws Exception {
	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function db1.nonexist does not exist in Catalog");
	catalog.getFunction(nonExistObjectPath);
}
 
Example #23
Source File: CatalogTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testAlterFunction_FunctionNotExistException() throws Exception {
	exception.expect(FunctionNotExistException.class);
	exception.expectMessage("Function db1.nonexist does not exist in Catalog");
	catalog.alterFunction(nonExistObjectPath, createFunction(), false);
}
 
Example #24
Source File: PulsarCatalog.java    From pulsar-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
    throw new UnsupportedOperationException();
}
 
Example #25
Source File: PulsarCatalog.java    From pulsar-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
    throw new UnsupportedOperationException();
}
 
Example #26
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Get the function.
 * Function name should be handled in a case insensitive way.
 *
 * @param functionPath path of the function
 * @return the requested function
 * @throws FunctionNotExistException if the function does not exist in the catalog
 * @throws CatalogException in case of any runtime exception
 */
CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException, CatalogException;
 
Example #27
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Modify an existing function.
 * Function name should be handled in a case insensitive way.
 *
 * @param functionPath       path of the function
 * @param newFunction        the function to be modified
 * @param ignoreIfNotExists  flag to specify behavior if the function does not exist:
 *                           if set to false, throw an exception
 *                           if set to true, nothing happens
 * @throws FunctionNotExistException if the function does not exist
 * @throws CatalogException in case of any runtime exception
 */
void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists)
	throws FunctionNotExistException, CatalogException;
 
Example #28
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Drop a function.
 * Function name should be handled in a case insensitive way.
 *
 * @param functionPath       path of the function to be dropped
 * @param ignoreIfNotExists  plag to specify behavior if the function does not exist:
 *                           if set to false, throw an exception
 *                           if set to true, nothing happens
 * @throws FunctionNotExistException if the function does not exist
 * @throws CatalogException in case of any runtime exception
 */
void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists)
	throws FunctionNotExistException, CatalogException;
 
Example #29
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Drop a function.
 *
 * @param functionPath       path of the function to be dropped
 * @param ignoreIfNotExists  plag to specify behavior if the function does not exist:
 *                           if set to false, throw an exception
 *                           if set to true, nothing happens
 * @throws FunctionNotExistException if the function does not exist
 * @throws CatalogException in case of any runtime exception
 */
void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists)
	throws FunctionNotExistException, CatalogException;
 
Example #30
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Modify an existing function.
 *
 * @param functionPath       path of the function
 * @param newFunction        the function to be modified
 * @param ignoreIfNotExists  flag to specify behavior if the function does not exist:
 *                           if set to false, throw an exception
 *                           if set to true, nothing happens
 * @throws FunctionNotExistException if the function does not exist
 * @throws CatalogException in case of any runtime exception
 */
void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists)
	throws FunctionNotExistException, CatalogException;