pvary commented on code in PR #17464:
URL: https://github.com/apache/iceberg/pull/17464#discussion_r3960156849


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCommits.java:
##########
@@ -216,6 +220,68 @@ public void 
testThriftExceptionUnknownStateIfNotInHistoryFailureOnCommit()
         .isEqualTo(2);
   }
 
+  /**
+   * Pretends we throw an unclear error while persisting a create-view commit, 
for a view that was
+   * never stored in the metastore. The commit status check must resolve 
cleanly instead of NPE-ing:
+   * the view-specific {@code doRefresh} treats a missing view as non-fatal 
when no metadata
+   * location is known and refreshes from a null location, so the status-check 
supplier observes
+   * null current metadata and resolves to false (a new metadata location 
cannot be current for a
+   * view that does not exist). The relaxed check then maps that to UNKNOWN.
+   */
+  @Test
+  public void 
testThriftExceptionUnknownStateOnCreateCommitWhenViewNeverPersisted()
+      throws TException, InterruptedException, IOException {
+    TableIdentifier createIdentifier = TableIdentifier.of(NS, 
"create_commit_failed_view");
+    HiveViewOperations ops = (HiveViewOperations) 
catalog.newViewOps(createIdentifier);
+    HiveViewOperations spyOps = spy(ops);
+
+    failCommitAndThrowException(spyOps);
+
+    Path createLocation = new Path(viewLocation.getParent(), 
"create_commit_failed_view");
+    ViewMetadata metadata =
+        ViewMetadata.builder()
+            .setLocation(createLocation.toString())
+            .setProperties(
+                ImmutableMap.of(
+                    TableProperties.COMMIT_NUM_STATUS_CHECKS, "1",
+                    TableProperties.COMMIT_STATUS_CHECKS_MIN_WAIT_MS, "1",
+                    TableProperties.COMMIT_STATUS_CHECKS_MAX_WAIT_MS, "10",
+                    TableProperties.COMMIT_STATUS_CHECKS_TOTAL_WAIT_MS, "100"))
+            .setCurrentVersion(
+                ImmutableViewVersion.builder()
+                    .versionId(1)
+                    .schemaId(SCHEMA.schemaId())
+                    .timestampMillis(System.currentTimeMillis())
+                    .defaultNamespace(NS)
+                    .putSummary("operation", "create")
+                    .addRepresentations(
+                        ImmutableSQLViewRepresentation.builder()
+                            .sql(VIEW_QUERY)
+                            .dialect("hive")
+                            .build())
+                    .build(),
+                SCHEMA)
+            .build();
+
+    try {
+      assertThatThrownBy(() -> spyOps.commit(null, metadata))
+          .isInstanceOf(CommitStateUnknownException.class)
+          .hasMessageStartingWith("Datacenter on fire");
+
+      assertThat(catalog.viewExists(createIdentifier))
+          .as("The view should not have been created")
+          .isFalse();
+
+      // the configured status check must run to completion: once from 
current(), once from
+      // inside checkCurrentMetadataLocation, which resolves the null metadata 
instead of throwing
+      verify(spyOps, times(2)).refresh();
+    } finally {
+      createLocation

Review Comment:
   I think this is not needed. Isn't `@After` takes care of this?



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