xuefuz commented on a change in pull request #8212: [FLINK-11519][table] Add function related catalog APIs URL: https://github.com/apache/flink/pull/8212#discussion_r276882578
########## File path: flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/GenericInMemoryCatalog.java ########## @@ -269,4 +273,81 @@ public boolean tableExists(ObjectPath tablePath) { return tablePath != null && databaseExists(tablePath.getDatabaseName()) && tables.containsKey(tablePath); } + // ------ functions ------ + + @Override + public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists) + throws FunctionAlreadyExistException, DatabaseNotExistException { + checkArgument(functionPath != null); + checkArgument(function != null); + + if (!databaseExists(functionPath.getDatabaseName())) { + throw new DatabaseNotExistException(catalogName, functionPath.getDatabaseName()); + } + + if (functionExists(functionPath)) { + if (!ignoreIfExists) { + throw new FunctionAlreadyExistException(catalogName, functionPath); + } + } else { + functions.put(functionPath, function.copy()); + } + } + + @Override + public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists) + throws FunctionNotExistException { + checkArgument(functionPath != null); + checkArgument(newFunction != null); + + if (functionExists(functionPath)) { + functions.put(functionPath, newFunction.copy()); + } else if (!ignoreIfNotExists) { + throw new FunctionNotExistException(catalogName, functionPath); + } + } + + @Override + public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists) throws FunctionNotExistException { + checkArgument(functionPath != null); + + if (functionExists(functionPath)) { + functions.remove(functionPath); + } else if (!ignoreIfNotExists) { + throw new FunctionNotExistException(catalogName, functionPath); + } + } + + @Override + public List<String> listFunctions(String databaseName) throws DatabaseNotExistException { + checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty"); + + String db = databaseName.toLowerCase(); + + if (!databaseExists(db)) { + throw new DatabaseNotExistException(catalogName, db); + } + + return functions.keySet().stream() + .filter(k -> k.getDatabaseName().equals(db)).map(k -> k.getObjectName()) + .collect(Collectors.toList()); + } + + @Override + public CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException { + checkArgument(functionPath != null); + + if (!functionExists(functionPath)) { + throw new FunctionNotExistException(catalogName, functionPath); + } else { + return functions.get(functionPath).copy(); + } + } + + @Override + public boolean functionExists(ObjectPath functionPath) { + return functionPath != null && databaseExists(functionPath.getDatabaseName()) && Review comment: Well, good point. However, I'd keep it consistent with other APIs (such as tableExists()). We can come back to fix all of them together. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services