From 71e05667e3f32cac5b1b935ae03ba21d4fe623be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Osipiuk?= Date: Tue, 13 Jul 2021 17:18:37 +0200 Subject: [PATCH] Add test for VIEWS and MATERIALIZED VIEWS interoperability --- .../io/trino/testing/BaseConnectorTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java index 6565b02997b5..03403a6f9b25 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java @@ -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) {