phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject [46/50] [abbrv] phoenix git commit: PHOENIX-2389 Adding/dropping multiple columns to table in one DDL statement is broken
Date Tue, 10 Nov 2015 01:19:01 GMT
PHOENIX-2389 Adding/dropping multiple columns to table in one DDL statement is broken


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e1e43441
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e1e43441
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e1e43441

Branch: refs/heads/txn
Commit: e1e434416f157add679f33637138e4374f067d63
Parents: ee435fb
Author: James Taylor <jtaylor@salesforce.com>
Authored: Mon Nov 9 11:09:40 2015 -0800
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Mon Nov 9 11:09:40 2015 -0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/AlterTableIT.java    | 109 +++++++++++++++++++
 .../apache/phoenix/schema/MetaDataClient.java   |   6 +-
 2 files changed, 112 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e1e43441/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index dc47d99..a523fac 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -969,6 +969,115 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
     }
 
     @Test
+    public void testAddMultipleColumns() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        String ddl = "CREATE TABLE T (\n"
+                +"ID VARCHAR(15) PRIMARY KEY,\n"
+                +"COL1 BIGINT)";
+        Connection conn1 = DriverManager.getConnection(getUrl(), props);
+        conn1.createStatement().execute(ddl);
+        conn1.createStatement().execute("CREATE INDEX I ON T(COL1)");
+        
+        ddl = "ALTER TABLE T ADD COL2 VARCHAR PRIMARY KEY, COL3 VARCHAR PRIMARY KEY";
+        conn1.createStatement().execute(ddl);
+        ResultSet rs = conn1.getMetaData().getColumns("", "", "T", null);
+        assertTrue(rs.next());
+        assertEquals("ID",rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("COL1",rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("COL2",rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("COL3",rs.getString(4));
+        assertFalse(rs.next());
+        
+        rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+                + "WHERE TENANT_ID IS NULL AND\n"
+                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'T' AND\n"
+                + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
+        assertTrue(rs.next());
+        assertEquals(4,rs.getInt(1));
+        assertFalse(rs.next());
+
+        rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+                + "WHERE TENANT_ID IS NULL AND\n"
+                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'I' AND\n"
+                + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
+        assertTrue(rs.next());
+        assertEquals(4,rs.getInt(1));
+        assertFalse(rs.next());
+        
+        conn1.createStatement().execute("UPSERT INTO T VALUES ('a',2,'a','b')");
+        conn1.createStatement().execute("UPSERT INTO T VALUES ('b',3,'b','c')");
+        conn1.createStatement().execute("UPSERT INTO T VALUES ('c',4,'c','c')");
+        conn1.commit();
+        
+        rs = conn1.createStatement().executeQuery("SELECT ID,COL1 FROM T WHERE COL1=3");
+        assertTrue(rs.next());
+        assertEquals("b",rs.getString(1));
+        assertEquals(3,rs.getLong(2));
+        assertFalse(rs.next());
+        
+        conn1.close();
+    }
+
+
+    @Test
+    public void testDropMultipleColumns() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        String ddl = "CREATE TABLE T (\n"
+                + "ID VARCHAR(15) PRIMARY KEY,\n"
+                + "COL1 BIGINT,"
+                + "COL2 BIGINT,"
+                + "COL3 BIGINT,"
+                + "COL4 BIGINT)";
+        Connection conn1 = DriverManager.getConnection(getUrl(), props);
+        conn1.createStatement().execute(ddl);
+        conn1.createStatement().execute("CREATE INDEX I ON T(COL1) INCLUDE (COL2,COL3,COL4)");
+        
+        ddl = "ALTER TABLE T DROP COLUMN COL2, COL3";
+        conn1.createStatement().execute(ddl);
+        ResultSet rs = conn1.getMetaData().getColumns("", "", "T", null);
+        assertTrue(rs.next());
+        assertEquals("ID",rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("COL1",rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("COL4",rs.getString(4));
+        assertFalse(rs.next());
+        
+        rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+                + "WHERE TENANT_ID IS NULL AND\n"
+                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'T' AND\n"
+                + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
+        assertTrue(rs.next());
+        assertEquals(3,rs.getInt(1));
+        assertFalse(rs.next());
+
+        rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+                + "WHERE TENANT_ID IS NULL AND\n"
+                + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'I' AND\n"
+                + "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
+        assertTrue(rs.next());
+        assertEquals(3,rs.getInt(1));
+        assertFalse(rs.next());
+        
+        conn1.createStatement().execute("UPSERT INTO T VALUES ('a',2, 20)");
+        conn1.createStatement().execute("UPSERT INTO T VALUES ('b',3, 30)");
+        conn1.createStatement().execute("UPSERT INTO T VALUES ('c',4, 40)");
+        conn1.commit();
+        
+        rs = conn1.createStatement().executeQuery("SELECT ID,COL1,COL4 FROM T WHERE COL1=3");
+        assertTrue(rs.next());
+        assertEquals("b",rs.getString(1));
+        assertEquals(3,rs.getLong(2));
+        assertEquals(30,rs.getLong(3));
+        assertFalse(rs.next());
+        
+        conn1.close();
+    }
+
+    @Test
     public void testAddColumnForNewColumnFamily() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String ddl = "CREATE TABLE testAddColumnForNewColumnFamily (\n"

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e1e43441/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 77ca2c3..82239ea 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -2601,7 +2601,7 @@ public class MetaDataClient {
 
                 if (numPkColumnsAdded>0 && !table.getIndexes().isEmpty()) {
                     for (PTable index : table.getIndexes()) {
-                        incrementTableSeqNum(index, index.getType(), 1);
+                        incrementTableSeqNum(index, index.getType(), numPkColumnsAdded);
                     }
                     tableMetaData.addAll(connection.getMutationState().toMutations().next().getSecond());
                     connection.rollback();
@@ -2831,7 +2831,7 @@ public class MetaDataClient {
                         }
                     }
                     if(!indexColumnsToDrop.isEmpty()) {
-                        incrementTableSeqNum(index, index.getType(), -1);
+                        incrementTableSeqNum(index, index.getType(), -indexColumnsToDrop.size());
                         dropColumnMutations(index, indexColumnsToDrop, tableMetaData);
                     }
 
@@ -2839,7 +2839,7 @@ public class MetaDataClient {
                 tableMetaData.addAll(connection.getMutationState().toMutations().next().getSecond());
                 connection.rollback();
 
-                long seqNum = incrementTableSeqNum(table, statement.getTableType(), -1);
+                long seqNum = incrementTableSeqNum(table, statement.getTableType(), -tableColumnsToDrop.size());
                 tableMetaData.addAll(connection.getMutationState().toMutations().next().getSecond());
                 connection.rollback();
                 // Force table header to be first in list


Mime
View raw message