|
139 | 139 | import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_MULTI_STATEMENT_WRITES;
|
140 | 140 | import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_NEGATIVE_DATE;
|
141 | 141 | import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_NOT_NULL_CONSTRAINT;
|
| 142 | +import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_REFRESH_VIEW; |
142 | 143 | import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_COLUMN;
|
143 | 144 | import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_FIELD;
|
144 | 145 | import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_MATERIALIZED_VIEW;
|
@@ -988,6 +989,46 @@ public void testView()
|
988 | 989 | .doesNotContain(testView);
|
989 | 990 | }
|
990 | 991 |
|
| 992 | + @Test |
| 993 | + public void testRefreshView() |
| 994 | + { |
| 995 | + if (!hasBehavior(SUPPORTS_REFRESH_VIEW)) { |
| 996 | + if (hasBehavior(SUPPORTS_CREATE_VIEW)) { |
| 997 | + try (TestView testView = new TestView(getQueryRunner()::execute, "test_view", " SELECT * FROM nation")) { |
| 998 | + assertQueryFails("ALTER VIEW %s REFRESH".formatted(testView.getName()), "This connector does not refreshing views"); |
| 999 | + } |
| 1000 | + } |
| 1001 | + else { |
| 1002 | + assertQueryFails("CREATE VIEW sample_view AS SELECT * FROM nation", "This connector does not support creating views"); |
| 1003 | + } |
| 1004 | + return; |
| 1005 | + } |
| 1006 | + |
| 1007 | + if (!hasBehavior(SUPPORTS_CREATE_TABLE) && !hasBehavior(SUPPORTS_ADD_COLUMN)) { |
| 1008 | + throw new AssertionError("Cannot test ALTER VIEW REFRESH without CREATE TABLE, the test needs to be implemented in a connector-specific way"); |
| 1009 | + } |
| 1010 | + |
| 1011 | + try (TestTable table = new TestTable(getQueryRunner()::execute, "test_table", "(id BIGINT, column_to_dropped BIGINT)", ImmutableList.of("1, 2")); |
| 1012 | + TestView view = new TestView(getQueryRunner()::execute, "test_view", " SELECT * FROM %s".formatted(table.getName()))) { |
| 1013 | + assertQuery("SELECT * FROM %s".formatted(view.getName()), "VALUES (1, 2)"); |
| 1014 | + |
| 1015 | + assertUpdate("ALTER TABLE %s ADD COLUMN new_column BIGINT".formatted(table.getName())); |
| 1016 | + assertQueryFails( |
| 1017 | + "SELECT * FROM %s".formatted(view.getName()), |
| 1018 | + ".*is stale or in invalid state: stored view column count \\(2\\) does not match column count derived from the view query analysis \\(3\\)"); |
| 1019 | + |
| 1020 | + assertUpdate("ALTER VIEW %s REFRESH".formatted(view.getName())); |
| 1021 | + assertQuery("SELECT * FROM %s".formatted(view.getName()), "VALUES (1, 2, null)"); |
| 1022 | + |
| 1023 | + assertUpdate("ALTER TABLE %s RENAME COLUMN new_column TO renamed_column".formatted(table.getName())); |
| 1024 | + assertQueryFails( |
| 1025 | + "SELECT * FROM %s".formatted(view.getName()), |
| 1026 | + ".*is stale or in invalid state: column \\[renamed_column] of type bigint projected from query view at position 2 has a different name from column \\[new_column] of type bigint stored in view definition"); |
| 1027 | + assertUpdate("ALTER VIEW %s REFRESH".formatted(view.getName())); |
| 1028 | + assertQuery("SELECT * FROM %s".formatted(view.getName()), "VALUES (1, 2, null)"); |
| 1029 | + } |
| 1030 | + } |
| 1031 | + |
991 | 1032 | @Test
|
992 | 1033 | public void testCreateViewSchemaNotFound()
|
993 | 1034 | {
|
|
0 commit comments