You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/07/16 22:25:18 UTC

[GitHub] [phoenix] yanxinyi opened a new pull request #832: Phoenix 5976 Cannot drop a column when the index view is involved

yanxinyi opened a new pull request #832:
URL: https://github.com/apache/phoenix/pull/832


   


----------------------------------------------------------------
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.

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



[GitHub] [phoenix] ChinmaySKulkarni commented on a change in pull request #832: Phoenix 5976 Cannot drop a column when the index view is involved

Posted by GitBox <gi...@apache.org>.
ChinmaySKulkarni commented on a change in pull request #832:
URL: https://github.com/apache/phoenix/pull/832#discussion_r456642814



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DropColumnMutator.java
##########
@@ -181,13 +183,28 @@ public MetaDataMutationResult validateAndAddMetadata(PTable table,
             byte[] key = mutation.getRow();
             int pkCount = getVarChars(key, rowKeyMetaData);
             if (isView && mutation instanceof Put) {
-                PColumn column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                PColumn column = null;
+                // checking put from the view or index
+                if (Bytes.compareTo(schemaName, rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0
+                        && Bytes.compareTo(tableName, rowKeyMetaData[TABLE_NAME_INDEX]) == 0) {
+                    column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                } else {
+                    for(int i = 0; i < table.getIndexes().size(); i++) {

Review comment:
       Synced offline with @yanxinyi . Missed that we have an `isView` check in the outer if condition. Thanks




----------------------------------------------------------------
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.

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



[GitHub] [phoenix] yanxinyi commented on pull request #832: Phoenix 5976 Cannot drop a column when the index view is involved

Posted by GitBox <gi...@apache.org>.
yanxinyi commented on pull request #832:
URL: https://github.com/apache/phoenix/pull/832#issuecomment-659709406


   The DropColumnMutator didn't check whether is view or view index and caused no column found exception. Adding this extra check for the drop column path and a few test cases. 
   
   @ChinmaySKulkarni  Please take a look, thanks.


----------------------------------------------------------------
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.

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



[GitHub] [phoenix] twdsilva commented on a change in pull request #832: Phoenix 5976 Cannot drop a column when the index view is involved

Posted by GitBox <gi...@apache.org>.
twdsilva commented on a change in pull request #832:
URL: https://github.com/apache/phoenix/pull/832#discussion_r456848509



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DropColumnMutator.java
##########
@@ -181,13 +183,28 @@ public MetaDataMutationResult validateAndAddMetadata(PTable table,
             byte[] key = mutation.getRow();
             int pkCount = getVarChars(key, rowKeyMetaData);
             if (isView && mutation instanceof Put) {
-                PColumn column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                PColumn column = null;
+                // checking put from the view or index
+                if (Bytes.compareTo(schemaName, rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0
+                        && Bytes.compareTo(tableName, rowKeyMetaData[TABLE_NAME_INDEX]) == 0) {
+                    column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                } else {
+                    for(int i = 0; i < table.getIndexes().size(); i++) {
+                        PTableImpl indexTable = (PTableImpl) table.getIndexes().get(i);
+                        byte[] indexTableName = indexTable.getTableName().getBytes();
+                        byte[] indexSchema = indexTable.getSchemaName().getBytes();
+                        if (Bytes.compareTo(indexSchema, rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0
+                                && Bytes.compareTo(indexTableName, rowKeyMetaData[TABLE_NAME_INDEX]) == 0) {
+                            column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, indexTable);
+                            break;
+                        }
+                    }
+                }
                 if (column == null)
                     continue;
                 // ignore any puts that modify the ordinal positions of columns

Review comment:
       I think this was to handle older clients that update ordinal column positions when a column is dropped. 




----------------------------------------------------------------
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.

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



[GitHub] [phoenix] yanxinyi commented on pull request #832: Phoenix 5976 Cannot drop a column when the index view is involved

Posted by GitBox <gi...@apache.org>.
yanxinyi commented on pull request #832:
URL: https://github.com/apache/phoenix/pull/832#issuecomment-660317760


   Added two new tests
   1. drop a column from the table and this column is included in the index table.
   2. drop a column from the table with a child view.
   
   
   @ChinmaySKulkarni as we discuss offline, I'm going to create another JIRA for fixing the ordinal position issue. 


----------------------------------------------------------------
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.

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



[GitHub] [phoenix] yanxinyi closed pull request #832: Phoenix 5976 Cannot drop a column when the index view is involved

Posted by GitBox <gi...@apache.org>.
yanxinyi closed pull request #832:
URL: https://github.com/apache/phoenix/pull/832


   


----------------------------------------------------------------
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.

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



[GitHub] [phoenix] ChinmaySKulkarni commented on a change in pull request #832: Phoenix 5976 Cannot drop a column when the index view is involved

Posted by GitBox <gi...@apache.org>.
ChinmaySKulkarni commented on a change in pull request #832:
URL: https://github.com/apache/phoenix/pull/832#discussion_r456585611



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DropColumnMutator.java
##########
@@ -80,7 +81,8 @@ public DropColumnMutator(Configuration conf) {
     }
 
     @Override
-    public MutateColumnType getMutateColumnType() {
+    public MutateColumnType getMutateColumnType()
+    {

Review comment:
       nit: remove this diff

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java
##########
@@ -411,5 +412,126 @@ public void testDroppingIndexedColDropsIndex() throws Exception {
             assertNull(results.next());
         }
     }
-    
+
+    @Test
+    public void testDropViewIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropViewIndexColumnForMultiTenantTable() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS "  + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX)) MULTI_TENANT=TRUE");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS "  + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM "  + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL, NON_PK1 CHAR(15),NON_PK2 CHAR(15), " +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + table +" (KEY_PREFIX, ID) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER TABLE " + table + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropColumnForMultiTenantTable() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL, NON_PK3 CHAR(15)," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX)) MULTI_TENANT=TRUE");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " +  view  + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+                // drop column
+                stmt.execute("ALTER VIEW " + view + " DROP COLUMN NON_PK3");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropColumnForMultiTenantTableWithIndex() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL, NON_PK3 CHAR(15)," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX)) MULTI_TENANT=TRUE");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " +  view  + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+
+                stmt.execute("CREATE INDEX " + index + " ON " + view +" (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+
+                // drop column
+                stmt.execute("ALTER VIEW " + view + " DROP COLUMN NON_PK3");
+            }
+        } catch (Exception e) {

Review comment:
       ditto

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java
##########
@@ -411,5 +412,126 @@ public void testDroppingIndexedColDropsIndex() throws Exception {
             assertNull(results.next());
         }
     }
-    
+
+    @Test
+    public void testDropViewIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {

Review comment:
       No need to catch here

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java
##########
@@ -411,5 +412,126 @@ public void testDroppingIndexedColDropsIndex() throws Exception {
             assertNull(results.next());
         }
     }
-    
+
+    @Test
+    public void testDropViewIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropViewIndexColumnForMultiTenantTable() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS "  + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX)) MULTI_TENANT=TRUE");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS "  + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM "  + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {

Review comment:
       Same here, no need to catch exception and fail. Just let it propagate up

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java
##########
@@ -411,5 +412,126 @@ public void testDroppingIndexedColDropsIndex() throws Exception {
             assertNull(results.next());
         }
     }
-    
+
+    @Test
+    public void testDropViewIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropViewIndexColumnForMultiTenantTable() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS "  + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX)) MULTI_TENANT=TRUE");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS "  + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM "  + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL, NON_PK1 CHAR(15),NON_PK2 CHAR(15), " +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + table +" (KEY_PREFIX, ID) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER TABLE " + table + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropColumnForMultiTenantTable() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL, NON_PK3 CHAR(15)," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX)) MULTI_TENANT=TRUE");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " +  view  + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+                // drop column
+                stmt.execute("ALTER VIEW " + view + " DROP COLUMN NON_PK3");
+            }
+        } catch (Exception e) {

Review comment:
       ditto

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java
##########
@@ -411,5 +412,126 @@ public void testDroppingIndexedColDropsIndex() throws Exception {
             assertNull(results.next());
         }
     }
