diqiu50 commented on code in PR #10494:
URL: https://github.com/apache/gravitino/pull/10494#discussion_r2978799001


##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java:
##########
@@ -396,4 +412,50 @@ public void setColumnType(SchemaTableName schemaTableName, 
String columnName, Ty
     String[] columnNames = {columnName};
     applyAlter(schemaTableName, TableChange.updateColumnType(columnNames, 
type));
   }
+
+  /**
+   * Checks whether the catalog supports function operations.
+   *
+   * @return true if the catalog supports function operations, false otherwise
+   */
+  public boolean supportsFunctions() {
+    return functionCatalog != null;
+  }
+
+  /**
+   * Lists all functions with details in the specified schema.
+   *
+   * @param schemaName the name of the schema
+   * @return an array of functions, or an empty array if functions are not 
supported
+   */
+  public Function[] listFunctionInfos(String schemaName) {
+    if (functionCatalog == null) {

Review Comment:
   Wrap as a function like `supportFunction`



##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java:
##########
@@ -679,4 +693,77 @@ private String getColumnName(
     }
     return internalMetadataColumnMetadata.getName();
   }
+
+  @Override
+  public Collection<LanguageFunction> listLanguageFunctions(
+      ConnectorSession session, String schemaName) {
+    if (!catalogConnectorMetadata.supportsFunctions()) {
+      return List.of();
+    }
+    Function[] functions = 
catalogConnectorMetadata.listFunctionInfos(schemaName);
+    List<LanguageFunction> result = new ArrayList<>();
+    for (Function function : functions) {
+      result.addAll(toLanguageFunctions(function));
+    }
+    LOG.debug("Listed {} language functions in schema {}", result.size(), 
schemaName);

Review Comment:
   Would logging at the debug level here be too verbose? Would trace-level 
logging be more appropriate?
   
   `listLanguageFunctions` and `getLanguageFunctions` need logs?



##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java:
##########
@@ -396,4 +412,50 @@ public void setColumnType(SchemaTableName schemaTableName, 
String columnName, Ty
     String[] columnNames = {columnName};
     applyAlter(schemaTableName, TableChange.updateColumnType(columnNames, 
type));
   }
+
+  /**
+   * Checks whether the catalog supports function operations.
+   *
+   * @return true if the catalog supports function operations, false otherwise
+   */
+  public boolean supportsFunctions() {
+    return functionCatalog != null;
+  }
+
+  /**
+   * Lists all functions with details in the specified schema.
+   *
+   * @param schemaName the name of the schema
+   * @return an array of functions, or an empty array if functions are not 
supported
+   */
+  public Function[] listFunctionInfos(String schemaName) {
+    if (functionCatalog == null) {
+      return new Function[0];
+    }
+    try {
+      return functionCatalog.listFunctionInfos(Namespace.of(schemaName));
+    } catch (NoSuchSchemaException e) {
+      throw new TrinoException(
+          GravitinoErrorCode.GRAVITINO_SCHEMA_NOT_EXISTS, 
SCHEMA_DOES_NOT_EXIST_MSG, e);
+    }
+  }
+
+  /**
+   * Retrieves a function by its schema and function name.
+   *
+   * @param schemaName the name of the schema
+   * @param functionName the name of the function
+   * @return the function, or null if functions are not supported or the 
function does not exist
+   */
+  @Nullable
+  public Function getFunction(String schemaName, String functionName) {
+    if (functionCatalog == null) {
+      return null;
+    }
+    try {
+      return functionCatalog.getFunction(NameIdentifier.of(schemaName, 
functionName));
+    } catch (NoSuchFunctionException e) {
+      return null;

Review Comment:
   Why don't we throw an exception here



##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java:
##########
@@ -679,4 +693,77 @@ private String getColumnName(
     }
     return internalMetadataColumnMetadata.getName();
   }
+
+  @Override
+  public Collection<LanguageFunction> listLanguageFunctions(
+      ConnectorSession session, String schemaName) {
+    if (!catalogConnectorMetadata.supportsFunctions()) {
+      return List.of();
+    }
+    Function[] functions = 
catalogConnectorMetadata.listFunctionInfos(schemaName);
+    List<LanguageFunction> result = new ArrayList<>();

Review Comment:
   Using stream functions to handle this logic



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