virajjasani commented on code in PR #2208:
URL: https://github.com/apache/phoenix/pull/2208#discussion_r2181269689


##########
phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java:
##########
@@ -4047,6 +4032,35 @@ public MutationState dropCDC(DropCDCStatement statement) 
throws SQLException {
         }
     }
 
+    private void deleteAllStreamMetadataForTable(String tableName) throws 
SQLException {
+        String deleteStreamStatusQuery = "DELETE FROM " + 
SYSTEM_CDC_STREAM_STATUS_NAME + " WHERE TABLE_NAME = ?";
+        String deleteStreamPartitionsQuery = "DELETE FROM " + 
SYSTEM_CDC_STREAM_STATUS_NAME + " WHERE TABLE_NAME = ?";

Review Comment:
   They both are referring to the same table



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCStreamIT.java:
##########
@@ -168,6 +172,31 @@ public void testOnlyOneStreamAllowed() throws Exception {
         assertStreamStatus(conn, tableName, streamName, 
CDCUtil.CdcStreamStatus.ENABLING);
     }
 
+    @Test
+    public void testStreamMetadataWhenTableIsDropped() throws SQLException {
+        Connection conn = newConnection();
+        String schemaName = "\"" + generateUniqueName().toLowerCase() + "\"";
+        String tableName = SchemaUtil.getTableName(schemaName, "\"" + 
generateUniqueName().toLowerCase() + "\"");
+        String create_table_sql = "CREATE TABLE  " + tableName + " ( k INTEGER 
PRIMARY KEY," + " v1 INTEGER, v2 DATE)";
+        conn.createStatement().execute(create_table_sql);
+        String cdcName = "\"" + generateUniqueName().toLowerCase() + "\"";
+        String cdc_sql = "CREATE CDC " + cdcName + " ON " + tableName;
+        conn.createStatement().execute(cdc_sql);
+        String drop_table_sql = "DROP TABLE " + tableName;
+        conn.createStatement().execute(drop_table_sql);
+        // check if stream metadata is cleared
+        Assert.assertNull(new 
MetaDataClient(conn.unwrap(PhoenixConnection.class))
+                
.getStreamNameIfCDCEnabled(SchemaUtil.getUnEscapedFullName(tableName)));
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT * FROM SYSTEM.CDC_STREAM WHERE TABLE_NAME='" + 
tableName + "'");
+        Assert.assertFalse(rs.next());
+        // should be able to re-create same table with same cdc name
+        conn.createStatement().execute(create_table_sql);
+        conn.createStatement().execute(cdc_sql);
+        Assert.assertNotNull(new 
MetaDataClient(conn.unwrap(PhoenixConnection.class))
+                
.getStreamNameIfCDCEnabled(SchemaUtil.getUnEscapedFullName(tableName)));

Review Comment:
   nit: can we do `CREATE TABLE` and `CREATE CDC` for same table and cdc object 
here to confirm it goes through?



-- 
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: issues-unsubscr...@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to