nastra commented on code in PR #14334:
URL: https://github.com/apache/iceberg/pull/14334#discussion_r2671928144
##########
core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java:
##########
@@ -1845,6 +1852,209 @@ public void concurrentReplaceViewVersion() {
}
}
+ @Test
+ public void concurrentUpdateViewSchema() {
+ TableIdentifier identifier = TableIdentifier.of("ns", "view");
+
+ if (requiresNamespaceCreate()) {
+ catalog().createNamespace(identifier.namespace());
+ }
+
+ assertThat(catalog().viewExists(identifier)).as("View should not
exist").isFalse();
+
+ View view =
+ catalog()
+ .buildView(identifier)
+ .withSchema(SCHEMA)
+ .withDefaultNamespace(identifier.namespace())
+ .withQuery("trino", "select id, data from ns.tbl")
+ .withProperty(ViewProperties.REPLACE_DROP_DIALECT_ALLOWED, "true")
+ .create();
+
+ assertThat(catalog().viewExists(identifier)).as("View should
exist").isTrue();
+
+ ReplaceViewVersion replaceViewVersionOne =
+ view.replaceVersion()
+ .withQuery("trino", "select id, data, extra from ns.tbl")
+ .withSchema(SCHEMA_WITH_EXTRA_COL)
+ .withDefaultNamespace(identifier.namespace());
+
+ ReplaceViewVersion replaceViewVersionTwo =
+ view.replaceVersion()
+ .withQuery("spark", "select count(id, data) from ns.tbl")
+ .withSchema(OTHER_SCHEMA)
+ .withDefaultNamespace(identifier.namespace());
+
+ // simulate a concurrent replace of the view version with 2 different
schema updates
+ ViewOperations viewOps = ((BaseView) view).operations();
+ ViewMetadata current = viewOps.current();
+
+ ViewMetadata trinoUpdate = ((ViewVersionReplace)
replaceViewVersionOne).internalApply();
+ ViewMetadata sparkUpdate = ((ViewVersionReplace)
replaceViewVersionTwo).internalApply();
+
+ viewOps.commit(current, trinoUpdate);
+
+ if (supportsServerSideRetry()) {
+ // retry should succeed and the changes should be applied
+ viewOps.commit(current, sparkUpdate);
+
+ View updatedView = catalog().loadView(identifier);
+ ViewVersion viewVersion = updatedView.currentVersion();
+ assertThat(viewVersion.versionId()).isEqualTo(3);
+ assertThat(updatedView.versions()).hasSize(3);
+ assertThat(updatedView.version(1))
+ .isEqualTo(
+ ImmutableViewVersion.builder()
+ .timestampMillis(updatedView.version(1).timestampMillis())
+ .versionId(1)
+ .schemaId(0)
+ .summary(updatedView.version(1).summary())
+ .defaultNamespace(identifier.namespace())
+ .addRepresentations(
+ ImmutableSQLViewRepresentation.builder()
+ .sql("select id, data from ns.tbl")
+ .dialect("trino")
+ .build())
+ .build());
+
assertThat(updatedView.schemas().get(updatedView.version(1).schemaId()).sameSchema(SCHEMA));
+
+ assertThat(updatedView.version(2))
+ .isEqualTo(
+ ImmutableViewVersion.builder()
+ .timestampMillis(updatedView.version(2).timestampMillis())
+ .versionId(2)
+ .schemaId(1)
+ .summary(updatedView.version(2).summary())
+ .defaultNamespace(identifier.namespace())
+ .addRepresentations(
+ ImmutableSQLViewRepresentation.builder()
+ .sql("select id, data, extra from ns.tbl")
+ .dialect("trino")
+ .build())
+ .build());
+ assertThat(
+ updatedView
+ .schemas()
+ .get(updatedView.version(2).schemaId())
+ .sameSchema(SCHEMA_WITH_EXTRA_COL));
Review Comment:
please update this check and other checks as well
--
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]