Copilot commented on code in PR #10998:
URL: https://github.com/apache/gravitino/pull/10998#discussion_r3245441468


##########
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveView.java:
##########
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.catalog.hive;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.apache.gravitino.annotation.Unstable;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.Dialects;
+import org.apache.gravitino.rel.Representation;
+import org.apache.gravitino.rel.SQLRepresentation;
+import org.apache.gravitino.rel.View;
+
+/**
+ * Represents a view stored in Hive Metastore (VIRTUAL_VIEW table type). The 
SQL dialect is detected
+ * from table properties: Trino views start with "/* Presto View:", Spark 
views carry {@code
+ * spark.sql.create.version} in their parameters, and all other views are 
treated as native Hive SQL
+ * views.
+ */
+@Unstable
+@EqualsAndHashCode
+@ToString
+public class HiveView implements View {
+
+  private static final String SPARK_VERSION_KEY = "spark.sql.create.version";
+  private static final String TRINO_VIEW_MARKER_KEY = "presto_view";
+  private static final String TRINO_VIEW_PREFIX = "/* Presto View:";
+
+  private String name;
+  private String comment;
+  private Column[] columns;
+  private String defaultCatalog;
+  private String defaultSchema;
+  private Map<String, String> properties;
+  private AuditInfo auditInfo;
+  private SQLRepresentation[] representations;
+
+  private HiveView() {}
+
+  @Override
+  public String name() {
+    return name;
+  }
+
+  @Override
+  public String comment() {
+    return comment;
+  }
+
+  @Override
+  public Column[] columns() {
+    return columns == null ? new Column[0] : columns;
+  }
+
+  @Override
+  @Nullable
+  public String defaultCatalog() {
+    return defaultCatalog;
+  }
+
+  @Override
+  @Nullable
+  public String defaultSchema() {
+    return defaultSchema;
+  }
+
+  @Override
+  public Representation[] representations() {
+    return representations == null ? new SQLRepresentation[0] : 
representations;
+  }
+
+  @Override
+  public Map<String, String> properties() {
+    return properties;
+  }

Review Comment:
   `properties()` can return null if the builder never sets `properties`, but 
the `View` contract expects an empty map when no properties are set. Return 
`Collections.emptyMap()` (or a defensive empty map) when `properties` is null 
to avoid NPEs in callers.



##########
catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java:
##########
@@ -197,4 +204,625 @@ void testCreateGenericTableWithEmptyColumns() throws 
Exception {
     HiveTable createdTable = hiveTableCaptor.getValue();
     Assertions.assertEquals(0, createdTable.columns().length);
   }
+
+  @Test
+  void testCreateViewRejectsTrinoDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_trino"),
+                    null,
+                    new Column[0],
+                    new SQLRepresentation[] {
+                      
SQLRepresentation.builder().withDialect("trino").withSql("SELECT 1").build()
+                    },
+                    null,
+                    null,
+                    Maps.newHashMap()));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testCreateViewPassesColumnsToHiveMetastore() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    Column[] columns = {
+      Column.of("id", org.apache.gravitino.rel.types.Types.LongType.get(), "id 
column"),
+      Column.of("name", org.apache.gravitino.rel.types.Types.StringType.get(), 
"name column")
+    };
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+
+    ArgumentCaptor<HiveTable> hiveTableCaptor = 
ArgumentCaptor.forClass(HiveTable.class);
+    doNothing().when(hiveClient).createTable(hiveTableCaptor.capture());
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    View created =
+        op.createView(
+            NameIdentifier.of("db", "v_hive"),
+            null,
+            columns,
+            new SQLRepresentation[] {
+              SQLRepresentation.builder()
+                  .withDialect("hive")
+                  .withSql("SELECT id, name FROM t")
+                  .build()
+            },
+            null,
+            null,
+            Maps.newHashMap());
+
+    Assertions.assertEquals(2, hiveTableCaptor.getValue().columns().length);
+    Assertions.assertEquals("id", 
hiveTableCaptor.getValue().columns()[0].name());
+    Assertions.assertEquals("name", 
hiveTableCaptor.getValue().columns()[1].name());
+    Assertions.assertEquals(
+        "SELECT id, name FROM t", 
hiveTableCaptor.getValue().viewOriginalText());
+    Assertions.assertEquals(2, created.columns().length);
+  }
+
+  @Test
+  void testCreateViewRejectsNonNullDefaultCatalogAndSchema() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    IllegalArgumentException exception =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_hive"),
+                    null,
+                    new Column[0],
+                    new SQLRepresentation[] {
+                      
SQLRepresentation.builder().withDialect("hive").withSql("SELECT 1").build()
+                    },
+                    "analytics",
+                    "mart",
+                    Maps.newHashMap(ImmutableMap.of("created_by", "test"))));
+
+    Assertions.assertTrue(
+        exception.getMessage().contains("does not support non-null 
defaultCatalog/defaultSchema"));
+  }
+
+  @Test
+  void testCreateViewRejectsSparkDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_spark"),
+                    null,
+                    new Column[0],
+                    new SQLRepresentation[] {
+                      
SQLRepresentation.builder().withDialect("spark").withSql("SELECT 1").build()
+                    },
+                    null,
+                    null,
+                    Maps.newHashMap()));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testCreateViewRejectsNonSqlRepresentation() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    IllegalArgumentException exception =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_non_sql"),
+                    null,
+                    new Column[0],
+                    new Representation[] {() -> "custom"},
+                    null,
+                    null,
+                    Maps.newHashMap()));
+
+    Assertions.assertTrue(exception.getMessage().contains("exactly one SQL 
representation"));
+  }
+
+  @Test
+  void testCreateViewRejectsMultipleRepresentations() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    IllegalArgumentException exception =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_multi_reps"),
+                    null,
+                    new Column[0],
+                    new Representation[] {
+                      
SQLRepresentation.builder().withDialect("hive").withSql("SELECT 1").build(),
+                      
SQLRepresentation.builder().withDialect("hive").withSql("SELECT 2").build()
+                    },
+                    null,
+                    null,
+                    Maps.newHashMap()));
+
+    Assertions.assertTrue(exception.getMessage().contains("exactly one SQL 
representation"));
+  }
+
+  @Test
+  void testLoadViewRejectsTrinoDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    when(hiveClient.getTable(anyString(), anyString(), anyString()))
+        .thenReturn(
+            HiveTable.builder()
+                .withName("v_trino")
+                .withCatalogName("hive")
+                .withDatabaseName("db")
+                .withColumns(new Column[0])
+                .withProperties(
+                    Maps.newHashMap(
+                        ImmutableMap.of(
+                            HiveConstants.TABLE_TYPE,
+                            TableType.VIRTUAL_VIEW.name(),
+                            "presto_view",
+                            "true")))
+                .withViewOriginalText("SELECT 1")
+                .build());
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () -> op.loadView(NameIdentifier.of("db", "v_trino")));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testLoadViewReturnsColumnsFromHiveMetastore() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    Column[] columns = {
+      Column.of("id", org.apache.gravitino.rel.types.Types.LongType.get(), "id 
column"),
+      Column.of("name", org.apache.gravitino.rel.types.Types.StringType.get(), 
"name column")
+    };
+    when(hiveClient.getTable(anyString(), anyString(), anyString()))
+        .thenReturn(
+            HiveTable.builder()
+                .withName("v_hive")
+                .withCatalogName("hive")
+                .withDatabaseName("db")
+                .withColumns(columns)
+                .withProperties(
+                    Maps.newHashMap(
+                        ImmutableMap.of(HiveConstants.TABLE_TYPE, 
TableType.VIRTUAL_VIEW.name())))
+                .withViewOriginalText("SELECT id, name FROM t")
+                .build());
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    View loaded = op.loadView(NameIdentifier.of("db", "v_hive"));
+
+    Assertions.assertEquals(2, loaded.columns().length);
+    Assertions.assertEquals("id", loaded.columns()[0].name());
+    Assertions.assertEquals("name", loaded.columns()[1].name());
+  }
+
+  @Test
+  void testLoadViewUsesOriginalText() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    when(hiveClient.getTable(anyString(), anyString(), anyString()))
+        .thenReturn(
+            HiveTable.builder()
+                .withName("v_hive")
+                .withCatalogName("hive")
+                .withDatabaseName("db")
+                .withColumns(new Column[0])
+                .withProperties(
+                    Maps.newHashMap(
+                        ImmutableMap.of(HiveConstants.TABLE_TYPE, 
TableType.VIRTUAL_VIEW.name())))
+                .withViewOriginalText("SELECT id, name FROM t")
+                .build());
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    View loaded = op.loadView(NameIdentifier.of("db", "v_hive"));
+
+    SQLRepresentation representation = (SQLRepresentation) 
loaded.representations()[0];
+    Assertions.assertEquals("SELECT id, name FROM t", representation.sql());
+  }
+
+  @Test
+  void testAlterViewReplaceRejectsTrinoDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveTable currentTable =
+        HiveTable.builder()
+            .withName("v_hive")
+            .withCatalogName("hive")
+            .withDatabaseName("db")
+            .withColumns(new Column[0])
+            .withProperties(
+                Maps.newHashMap(
+                    ImmutableMap.of(HiveConstants.TABLE_TYPE, 
TableType.VIRTUAL_VIEW.name())))
+            .withViewOriginalText("SELECT 1")
+            .build();
+    when(hiveClient.getTable(anyString(), anyString(), 
anyString())).thenReturn(currentTable);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () ->
+                op.alterView(
+                    NameIdentifier.of("db", "v_hive"),
+                    ViewChange.replaceView(
+                        new Column[0],
+                        new SQLRepresentation[] {
+                          SQLRepresentation.builder()
+                              .withDialect("trino")
+                              .withSql("SELECT 2")
+                              .build()
+                        },
+                        null,
+                        null,
+                        null)));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testAlterViewReplacePassesReplacementColumnsToHiveMetastore() throws 
Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    Column[] currentColumns = {
+      Column.of("id", org.apache.gravitino.rel.types.Types.LongType.get(), "id 
column")
+    };
+    Column[] replacementColumns = {
+      Column.of("id", org.apache.gravitino.rel.types.Types.LongType.get(), "id 
column"),
+      Column.of("name", org.apache.gravitino.rel.types.Types.StringType.get(), 
"name column")
+    };

Review Comment:
   Avoid using fully-qualified names in code (per AGENTS.md import guideline). 
Import `org.apache.gravitino.rel.types.Types` and use `Types.*` directly 
instead of `org.apache.gravitino.rel.types.Types.*` in the test body.



##########
catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/converter/TestHiveTableConverter.java:
##########
@@ -154,4 +163,72 @@ public void testGetColumnsWithEmptyPartitionKeys() {
     assertEquals("id", columns[0].name());
     assertEquals("name", columns[1].name());
   }
+
+  @Test
+  public void testToHiveTablePreservesVirtualViewColumnsInStorageDescriptor() {
+    Column[] columns = {
+      Column.of("id", Types.IntegerType.get(), "ID column"),
+      Column.of("name", Types.StringType.get(), "Name column")
+    };
+    HiveTable hiveTable =
+        HiveTable.builder()
+            .withName("v_orders")
+            .withDatabaseName("db")
+            .withColumns(columns)
+            .withProperties(
+                new HashMap<>(java.util.Map.of(TABLE_TYPE, 
TableType.VIRTUAL_VIEW.name())))
+            .withAuditInfo(
+                
AuditInfo.builder().withCreator("tester").withCreateTime(Instant.now()).build())
+            .withViewOriginalText("SELECT id, name FROM t")
+            .build();
+
+    Table table = HiveTableConverter.toHiveTable(hiveTable);
+
+    assertNotNull(table.getSd());
+    assertEquals(2, table.getSd().getColsSize());
+    assertEquals("id", table.getSd().getCols().get(0).getName());
+    assertEquals("name", table.getSd().getCols().get(1).getName());
+    assertEquals("SELECT id, name FROM t", table.getViewOriginalText());
+    assertEquals("SELECT id, name FROM t", table.getViewExpandedText());
+  }
+
+  @Test
+  public void testToHiveTableMirrorsOriginalTextToExpandedText() {
+    Column[] columns = {Column.of("id", Types.IntegerType.get(), "ID column")};
+    HiveTable hiveTable =
+        HiveTable.builder()
+            .withName("v_orders")
+            .withDatabaseName("db")
+            .withColumns(columns)
+            .withProperties(
+                new HashMap<>(java.util.Map.of(TABLE_TYPE, 
TableType.VIRTUAL_VIEW.name())))
+            .withAuditInfo(
+                
AuditInfo.builder().withCreator("tester").withCreateTime(Instant.now()).build())
+            .withViewOriginalText("SELECT `db`.`t`.`id` FROM `db`.`t`")
+            .build();

Review Comment:
   Avoid fully-qualified references like `java.util.Map.of(...)` in code 
(AGENTS.md import guideline). Import `java.util.Map` and use `Map.of(...)` (or 
use an existing map utility) to keep the test consistent with project 
conventions.



##########
catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java:
##########
@@ -197,4 +204,625 @@ void testCreateGenericTableWithEmptyColumns() throws 
Exception {
     HiveTable createdTable = hiveTableCaptor.getValue();
     Assertions.assertEquals(0, createdTable.columns().length);
   }
+
+  @Test
+  void testCreateViewRejectsTrinoDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_trino"),
+                    null,
+                    new Column[0],
+                    new SQLRepresentation[] {
+                      
SQLRepresentation.builder().withDialect("trino").withSql("SELECT 1").build()
+                    },
+                    null,
+                    null,
+                    Maps.newHashMap()));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testCreateViewPassesColumnsToHiveMetastore() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    Column[] columns = {
+      Column.of("id", org.apache.gravitino.rel.types.Types.LongType.get(), "id 
column"),
+      Column.of("name", org.apache.gravitino.rel.types.Types.StringType.get(), 
"name column")
+    };

Review Comment:
   Avoid using fully-qualified names in code (per AGENTS.md import guideline). 
Import `org.apache.gravitino.rel.types.Types` and use 
`Types.LongType/Types.StringType` directly instead of 
`org.apache.gravitino.rel.types.Types.*` in the test body.



##########
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveViewCatalogOperations.java:
##########
@@ -0,0 +1,472 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.catalog.hive;
+
+import static org.apache.gravitino.catalog.hive.HiveConstants.COMMENT;
+import static 
org.apache.gravitino.catalog.hive.HiveConstants.HIVE_FILTER_FIELD_PARAMS;
+import static org.apache.gravitino.catalog.hive.HiveConstants.TABLE_TYPE;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.time.Instant;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchViewException;
+import org.apache.gravitino.exceptions.ViewAlreadyExistsException;
+import org.apache.gravitino.hive.CachedClientPool;
+import org.apache.gravitino.hive.HiveTable;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.Dialects;
+import org.apache.gravitino.rel.Representation;
+import org.apache.gravitino.rel.SQLRepresentation;
+import org.apache.gravitino.rel.View;
+import org.apache.gravitino.rel.ViewCatalog;
+import org.apache.gravitino.rel.ViewChange;
+import org.apache.gravitino.utils.PrincipalUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class HiveViewCatalogOperations implements ViewCatalog {
+  private static final Logger LOG = 
LoggerFactory.getLogger(HiveViewCatalogOperations.class);
+  private static final short MAX_TABLES = -1;
+
+  private final Supplier<CachedClientPool> clientPoolSupplier;
+  private final Supplier<String> catalogNameSupplier;
+  private final Predicate<NameIdentifier> schemaExistsChecker;
+
+  HiveViewCatalogOperations(
+      Supplier<CachedClientPool> clientPoolSupplier,
+      Supplier<String> catalogNameSupplier,
+      Predicate<NameIdentifier> schemaExistsChecker) {
+    this.clientPoolSupplier = clientPoolSupplier;
+    this.catalogNameSupplier = catalogNameSupplier;
+    this.schemaExistsChecker = schemaExistsChecker;
+  }
+
+  @Override
+  public NameIdentifier[] listViews(Namespace namespace) throws 
NoSuchSchemaException {
+    NameIdentifier schemaIdent = NameIdentifier.of(namespace.levels());
+    if (!schemaExistsChecker.test(schemaIdent)) {
+      throw new NoSuchSchemaException("Schema %s does not exist", namespace);
+    }
+    try {
+      String viewFilter =
+          String.format("%stableType like \"VIRTUAL_VIEW\"", 
HIVE_FILTER_FIELD_PARAMS);
+      List<String> views =
+          clientPool()
+              .run(
+                  c ->
+                      c.listTableNamesByFilter(
+                          catalogName(), schemaIdent.name(), viewFilter, 
MAX_TABLES));
+      return views.stream()
+          .map(name -> NameIdentifier.of(namespace, name))
+          .toArray(NameIdentifier[]::new);
+    } catch (InterruptedException e) {
+      throw new RuntimeException("Failed to list Hive views in " + namespace, 
e);
+    }
+  }
+
+  @Override
+  public View loadView(NameIdentifier ident) throws NoSuchViewException {
+    return loadHiveView(ident);
+  }
+
+  @Override
+  public View createView(
+      NameIdentifier ident,
+      String comment,
+      Column[] columns,
+      Representation[] representations,
+      String defaultCatalog,
+      String defaultSchema,
+      Map<String, String> properties)
+      throws NoSuchSchemaException, ViewAlreadyExistsException {
+    NameIdentifier schemaIdent = NameIdentifier.of(ident.namespace().levels());
+    if (!schemaExistsChecker.test(schemaIdent)) {
+      throw new NoSuchSchemaException("Schema %s does not exist", schemaIdent);
+    }
+    SQLRepresentation sqlRepresentation =
+        validateSQLRepresentation(representations, defaultCatalog, 
defaultSchema, ident);
+
+    try {
+      Map<String, String> params =
+          Maps.newHashMap(properties == null ? ImmutableMap.of() : properties);
+      params.put(TABLE_TYPE, TableType.VIRTUAL_VIEW.name());
+      String viewOriginalText = toHmsViewOriginalText(sqlRepresentation, 
ident);
+
+      HiveTable hiveTable =
+          HiveTable.builder()
+              .withName(ident.name())
+              .withComment(comment)
+              .withColumns(copyColumns(columns))
+              .withProperties(params)
+              .withAuditInfo(
+                  AuditInfo.builder()
+                      .withCreator(PrincipalUtils.getCurrentUserName())
+                      .withCreateTime(Instant.now())
+                      .build())
+              .withCatalogName(catalogName())
+              .withDatabaseName(schemaIdent.name())
+              .withViewOriginalText(viewOriginalText)
+              .build();
+
+      clientPool()
+          .run(
+              c -> {
+                c.createTable(hiveTable);
+                return null;
+              });
+
+      LOG.info("Created Hive view {} in Hive Metastore", ident.name());
+      return toHiveView(
+          ident,
+          hiveTable.comment(),
+          hiveTable.properties(),
+          hiveTable.viewOriginalText(),
+          hiveTable.columns(),
+          hiveTable.auditInfo());
+    } catch (Exception e) {
+      if (isAlreadyExistsError(e)) {
+        throw new ViewAlreadyExistsException("View %s already exists in Hive 
Metastore", ident);
+      }
+      throw new RuntimeException("Failed to create Hive view " + ident, e);
+    }
+  }
+
+  @Override
+  public View alterView(NameIdentifier ident, ViewChange... changes)
+      throws NoSuchViewException, ViewAlreadyExistsException {
+    NameIdentifier schemaIdent = NameIdentifier.of(ident.namespace().levels());
+
+    try {
+      HiveTable currentHiveTable =
+          clientPool().run(c -> c.getTable(catalogName(), schemaIdent.name(), 
ident.name()));
+      if (!TableType.VIRTUAL_VIEW
+          .name()
+          .equalsIgnoreCase(currentHiveTable.properties().get(TABLE_TYPE))) {
+        throw new NoSuchViewException("No view named %s (it is a table, not a 
view)", ident.name());
+      }
+
+      String newViewName = currentHiveTable.name();
+      String updatedViewOriginalText = currentHiveTable.viewOriginalText();
+      Map<String, String> updatedProperties = 
Maps.newHashMap(currentHiveTable.properties());
+      Column[] updatedColumns = copyColumns(currentHiveTable.columns());
+      String updatedComment = currentHiveTable.comment();
+      updatedProperties.remove(COMMENT);
+
+      for (ViewChange change : changes) {
+        if (change instanceof ViewChange.RenameView) {
+          String renameTarget = ((ViewChange.RenameView) change).getNewName();
+          NameIdentifier targetIdent = NameIdentifier.of(ident.namespace(), 
renameTarget);
+          if (viewExists(targetIdent)) {
+            throw new ViewAlreadyExistsException(
+                "View %s already exists in Hive Metastore", targetIdent);
+          }
+          newViewName = renameTarget;
+        } else if (change instanceof ViewChange.SetProperty) {
+          ViewChange.SetProperty sp = (ViewChange.SetProperty) change;
+          if (COMMENT.equals(sp.getProperty())) {
+            updatedComment = sp.getValue();
+          } else {
+            updatedProperties.put(sp.getProperty(), sp.getValue());
+          }
+        } else if (change instanceof ViewChange.RemoveProperty) {
+          String property = ((ViewChange.RemoveProperty) change).getProperty();
+          if (COMMENT.equals(property)) {
+            updatedComment = null;
+          } else {
+            updatedProperties.remove(property);
+          }
+        } else if (change instanceof ViewChange.ReplaceView) {
+          ViewChange.ReplaceView replace = (ViewChange.ReplaceView) change;
+          SQLRepresentation sqlRepresentation =
+              validateSQLRepresentation(
+                  replace.getRepresentations(),
+                  replace.getDefaultCatalog(),
+                  replace.getDefaultSchema(),
+                  ident);
+          updatedColumns = copyColumns(replace.getColumns());
+          updatedComment = replace.getComment();
+          updatedViewOriginalText = toHmsViewOriginalText(sqlRepresentation, 
ident);
+        } else {
+          throw new IllegalArgumentException(
+              "Unsupported view change type: " + 
change.getClass().getSimpleName());
+        }
+      }
+
+      HiveTable updatedHiveTable =
+          buildAlteredHiveView(
+              currentHiveTable,
+              schemaIdent,
+              newViewName,
+              updatedComment,
+              updatedProperties,
+              updatedColumns,
+              updatedViewOriginalText);
+
+      final String originalName = ident.name();
+      clientPool()
+          .run(
+              c -> {
+                c.alterTable(catalogName(), schemaIdent.name(), originalName, 
updatedHiveTable);
+                return null;
+              });
+
+      LOG.info("Altered Hive view {} (now {})", ident.name(), newViewName);
+      NameIdentifier updatedIdent = NameIdentifier.of(ident.namespace(), 
newViewName);
+      return toHiveView(
+          updatedIdent,
+          updatedHiveTable.comment(),
+          updatedHiveTable.properties(),
+          updatedHiveTable.viewOriginalText(),
+          updatedHiveTable.columns(),
+          updatedHiveTable.auditInfo());
+    } catch (NoSuchViewException | ViewAlreadyExistsException | 
IllegalArgumentException e) {
+      throw e;
+    } catch (UnsupportedOperationException e) {
+      throw e;
+    } catch (Exception e) {
+      if (isAlreadyExistsError(e)) {
+        throw new ViewAlreadyExistsException(
+            "View %s already exists in Hive Metastore",
+            NameIdentifier.of(ident.namespace(), 
extractRenameTargetName(ident.name(), changes)));
+      }
+      throw new RuntimeException("Failed to alter Hive view " + ident, e);
+    }
+  }
+
+  private HiveTable buildAlteredHiveView(
+      HiveTable currentHiveTable,
+      NameIdentifier schemaIdent,
+      String viewName,
+      String comment,
+      Map<String, String> properties,
+      Column[] columns,
+      String viewOriginalText) {
+    return HiveTable.builder()
+        .withName(viewName)
+        .withComment(comment)
+        .withColumns(copyColumns(columns))
+        .withProperties(properties)
+        .withAuditInfo(currentHiveTable.auditInfo())
+        .withCatalogName(catalogName())
+        .withDatabaseName(schemaIdent.name())
+        .withViewOriginalText(viewOriginalText)
+        .build();
+  }
+
+  @Override
+  public boolean dropView(NameIdentifier ident) {
+    NameIdentifier schemaIdent = NameIdentifier.of(ident.namespace().levels());
+    try {
+      HiveTable hiveTable =
+          clientPool().run(c -> c.getTable(catalogName(), schemaIdent.name(), 
ident.name()));
+      if 
(!TableType.VIRTUAL_VIEW.name().equalsIgnoreCase(hiveTable.properties().get(TABLE_TYPE)))
 {
+        return false;
+      }
+
+      clientPool()
+          .run(
+              c -> {
+                c.dropTable(catalogName(), schemaIdent.name(), ident.name(), 
false, false);
+                return null;
+              });
+      LOG.info("Dropped Hive view {}", ident.name());
+      return true;
+    } catch (Exception e) {
+      if (isNotFoundError(e)) {
+        return false;
+      }
+      throw new RuntimeException("Failed to drop Hive view " + ident, e);
+    }
+  }
+
+  @Override
+  public boolean viewExists(NameIdentifier ident) {
+    try {
+      loadHiveView(ident);
+      return true;
+    } catch (NoSuchViewException e) {
+      return false;
+    }
+  }
+
+  private HiveView loadHiveView(NameIdentifier ident) throws 
NoSuchViewException {
+    NameIdentifier schemaIdent = NameIdentifier.of(ident.namespace().levels());
+    try {
+      HiveTable hiveTable =
+          clientPool().run(c -> c.getTable(catalogName(), schemaIdent.name(), 
ident.name()));
+      if 
(!TableType.VIRTUAL_VIEW.name().equalsIgnoreCase(hiveTable.properties().get(TABLE_TYPE)))
 {
+        throw new NoSuchViewException("No view named %s (it is a table, not a 
view)", ident);
+      }
+
+      return toHiveView(
+          ident,
+          hiveTable.comment(),
+          hiveTable.properties(),
+          hiveTable.viewOriginalText(),
+          hiveTable.columns(),
+          hiveTable.auditInfo());
+
+    } catch (NoSuchViewException | UnsupportedOperationException e) {
+      throw e;
+    } catch (Exception e) {
+      if (isNotFoundError(e)) {
+        throw new NoSuchViewException(e, "View %s does not exist in Hive 
Metastore", ident);
+      }
+      throw new RuntimeException("Failed to load Hive view " + ident, e);
+    }
+  }
+
+  private HiveView toHiveView(
+      NameIdentifier ident,
+      String comment,
+      Map<String, String> properties,
+      String viewOriginalText,
+      Column[] columns,
+      AuditInfo auditInfo) {
+    Map<String, String> params =
+        Maps.newHashMap(properties != null ? properties : ImmutableMap.of());
+    String representationSql = viewOriginalText;
+    String detectedDialect = HiveView.detectDialect(representationSql, params);
+    if (!Dialects.HIVE.equalsIgnoreCase(detectedDialect)) {
+      // TODO(design-docs/gravitino-logical-view-management.md): support 
loading trino/spark HMS
+      // views.
+      throw new UnsupportedOperationException(
+          String.format(
+              "Hive catalog currently supports only '%s' view dialect, but 
found '%s' for view %s",
+              Dialects.HIVE, detectedDialect, ident));
+    }
+
+    SQLRepresentation rep =
+        SQLRepresentation.builder()
+            .withDialect(Dialects.HIVE)
+            .withSql(representationSql != null ? representationSql : "")
+            .build();
+
+    return HiveView.builder()
+        .withName(ident.name())
+        .withComment(comment)
+        .withColumns(copyColumns(columns))
+        .withRepresentations(new SQLRepresentation[] {rep})
+        .withProperties(params)
+        .withAuditInfo(auditInfo)
+        .build();
+  }
+
+  private SQLRepresentation validateSQLRepresentation(
+      Representation[] representations,
+      String defaultCatalog,
+      String defaultSchema,
+      NameIdentifier ident) {
+    Preconditions.checkArgument(
+        representations.length == 1 && representations[0] instanceof 
SQLRepresentation,
+        "Hive catalog requires exactly one SQL representation for view %s, but 
got %s"
+            + " representation(s), first representation type is %s",
+        ident,
+        representations.length,
+        representations.length == 0 || representations[0] == null
+            ? "null"
+            : representations[0].getClass().getSimpleName());
+
+    SQLRepresentation selected = (SQLRepresentation) representations[0];
+    boolean isHiveDialect = Dialects.HIVE.equalsIgnoreCase(selected.dialect());
+    if (!isHiveDialect) {
+      // TODO(design-docs/gravitino-logical-view-management.md): support 
creating trino/spark HMS
+      // views.
+      throw new UnsupportedOperationException(
+          String.format(
+              "Hive catalog currently supports only '%s' view dialect, but got 
'%s' for view %s",
+              Dialects.HIVE, selected.dialect(), ident));
+    }
+    if (isHiveDialect) {
+      Preconditions.checkArgument(
+          defaultCatalog == null && defaultSchema == null,
+          "Hive dialect '%s' does not support non-null 
defaultCatalog/defaultSchema, but got "
+              + "defaultCatalog=%s, defaultSchema=%s for view %s",
+          Dialects.HIVE,
+          defaultCatalog,
+          defaultSchema,
+          ident);
+    }
+    return selected;
+  }
+
+  private String toHmsViewOriginalText(SQLRepresentation representation, 
NameIdentifier ident) {
+    String dialect = representation.dialect().toLowerCase();
+    if (!Dialects.HIVE.equals(dialect)) {

Review Comment:
   `representation.dialect().toLowerCase()` is locale-sensitive; under locales 
like Turkish, "HIVE" lowercases to a different string and will incorrectly be 
rejected as unsupported. Use `toLowerCase(Locale.ROOT)` (or avoid lowercasing 
and use `equalsIgnoreCase`) to make dialect matching locale-independent.
   



##########
catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/converter/TestHiveTableConverter.java:
##########
@@ -154,4 +163,72 @@ public void testGetColumnsWithEmptyPartitionKeys() {
     assertEquals("id", columns[0].name());
     assertEquals("name", columns[1].name());
   }
+
+  @Test
+  public void testToHiveTablePreservesVirtualViewColumnsInStorageDescriptor() {
+    Column[] columns = {
+      Column.of("id", Types.IntegerType.get(), "ID column"),
+      Column.of("name", Types.StringType.get(), "Name column")
+    };
+    HiveTable hiveTable =
+        HiveTable.builder()
+            .withName("v_orders")
+            .withDatabaseName("db")
+            .withColumns(columns)
+            .withProperties(
+                new HashMap<>(java.util.Map.of(TABLE_TYPE, 
TableType.VIRTUAL_VIEW.name())))
+            .withAuditInfo(
+                
AuditInfo.builder().withCreator("tester").withCreateTime(Instant.now()).build())
+            .withViewOriginalText("SELECT id, name FROM t")
+            .build();

Review Comment:
   Avoid fully-qualified references like `java.util.Map.of(...)` in code 
(AGENTS.md import guideline). Import `java.util.Map` and use `Map.of(...)` (or 
use an existing map utility) to keep the test consistent with project 
conventions.



##########
catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java:
##########
@@ -197,4 +204,625 @@ void testCreateGenericTableWithEmptyColumns() throws 
Exception {
     HiveTable createdTable = hiveTableCaptor.getValue();
     Assertions.assertEquals(0, createdTable.columns().length);
   }
+
+  @Test
+  void testCreateViewRejectsTrinoDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_trino"),
+                    null,
+                    new Column[0],
+                    new SQLRepresentation[] {
+                      
SQLRepresentation.builder().withDialect("trino").withSql("SELECT 1").build()
+                    },
+                    null,
+                    null,
+                    Maps.newHashMap()));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testCreateViewPassesColumnsToHiveMetastore() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    Column[] columns = {
+      Column.of("id", org.apache.gravitino.rel.types.Types.LongType.get(), "id 
column"),
+      Column.of("name", org.apache.gravitino.rel.types.Types.StringType.get(), 
"name column")
+    };
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+
+    ArgumentCaptor<HiveTable> hiveTableCaptor = 
ArgumentCaptor.forClass(HiveTable.class);
+    doNothing().when(hiveClient).createTable(hiveTableCaptor.capture());
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    View created =
+        op.createView(
+            NameIdentifier.of("db", "v_hive"),
+            null,
+            columns,
+            new SQLRepresentation[] {
+              SQLRepresentation.builder()
+                  .withDialect("hive")
+                  .withSql("SELECT id, name FROM t")
+                  .build()
+            },
+            null,
+            null,
+            Maps.newHashMap());
+
+    Assertions.assertEquals(2, hiveTableCaptor.getValue().columns().length);
+    Assertions.assertEquals("id", 
hiveTableCaptor.getValue().columns()[0].name());
+    Assertions.assertEquals("name", 
hiveTableCaptor.getValue().columns()[1].name());
+    Assertions.assertEquals(
+        "SELECT id, name FROM t", 
hiveTableCaptor.getValue().viewOriginalText());
+    Assertions.assertEquals(2, created.columns().length);
+  }
+
+  @Test
+  void testCreateViewRejectsNonNullDefaultCatalogAndSchema() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    IllegalArgumentException exception =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_hive"),
+                    null,
+                    new Column[0],
+                    new SQLRepresentation[] {
+                      
SQLRepresentation.builder().withDialect("hive").withSql("SELECT 1").build()
+                    },
+                    "analytics",
+                    "mart",
+                    Maps.newHashMap(ImmutableMap.of("created_by", "test"))));
+
+    Assertions.assertTrue(
+        exception.getMessage().contains("does not support non-null 
defaultCatalog/defaultSchema"));
+  }
+
+  @Test
+  void testCreateViewRejectsSparkDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_spark"),
+                    null,
+                    new Column[0],
+                    new SQLRepresentation[] {
+                      
SQLRepresentation.builder().withDialect("spark").withSql("SELECT 1").build()
+                    },
+                    null,
+                    null,
+                    Maps.newHashMap()));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testCreateViewRejectsNonSqlRepresentation() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    IllegalArgumentException exception =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_non_sql"),
+                    null,
+                    new Column[0],
+                    new Representation[] {() -> "custom"},
+                    null,
+                    null,
+                    Maps.newHashMap()));
+
+    Assertions.assertTrue(exception.getMessage().contains("exactly one SQL 
representation"));
+  }
+
+  @Test
+  void testCreateViewRejectsMultipleRepresentations() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    HiveSchema schema = 
HiveSchema.builder().withCatalogName("hive").withName("db").build();
+    when(hiveClient.getDatabase(anyString(), anyString())).thenReturn(schema);
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    IllegalArgumentException exception =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                op.createView(
+                    NameIdentifier.of("db", "v_multi_reps"),
+                    null,
+                    new Column[0],
+                    new Representation[] {
+                      
SQLRepresentation.builder().withDialect("hive").withSql("SELECT 1").build(),
+                      
SQLRepresentation.builder().withDialect("hive").withSql("SELECT 2").build()
+                    },
+                    null,
+                    null,
+                    Maps.newHashMap()));
+
+    Assertions.assertTrue(exception.getMessage().contains("exactly one SQL 
representation"));
+  }
+
+  @Test
+  void testLoadViewRejectsTrinoDialect() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    when(hiveClient.getTable(anyString(), anyString(), anyString()))
+        .thenReturn(
+            HiveTable.builder()
+                .withName("v_trino")
+                .withCatalogName("hive")
+                .withDatabaseName("db")
+                .withColumns(new Column[0])
+                .withProperties(
+                    Maps.newHashMap(
+                        ImmutableMap.of(
+                            HiveConstants.TABLE_TYPE,
+                            TableType.VIRTUAL_VIEW.name(),
+                            "presto_view",
+                            "true")))
+                .withViewOriginalText("SELECT 1")
+                .build());
+    when(clientPool.run(any()))
+        .thenAnswer(
+            invocation -> {
+              ClientPool.Action<?, HiveClient, ?> action = 
invocation.getArgument(0);
+              return action.run(hiveClient);
+            });
+    op.clientPool = clientPool;
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () -> op.loadView(NameIdentifier.of("db", "v_trino")));
+    Assertions.assertTrue(exception.getMessage().contains("supports only 
'hive'"));
+  }
+
+  @Test
+  void testLoadViewReturnsColumnsFromHiveMetastore() throws Exception {
+    HiveCatalogOperations op = new HiveCatalogOperations();
+    op.initialize(Maps.newHashMap(), null, HIVE_PROPERTIES_METADATA);
+
+    CachedClientPool clientPool = mock(CachedClientPool.class);
+    HiveClient hiveClient = mock(HiveClient.class);
+    Column[] columns = {
+      Column.of("id", org.apache.gravitino.rel.types.Types.LongType.get(), "id 
column"),
+      Column.of("name", org.apache.gravitino.rel.types.Types.StringType.get(), 
"name column")
+    };

Review Comment:
   Avoid using fully-qualified names in code (per AGENTS.md import guideline). 
Import `org.apache.gravitino.rel.types.Types` and use `Types.*` directly 
instead of `org.apache.gravitino.rel.types.Types.*` in the test body.



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