mchades commented on code in PR #11926:
URL: https://github.com/apache/gravitino/pull/11926#discussion_r3655186543


##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadataAdapter.java:
##########
@@ -148,6 +155,83 @@ public GravitinoTable createTable(ConnectorTableMetadata 
tableMetadata) {
     return new GravitinoTable(schemaName, tableName, columns, comment, 
properties);
   }
 
+  /**
+   * Transform Gravitino view metadata to Trino ConnectorViewDefinition. Owner 
is not supported by
+   * Gravitino views, so the resulting definition always has an empty owner; 
since Trino requires an
+   * owner for run-as-definer views, {@code runAsInvoker} is always {@code 
true}.
+   *
+   * @param view the Gravitino view
+   * @return the Trino ConnectorViewDefinition
+   */
+  public ConnectorViewDefinition getViewDefinition(GravitinoView view) {
+    Preconditions.checkArgument(
+        view.getSql() != null,
+        "View %s.%s has no Trino dialect SQL representation",
+        view.getSchemaName(),
+        view.getName());
+    List<ViewColumn> columns =
+        view.getColumns().stream()
+            .map(
+                column ->
+                    new ViewColumn(
+                        column.getName(),
+                        
dataTypeTransformer.getTrinoType(column.getType()).getTypeId(),
+                        Optional.ofNullable(column.getComment())))
+            .collect(Collectors.toList());
+
+    return new ConnectorViewDefinition(
+        view.getSql(),
+        Optional.ofNullable(view.getDefaultCatalog()),
+        Optional.ofNullable(view.getDefaultSchema()),

Review Comment:
   Thanks, this fixes the invalid constructor shape in single-metalake mode. In 
multi-metalake mode, however, `getView()` still passes 
`CatalogConnectorMetadata.getCatalogName()`, whose field is initialized from 
`catalogIdentifier.name()` (for example, `iceberg`). The actual Trino catalog 
name is produced by `getTrinoCatalogName(metalake, catalog)` (for example, 
`metalake.iceberg`). A schema-only Iceberg view is therefore normalized to the 
wrong catalog and cannot resolve during analysis. Could we retain and pass the 
actual `connectorName` supplied to `GravitinoConnectorFactory.create(...)`, and 
add a `use-single-metalake=false` regression test?



##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadataAdapter.java:
##########
@@ -148,6 +155,83 @@ public GravitinoTable createTable(ConnectorTableMetadata 
tableMetadata) {
     return new GravitinoTable(schemaName, tableName, columns, comment, 
properties);
   }
 
+  /**
+   * Transform Gravitino view metadata to Trino ConnectorViewDefinition. Owner 
is not supported by
+   * Gravitino views, so the resulting definition always has an empty owner; 
since Trino requires an
+   * owner for run-as-definer views, {@code runAsInvoker} is always {@code 
true}.
+   *
+   * @param view the Gravitino view
+   * @return the Trino ConnectorViewDefinition
+   */
+  public ConnectorViewDefinition getViewDefinition(GravitinoView view) {
+    Preconditions.checkArgument(
+        view.getSql() != null,
+        "View %s.%s has no Trino dialect SQL representation",
+        view.getSchemaName(),
+        view.getName());
+    List<ViewColumn> columns =
+        view.getColumns().stream()
+            .map(
+                column ->
+                    new ViewColumn(
+                        column.getName(),
+                        
dataTypeTransformer.getTrinoType(column.getType()).getTypeId(),
+                        Optional.ofNullable(column.getComment())))
+            .collect(Collectors.toList());
+
+    return new ConnectorViewDefinition(
+        view.getSql(),
+        Optional.ofNullable(view.getDefaultCatalog()),
+        Optional.ofNullable(view.getDefaultSchema()),
+        columns,
+        Optional.ofNullable(view.getComment()),
+        Optional.empty(),
+        true,
+        List.of());

Review Comment:
   Thanks, rejecting non-empty paths avoids the silent semantic change. One 
issue remains: `Preconditions.checkArgument` throws a plain 
`IllegalArgumentException`, and `createViewInternal()` does not translate it, 
so Trino reports this user-selected `SET PATH` case as 
`GENERIC_INTERNAL_ERROR`. Could we throw `TrinoException` with 
`GRAVITINO_UNSUPPORTED_OPERATION` (or `NOT_SUPPORTED`) instead, and assert that 
error code in the regression test?



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