Skip to content

Commit b2af241

Browse files
committed
Minor cleanup in RefreshView tests
Each connector might have a different way of handling drops and column rename, we use EXCEPT CORRESPONDING clause to ensure the results of the both the views and tables are same. Additionally fixed error message when dropping a column.
1 parent 0cfcbae commit b2af241

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,23 +1008,23 @@ public void testRefreshView()
10081008

10091009
try (TestTable table = newTrinoTable("test_table", "(id BIGINT, column_to_dropped BIGINT, column_to_be_renamed BIGINT, column_with_comment BIGINT)", ImmutableList.of("1, 2, 3, 4"));
10101010
TestView view = new TestView(getQueryRunner()::execute, "test_view", " SELECT * FROM %s".formatted(table.getName()))) {
1011-
assertQuery("SELECT * FROM " + view.getName(), "VALUES (1, 2, 3, 4)");
1011+
assertQueryReturnsEmptyResult("SELECT * FROM " + view.getName() + " EXCEPT CORRESPONDING SELECT * FROM " + table.getName());
10121012

10131013
assertUpdate("ALTER TABLE %s ADD COLUMN new_column BIGINT".formatted(table.getName()));
10141014
assertQueryFails(
10151015
"SELECT * FROM " + view.getName(),
10161016
".*is stale or in invalid state: stored view column count \\(4\\) does not match column count derived from the view query analysis \\(5\\)");
10171017

10181018
assertUpdate("ALTER VIEW %s REFRESH".formatted(view.getName()));
1019-
assertQuery("SELECT * FROM " + view.getName(), "VALUES (1, 2, 3, 4, null)");
1019+
assertQueryReturnsEmptyResult("SELECT * FROM " + view.getName() + " EXCEPT CORRESPONDING SELECT * FROM " + table.getName());
10201020

10211021
if (hasBehavior(SUPPORTS_RENAME_COLUMN)) {
10221022
assertUpdate("ALTER TABLE %s RENAME COLUMN column_to_be_renamed TO renamed_column".formatted(table.getName()));
10231023
assertQueryFails(
10241024
"SELECT * FROM %s".formatted(view.getName()),
10251025
".*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 \\[column_to_be_renamed] of type bigint stored in view definition");
10261026
assertUpdate("ALTER VIEW %s REFRESH".formatted(view.getName()));
1027-
assertQuery("SELECT * FROM " + view.getName(), "VALUES (1, 2, 3, 4, null)");
1027+
assertQueryReturnsEmptyResult("SELECT * FROM " + view.getName() + " EXCEPT CORRESPONDING SELECT * FROM " + table.getName());
10281028
}
10291029

10301030
if (hasBehavior(SUPPORTS_COMMENT_ON_COLUMN)) {
@@ -1035,18 +1035,16 @@ public void testRefreshView()
10351035
assertUpdate("ALTER TABLE %s ADD COLUMN new_column_2 BIGINT".formatted(table.getName()));
10361036
assertUpdate("ALTER VIEW %s REFRESH".formatted(view.getName()));
10371037
assertThat(getColumnComment(view.getName(), "column_with_comment")).isEqualTo("test comment");
1038-
1039-
assertUpdate("ALTER TABLE %s RENAME COLUMN column_with_comment TO renamed_new_column".formatted(table.getName()));
10401038
}
10411039

10421040
if (hasBehavior(SUPPORTS_DROP_COLUMN)) {
10431041
assertUpdate("ALTER TABLE %s DROP COLUMN column_to_dropped".formatted(table.getName()));
10441042
assertQueryFails(
10451043
"SELECT * FROM " + view.getName(),
1046-
".*is stale or in invalid state: stored view column count \\(5\\) does not match column count derived from the view query analysis \\(4\\)");
1044+
".*is stale or in invalid state: stored view column count \\(6\\) does not match column count derived from the view query analysis \\(5\\)");
10471045

10481046
assertUpdate("ALTER VIEW %s REFRESH".formatted(view.getName()));
1049-
assertQuery("SELECT * FROM " + view.getName(), "VALUES (1, 3, 4, null)");
1047+
assertQueryReturnsEmptyResult("SELECT * FROM " + view.getName() + " EXCEPT CORRESPONDING SELECT * FROM " + table.getName());
10501048
}
10511049
}
10521050
}

0 commit comments

Comments
 (0)