xuefuz commented on a change in pull request #9135: [FLINK-13296][table]
FunctionCatalog.lookupFunction() should check in memory functions if the target
function doesn't exist in catalog
URL: https://github.com/apache/flink/pull/9135#discussion_r304128070
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FunctionCatalog.java
##########
@@ -162,53 +162,57 @@ public void registerScalarFunction(String name,
ScalarFunction function) {
FunctionDefinition userCandidate = null;
Catalog catalog =
catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get();
+ ObjectPath functionPath = new
ObjectPath(catalogManager.getCurrentDatabase(), functionName);
- if (catalog.getTableFactory().isPresent() &&
+ if (catalog.functionExists(functionPath)) {
+ if (catalog.getTableFactory().isPresent() &&
catalog.getTableFactory().get() instanceof
FunctionDefinitionFactory) {
- try {
- CatalogFunction catalogFunction =
catalog.getFunction(
- new
ObjectPath(catalogManager.getCurrentDatabase(), functionName));
+ try {
+ CatalogFunction catalogFunction =
catalog.getFunction(functionPath);
- FunctionDefinitionFactory factory =
(FunctionDefinitionFactory) catalog.getTableFactory().get();
+ FunctionDefinitionFactory factory =
(FunctionDefinitionFactory) catalog.getTableFactory().get();
- userCandidate =
factory.createFunctionDefinition(functionName, catalogFunction);
- } catch (FunctionNotExistException e) {
- // Ignore
- }
-
- return Optional.of(
- new FunctionLookup.Result(
-
ObjectIdentifier.of(catalogManager.getCurrentCatalog(),
catalogManager.getCurrentDatabase(), name),
- userCandidate)
- );
- } else {
- // Else, check in-memory functions
- userCandidate = userFunctions.get(functionName);
+ userCandidate =
factory.createFunctionDefinition(functionName, catalogFunction);
- final Optional<FunctionDefinition> foundDefinition;
- if (userCandidate != null) {
- foundDefinition = Optional.of(userCandidate);
+ return Optional.of(
+ new FunctionLookup.Result(
+
ObjectIdentifier.of(catalogManager.getCurrentCatalog(),
catalogManager.getCurrentDatabase(), name),
+ userCandidate)
+ );
+ } catch (FunctionNotExistException e) {
+ // Ignore
Review comment:
Instead of ignoring the exception, I'm wondering if we should throw a
TableException. This is because the function exists previously but now stops
existing, which implies an unexpected scenario.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services