nastra commented on code in PR #14831:
URL: https://github.com/apache/iceberg/pull/14831#discussion_r2634410892


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCommits.java:
##########
@@ -111,6 +113,36 @@ public void dropTestView() throws IOException {
     catalog.dropView(VIEW_IDENTIFIER);
   }
 
+  @Test
+  public void testViewQueryIsUpdatedOnCommit() throws Exception {
+    HiveViewOperations ops = (HiveViewOperations) ((BaseView) 
view).operations();
+    Table tbl = ops.loadHmsTable();
+    assertThat(tbl.getViewOriginalText()).isEqualTo(VIEW_QUERY);
+    assertThat(tbl.getViewExpandedText()).isEqualTo(VIEW_QUERY);
+
+    String newQuery = "select * from ns.tbl2 limit 10";
+    assertThat(VIEW_QUERY).isNotEqualTo(newQuery);
+
+    // update view query
+    view =
+        catalog
+            .buildView(VIEW_IDENTIFIER)
+            .withSchema(SCHEMA)
+            .withDefaultNamespace(NS)
+            .withQuery("hive", newQuery)
+            .replace();
+
+    Table updatedTbl = ops.loadHmsTable();
+
+    assertThat(updatedTbl.getViewOriginalText())
+        .as("The original view query in HMS must be updated to the new SQL.")
+        .isEqualTo(newQuery);
+
+    assertThat(updatedTbl.getViewExpandedText())
+        .as("The expanded view query in HMS must be updated to the new SQL.")
+        .isEqualTo(newQuery);
+  }

Review Comment:
   ```suggestion
   public void testViewQueryIsUpdatedOnCommit() throws Exception {
       HiveViewOperations ops = (HiveViewOperations) ((BaseView) 
view).operations();
       assertThat(view.currentVersion().representations())
           .containsExactly(
               
ImmutableSQLViewRepresentation.builder().sql(VIEW_QUERY).dialect("hive").build());
   
       Table hmsTable = ops.loadHmsTable();
       assertThat(hmsTable.getViewOriginalText()).isEqualTo(VIEW_QUERY);
       assertThat(hmsTable.getViewExpandedText()).isEqualTo(VIEW_QUERY);
   
       String newQuery = "select * from ns.tbl2 limit 10";
       view =
           catalog
               .buildView(VIEW_IDENTIFIER)
               .withSchema(SCHEMA)
               .withDefaultNamespace(NS)
               .withQuery("hive", newQuery)
               .replace();
   
       assertThat(view.currentVersion().representations())
           .containsExactly(
               
ImmutableSQLViewRepresentation.builder().sql(newQuery).dialect("hive").build());
   
       Table updatedHmsTable = ops.loadHmsTable();
       assertThat(updatedHmsTable.getViewOriginalText()).isEqualTo(newQuery);
       assertThat(updatedHmsTable.getViewExpandedText()).isEqualTo(newQuery);
     }
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to