pvary commented on code in PR #17464:
URL: https://github.com/apache/iceberg/pull/17464#discussion_r3959056225
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCommits.java:
##########
@@ -216,6 +218,78 @@ 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();
+
+ // pins the view-specific doRefresh wiring: a missing view is not an
error when no metadata
+ // location is known, so refreshing a never-persisted view must yield
null metadata
+ assertThat(ops.refresh())
+ .as("Refreshing a never-persisted view should yield null metadata")
+ .isNull();
+
+ // and the commit status check supplier must resolve to false for the
null metadata instead
+ // of throwing an NPE
+ assertThat(
+ ops.checkCurrentMetadataLocation(
+ createLocation + "/metadata/00000-uuid.metadata.json"))
+ .as("A new metadata location cannot be current for a never-persisted
view")
+ .isFalse();
Review Comment:
Could we check on the number of calls on refresh? We already has a spyOps,
so it is easy to reach, and we don't have to expose internals for it.
--
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]