jerryshao commented on code in PR #9560:
URL: https://github.com/apache/gravitino/pull/9560#discussion_r2672081159


##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -71,29 +84,56 @@ public ManagedFunctionOperations(EntityStore store, 
IdGenerator idGenerator) {
 
   @Override
   public NameIdentifier[] listFunctions(Namespace namespace) throws 
NoSuchSchemaException {
-    // TODO: Implement when FunctionEntity is available
-    throw new UnsupportedOperationException("listFunctions: FunctionEntity not 
yet implemented");
+    return Arrays.stream(listFunctionInfos(namespace))
+        .map(f -> NameIdentifier.of(namespace, f.name()))
+        .toArray(NameIdentifier[]::new);
   }
 
   @Override
   public Function[] listFunctionInfos(Namespace namespace) throws 
NoSuchSchemaException {
-    // TODO: Implement when FunctionEntity is available
-    throw new UnsupportedOperationException(
-        "listFunctionInfos: FunctionEntity not yet implemented");
+    try {
+      List<FunctionEntity> functions =
+          store.list(namespace, FunctionEntity.class, 
Entity.EntityType.FUNCTION);
+      return functions.toArray(FunctionEntity[]::new);
+
+    } catch (NoSuchEntityException e) {
+      throw new NoSuchSchemaException(e, "Schema %s does not exist", 
namespace);
+    } catch (IOException e) {
+      throw new RuntimeException("Failed to list functions in namespace " + 
namespace, e);
+    }
   }
 
   @Override
   public Function getFunction(NameIdentifier ident) throws 
NoSuchFunctionException {
-    // TODO: Implement when FunctionEntity is available
-    throw new UnsupportedOperationException("getFunction: FunctionEntity not 
yet implemented");
+    return getFunction(ident, FunctionEntity.LATEST_VERSION);
   }
 
   @Override
   public Function getFunction(NameIdentifier ident, int version)
       throws NoSuchFunctionException, NoSuchFunctionVersionException {
-    // TODO: Implement when FunctionEntity is available
-    throw new UnsupportedOperationException(
-        "getFunction with version: FunctionEntity not yet implemented");
+    NameIdentifier versionedIdent = toVersionedIdent(ident, version);
+    try {
+      return store.get(versionedIdent, Entity.EntityType.FUNCTION, 
FunctionEntity.class);
+
+    } catch (NoSuchEntityException e) {
+      if (version == FunctionEntity.LATEST_VERSION) {
+        throw new NoSuchFunctionException(e, "Function %s does not exist", 
ident);
+      }
+      // Check if the function exists at all
+      try {
+        store.get(
+            toVersionedIdent(ident, FunctionEntity.LATEST_VERSION),
+            Entity.EntityType.FUNCTION,
+            FunctionEntity.class);
+        // Function exists, but version doesn't
+        throw new NoSuchFunctionVersionException(
+            e, "Function %s version %d does not exist", ident, version);
+      } catch (NoSuchEntityException | IOException ex) {
+        throw new NoSuchFunctionException(e, "Function %s does not exist", 
ident);
+      }
+    } catch (IOException e) {
+      throw new RuntimeException("Failed to get function " + ident, e);
+    }

Review Comment:
   Is it necessary to distinguish `NoSuchFunctionException` and 
`NoSuchFunctionVersionException`, to handle this you need to call the DB twice, 
which is not so efficient. 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to