gjacoby126 commented on a change in pull request #1341:
URL: https://github.com/apache/phoenix/pull/1341#discussion_r742156665



##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
##########
@@ -82,7 +79,66 @@ private static void verifyNewColumns(ResultSet rs, String 
... values) throws SQL
         assertFalse(rs.next());
         assertEquals(values.length, i - 1);
     }
-    
+
+    @Test
+    public void testCreateAndAlterViewsWithChangeDetectionEnabled() throws 
Exception {
+        String tenantId = "TE_" + generateUniqueName();
+        String schemaName = "S_" + generateUniqueName();
+        String tableName = "T_" + generateUniqueName();
+        String globalViewName = "GV_" + generateUniqueName();
+        String tenantViewName = "TV_" + generateUniqueName();
+        String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
+        String fullGlobalViewName = SchemaUtil.getTableName(schemaName, 
globalViewName);
+        String fullTenantViewName = SchemaUtil.getTableName(schemaName, 
tenantViewName);
+
+        PTable globalView = null;
+        PTable alteredGlobalView = null;
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String ddl = "CREATE TABLE " + fullTableName +
+                " (id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 
bigint NOT NULL," +
+                " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) " +
+                "MULTI_TENANT=true, CHANGE_DETECTION_ENABLED=true";
+            conn.createStatement().execute(ddl);
+            PTable table = PhoenixRuntime.getTableNoCache(conn, fullTableName);
+            assertTrue(table.isChangeDetectionEnabled());
+            AlterTableIT.verifySchemaExport(table, 
getUtility().getConfiguration());
+
+            String globalViewDdl = "CREATE VIEW " + fullGlobalViewName +
+                " (id2 CHAR(12) NOT NULL PRIMARY KEY, col3 BIGINT NULL) " +
+                " AS SELECT * FROM " + fullTableName + " 
CHANGE_DETECTION_ENABLED=true";
+
+            conn.createStatement().execute(globalViewDdl);
+            globalView = PhoenixRuntime.getTableNoCache(conn, 
fullGlobalViewName);
+            assertTrue(globalView.isChangeDetectionEnabled());
+            //   base column count doesn't get set properly
+            PTableImpl.Builder builder = 
PTableImpl.builderFromExisting(globalView);
+            builder.setBaseColumnCount(table.getColumns().size());
+            globalView = builder.setColumns(globalView.getColumns()).build();
+            AlterTableIT.verifySchemaExport(globalView, 
getUtility().getConfiguration());
+
+            String alterViewDdl = "ALTER VIEW " + fullGlobalViewName + " ADD 
id3 VARCHAR(12) NULL "

Review comment:
       Added tests




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to