Skip to content

Commit

Permalink
Add test for VIEWS and MATERIALIZED VIEWS interoperability
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk authored and findepi committed Jul 19, 2021
1 parent 4b4e4f1 commit 71e0566
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,37 @@ public void testMaterializedView()
assertUpdate("DROP MATERIALIZED VIEW " + viewNameWithComment);
}

@Test
public void testViewAndMaterializedViewTogether()
{
if (!hasBehavior(SUPPORTS_CREATE_MATERIALIZED_VIEW) || !hasBehavior(SUPPORTS_CREATE_VIEW)) {
return;
}
// Validate that it is possible to have views and materialized views defined at the same time and both are operational

String schemaName = getSession().getSchema().orElseThrow();

String regularViewName = "test_views_together_normal_" + randomTableSuffix();
assertUpdate("CREATE VIEW " + regularViewName + " AS SELECT * FROM region");

String materializedViewName = "test_views_together_materialized_" + randomTableSuffix();
assertUpdate("CREATE MATERIALIZED VIEW " + materializedViewName + " AS SELECT * FROM nation");

// both should be accessible via information_schema.views
// TODO: actually it is not the cased now hence overridable `checkInformationSchemaViewsForMaterializedView`
assertThat(query("SELECT table_name FROM information_schema.views WHERE table_schema = '" + schemaName + "'"))
.skippingTypesCheck()
.containsAll("VALUES '" + regularViewName + "'");
checkInformationSchemaViewsForMaterializedView(schemaName, materializedViewName);

// check we can query from both
assertThat(query("SELECT * FROM " + regularViewName)).containsAll("SELECT * FROM region");
assertThat(query("SELECT * FROM " + materializedViewName)).containsAll("SELECT * FROM nation");

assertUpdate("DROP VIEW " + regularViewName);
assertUpdate("DROP MATERIALIZED VIEW " + materializedViewName);
}

// TODO inline when all implementations fixed
protected void checkInformationSchemaViewsForMaterializedView(String schemaName, String viewName)
{
Expand Down

0 comments on commit 71e0566

Please sign in to comment.