Skip to content

Commit

Permalink
REST server might override the configured view location
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra committed Oct 18, 2023
1 parent 380c465 commit d4f510d
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ protected boolean requiresNamespaceCreate() {
return false;
}

protected boolean overridesRequestedLocation() {
return false;
}

@Test
public void basicCreateView() {
TableIdentifier identifier = TableIdentifier.of("ns", "view");
Expand Down Expand Up @@ -141,9 +145,14 @@ public void completeCreateView() {
assertThat(catalog().viewExists(identifier)).as("View should exist").isTrue();
assertThat(((BaseView) view).operations().current().metadataFileLocation()).isNotNull();

if (!overridesRequestedLocation()) {
assertThat(view.location()).isEqualTo("file://tmp/ns/view");
} else {
assertThat(view.location()).isNotNull();
}

// validate view settings
assertThat(view.name()).isEqualTo(ViewUtil.fullViewName(catalog().name(), identifier));
assertThat(view.location()).isEqualTo("file://tmp/ns/view");
assertThat(view.properties()).containsEntry("prop1", "val1").containsEntry("prop2", "val2");
assertThat(view.history())
.hasSize(1)
Expand Down Expand Up @@ -1413,7 +1422,12 @@ public void createAndReplaceViewWithLocation() {
.create();

assertThat(catalog().viewExists(identifier)).as("View should exist").isTrue();
assertThat(view.location()).isEqualTo("file://tmp/ns/view");

if (!overridesRequestedLocation()) {
assertThat(view.location()).isEqualTo("file://tmp/ns/view");
} else {
assertThat(view.location()).isNotNull();
}

view =
catalog()
Expand All @@ -1424,7 +1438,11 @@ public void createAndReplaceViewWithLocation() {
.withLocation("file://updated_tmp/ns/view")
.replace();

assertThat(view.location()).isEqualTo("file://updated_tmp/ns/view");
if (!overridesRequestedLocation()) {
assertThat(view.location()).isEqualTo("file://updated_tmp/ns/view");
} else {
assertThat(view.location()).isNotNull();
}

assertThat(catalog().dropView(identifier)).isTrue();
assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse();
Expand All @@ -1450,13 +1468,21 @@ public void updateViewLocation() {
.create();

assertThat(catalog().viewExists(identifier)).as("View should exist").isTrue();
assertThat(view.location()).isEqualTo("file://tmp/ns/view");
if (!overridesRequestedLocation()) {
assertThat(view.location()).isEqualTo("file://tmp/ns/view");
} else {
assertThat(view.location()).isNotNull();
}

view.updateLocation().setLocation("file://updated_tmp/ns/view").commit();

View updatedView = catalog().loadView(identifier);

assertThat(updatedView.location()).isEqualTo("file://updated_tmp/ns/view");
if (!overridesRequestedLocation()) {
assertThat(updatedView.location()).isEqualTo("file://updated_tmp/ns/view");
} else {
assertThat(view.location()).isNotNull();
}

// history and view versions should stay the same after updating view properties
assertThat(updatedView.history()).hasSize(1).isEqualTo(view.history());
Expand Down

0 comments on commit d4f510d

Please sign in to comment.