rdblue commented on code in PR #9582:
URL: https://github.com/apache/iceberg/pull/9582#discussion_r1473173626


##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -1362,6 +1362,127 @@ public void showCreateComplexView() {
     assertThat(sql("SHOW CREATE TABLE %s", 
viewName)).containsExactly(row(expected));
   }
 
+  @Test
+  public void alterViewSetProperties() {
+    String viewName = "viewWithSetProperties";
+
+    sql("CREATE VIEW %s AS SELECT id FROM %s WHERE id <= 3", viewName, 
tableName);
+
+    ViewCatalog viewCatalog = viewCatalog();
+    assertThat(viewCatalog.loadView(TableIdentifier.of(NAMESPACE, 
viewName)).properties())
+        .doesNotContainKey("key1")
+        .doesNotContainKey("comment");
+
+    sql("ALTER VIEW %s SET TBLPROPERTIES ('key1' = 'val1', 'comment' = 'view 
comment')", viewName);
+    assertThat(viewCatalog.loadView(TableIdentifier.of(NAMESPACE, 
viewName)).properties())
+        .containsEntry("key1", "val1")
+        .containsEntry("comment", "view comment");
+
+    sql("ALTER VIEW %s SET TBLPROPERTIES ('key1' = 'new_val1')", viewName);
+    assertThat(viewCatalog.loadView(TableIdentifier.of(NAMESPACE, 
viewName)).properties())
+        .containsEntry("key1", "new_val1")
+        .containsEntry("comment", "view comment");
+  }
+
+  @Test
+  public void alterViewSetReservedProperties() {
+    String viewName = "viewWithSetReservedProperties";
+
+    sql("CREATE VIEW %s AS SELECT id FROM %s WHERE id <= 3", viewName, 
tableName);
+
+    assertThatThrownBy(() -> sql("ALTER VIEW %s SET TBLPROPERTIES ('provider' 
= 'val1')", viewName))
+        .isInstanceOf(AnalysisException.class)
+        .hasMessageContaining(
+            "The feature is not supported: provider is a reserved table 
property");
+
+    assertThatThrownBy(
+            () -> sql("ALTER VIEW %s SET TBLPROPERTIES ('location' = 
'random_location')", viewName))
+        .isInstanceOf(AnalysisException.class)
+        .hasMessageContaining(
+            "The feature is not supported: location is a reserved table 
property");
+
+    assertThatThrownBy(
+            () -> sql("ALTER VIEW %s SET TBLPROPERTIES ('format-version' = 
'99')", viewName))
+        .isInstanceOf(UnsupportedOperationException.class)
+        .hasMessageContaining(
+            "Cannot specify 'format-version' because it's a reserved view 
property");
+
+    assertThatThrownBy(
+            () -> sql("ALTER VIEW %s SET TBLPROPERTIES ('queryColumnNames' = 
'a,b,c')", viewName))
+        .isInstanceOf(UnsupportedOperationException.class)
+        .hasMessageContaining(
+            "Cannot specify 'queryColumnNames' because it's a reserved view 
property");
+  }
+
+  @Test
+  public void alterViewUnsetProperties() {
+    String viewName = "viewWithUnsetProperties";
+    sql("CREATE VIEW %s AS SELECT id FROM %s WHERE id <= 3", viewName, 
tableName);
+
+    ViewCatalog viewCatalog = viewCatalog();
+    assertThat(viewCatalog.loadView(TableIdentifier.of(NAMESPACE, 
viewName)).properties())
+        .doesNotContainKey("key1")
+        .doesNotContainKey("comment");
+
+    sql("ALTER VIEW %s SET TBLPROPERTIES ('key1' = 'val1', 'comment' = 'view 
comment')", viewName);
+    assertThat(viewCatalog.loadView(TableIdentifier.of(NAMESPACE, 
viewName)).properties())
+        .containsEntry("key1", "val1")
+        .containsEntry("comment", "view comment");
+
+    sql("ALTER VIEW %s UNSET TBLPROPERTIES ('key1')", viewName);
+    assertThat(viewCatalog.loadView(TableIdentifier.of(NAMESPACE, 
viewName)).properties())
+        .doesNotContainKey("key1")
+        .containsEntry("comment", "view comment");
+  }
+
+  @Test
+  public void alterViewUnsetUnknownProperty() {
+    String viewName = "viewWithUnsetUnknownProp";
+    sql("CREATE VIEW %s AS SELECT id FROM %s WHERE id <= 3", viewName, 
tableName);
+
+    assertThatThrownBy(() -> sql("ALTER VIEW %s UNSET TBLPROPERTIES 
('unknown-key')", viewName))
+        .isInstanceOf(AnalysisException.class)
+        .hasMessageContaining("Attempted to unset non-existing property 
'unknown-key'");
+
+    assertThatNoException()
+        .isThrownBy(
+            () -> sql("ALTER VIEW %s UNSET TBLPROPERTIES IF EXISTS 
('unknown-key')", viewName));
+  }
+
+  @Test
+  public void alterViewUnsetReservedProperties() {
+    String viewName = "viewWithUnsetReservedProperties";
+
+    sql("CREATE VIEW %s AS SELECT id FROM %s WHERE id <= 3", viewName, 
tableName);
+
+    assertThatThrownBy(() -> sql("ALTER VIEW %s UNSET TBLPROPERTIES 
('provider')", viewName))
+        .isInstanceOf(AnalysisException.class)
+        .hasMessageContaining(
+            "The feature is not supported: provider is a reserved table 
property");
+
+    assertThatThrownBy(() -> sql("ALTER VIEW %s UNSET TBLPROPERTIES 
('location')", viewName))
+        .isInstanceOf(AnalysisException.class)
+        .hasMessageContaining(
+            "The feature is not supported: location is a reserved table 
property");
+
+    assertThatThrownBy(() -> sql("ALTER VIEW %s UNSET TBLPROPERTIES 
('format-version')", viewName))
+        .isInstanceOf(UnsupportedOperationException.class)
+        .hasMessageContaining(
+            "Cannot specify 'format-version' because it's a reserved view 
property");

Review Comment:
   Same as above, it would be nice to improve the error message.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to