-    
+
+    @Test
+    public void testDropViewIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS " + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM " + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropViewIndexColumnForMultiTenantTable() throws Exception {
+        String table = generateUniqueName();
+        String view = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS "  + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL," +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX)) MULTI_TENANT=TRUE");
+                // create view
+                stmt.execute(
+                        "CREATE VIEW IF NOT EXISTS "  + view + "  (PK1 DATE NOT NULL,PK2 CHAR(15) NOT NULL," +
+                                "NON_PK1 CHAR(15),NON_PK2 CHAR(15) CONSTRAINT PKVIEW PRIMARY KEY (PK1,PK2)) " +
+                                "AS SELECT * FROM "  + table + " WHERE KEY_PREFIX = '123'");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + view + " (PK2, PK1) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER VIEW "  + view + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void testDropIndexColumn() throws Exception {
+        String table = generateUniqueName();
+        String index = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE IF NOT EXISTS " + table + " (ID CHAR(10) NOT NULL,KEY_PREFIX CHAR(3) NOT NULL, NON_PK1 CHAR(15),NON_PK2 CHAR(15), " +
+                        " CONSTRAINT PK PRIMARY KEY (ID,KEY_PREFIX))");
+                // create index
+                stmt.execute("CREATE INDEX " + index + " ON " + table +" (KEY_PREFIX, ID) INCLUDE (NON_PK1, NON_PK2)");
+                // drop column
+                stmt.execute("ALTER TABLE " + table + " DROP COLUMN NON_PK1");
+            }
+        } catch (Exception e) {

Review comment:
       ditto

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DropColumnMutator.java
##########
@@ -181,13 +183,28 @@ public MetaDataMutationResult validateAndAddMetadata(PTable table,
             byte[] key = mutation.getRow();
             int pkCount = getVarChars(key, rowKeyMetaData);
             if (isView && mutation instanceof Put) {
-                PColumn column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                PColumn column = null;
+                // checking put from the view or index
+                if (Bytes.compareTo(schemaName, rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0
+                        && Bytes.compareTo(tableName, rowKeyMetaData[TABLE_NAME_INDEX]) == 0) {
+                    column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                } else {
+                    for(int i = 0; i < table.getIndexes().size(); i++) {
+                        PTableImpl indexTable = (PTableImpl) table.getIndexes().get(i);
+                        byte[] indexTableName = indexTable.getTableName().getBytes();
+                        byte[] indexSchema = indexTable.getSchemaName().getBytes();
+                        if (Bytes.compareTo(indexSchema, rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0
+                                && Bytes.compareTo(indexTableName, rowKeyMetaData[TABLE_NAME_INDEX]) == 0) {
+                            column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, indexTable);
+                            break;
+                        }
+                    }
+                }
                 if (column == null)
                     continue;
                 // ignore any puts that modify the ordinal positions of columns

Review comment:
       Do we know why we are ignoring puts that modify ordinal positions?
   FYI @twdsilva 

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DropColumnMutator.java
##########
@@ -181,13 +183,28 @@ public MetaDataMutationResult validateAndAddMetadata(PTable table,
             byte[] key = mutation.getRow();
             int pkCount = getVarChars(key, rowKeyMetaData);
             if (isView && mutation instanceof Put) {
-                PColumn column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                PColumn column = null;
+                // checking put from the view or index
+                if (Bytes.compareTo(schemaName, rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0
+                        && Bytes.compareTo(tableName, rowKeyMetaData[TABLE_NAME_INDEX]) == 0) {
+                    column = MetaDataUtil.getColumn(pkCount, rowKeyMetaData, table);
+                } else {
+                    for(int i = 0; i < table.getIndexes().size(); i++) {

Review comment:
       Is this required even when the parent is a table (table_type='u') or only needed when it is a view (table_type='v')?




----------------------------------------------------------------
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.

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