phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [10/15] git commit: PHOENIX-1385 Adding, dropping and adding columns fails with NPE (Samarth Jain, James Taylor)
Date Wed, 29 Oct 2014 00:02:05 GMT
PHOENIX-1385 Adding, dropping and adding columns fails with NPE (Samarth Jain, James Taylor)


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

Branch: refs/heads/3.2
Commit: 2681601164441f6868e8472c40ed461cdac32c36
Parents: f468759
Author: James Taylor <jtaylor@salesforce.com>
Authored: Mon Oct 27 13:35:49 2014 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Mon Oct 27 13:45:32 2014 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/AlterTableIT.java    | 22 +++++++-
 .../apache/phoenix/jdbc/PhoenixConnection.java  |  8 +--
 .../query/ConnectionQueryServicesImpl.java      |  4 +-
 .../query/ConnectionlessQueryServicesImpl.java  |  6 +--
 .../query/DelegateConnectionQueryServices.java  |  6 +--
 .../apache/phoenix/query/MetaDataMutated.java   |  2 +-
 .../apache/phoenix/schema/MetaDataClient.java   |  6 +--
 .../apache/phoenix/schema/PMetaDataImpl.java    | 53 +++++++++++---------
 8 files changed, 64 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/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 b17c1bd..9c14f16 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
@@ -884,4 +884,24 @@ public class AlterTableIT extends BaseHBaseManagedTimeIT {
         pstmt2.close();
         conn1.close();
     }
-}
+    
+    @Test
+    public void testAddColumnsUsingNewConnection() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        String ddl = "CREATE TABLE T (\n"
+                +"ID1 VARCHAR(15) NOT NULL,\n"
+                +"ID2 VARCHAR(15) NOT NULL,\n"
+                +"CREATED_DATE DATE,\n"
+                +"CREATION_TIME BIGINT,\n"
+                +"LAST_USED DATE,\n"
+                +"CONSTRAINT PK PRIMARY KEY (ID1, ID2))";
+        Connection conn1 = DriverManager.getConnection(getUrl(), props);
+        conn1.createStatement().execute(ddl);
+        ddl = "ALTER TABLE T ADD STRING VARCHAR, STRING_DATA_TYPES VARCHAR";
+        conn1.createStatement().execute(ddl);
+        ddl = "ALTER TABLE T DROP COLUMN STRING, STRING_DATA_TYPES";
+        conn1.createStatement().execute(ddl);
+        ddl = "ALTER TABLE T ADD STRING_ARRAY1 VARCHAR[]";
+        conn1.createStatement().execute(ddl);
+        conn1.close();
+    }}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index 7eced73..75f9f55 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -697,11 +697,11 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
     }
 
     @Override
-    public PMetaData removeColumn(PName tenantId, String tableName, String familyName, String
columnName,
-            long tableTimeStamp, long tableSeqNum) throws SQLException {
-        metaData = metaData.removeColumn(tenantId, tableName, familyName, columnName, tableTimeStamp,
tableSeqNum);
+    public PMetaData removeColumn(PName tenantId, String tableName, List<PColumn> columnsToRemove,
long tableTimeStamp,
+            long tableSeqNum) throws SQLException {
+        metaData = metaData.removeColumn(tenantId, tableName, columnsToRemove, tableTimeStamp,
tableSeqNum);
         //Cascade through to connectionQueryServices too
-        getQueryServices().removeColumn(tenantId, tableName, familyName, columnName, tableTimeStamp,
tableSeqNum);
+        getQueryServices().removeColumn(tenantId, tableName, columnsToRemove, tableTimeStamp,
tableSeqNum);
         return metaData;
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index c0552ce..3e46a30 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -480,12 +480,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
     }
 
     @Override
-    public PMetaData removeColumn(final PName tenantId, final String tableName, final String
familyName, final String columnName, final long tableTimeStamp, final long tableSeqNum) throws
SQLException {
+    public PMetaData removeColumn(final PName tenantId, final String tableName, final List<PColumn>
columnsToRemove, final long tableTimeStamp, final long tableSeqNum) throws SQLException {
         return metaDataMutated(tenantId, tableName, tableSeqNum, new Mutator() {
             @Override
             public PMetaData mutate(PMetaData metaData) throws SQLException {
                 try {
-                    return metaData.removeColumn(tenantId, tableName, familyName, columnName,
tableTimeStamp, tableSeqNum);
+                    return metaData.removeColumn(tenantId, tableName, columnsToRemove, tableTimeStamp,
tableSeqNum);
                 } catch (TableNotFoundException e) {
                     // The DROP TABLE may have been processed first, so just ignore.
                     return metaData;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
index c372802..7d0a109 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
@@ -150,9 +150,9 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices
imple
     }
 
     @Override
-    public PMetaData removeColumn(PName tenantId, String tableName, String familyName, String
columnName,
-            long tableTimeStamp, long tableSeqNum) throws SQLException {
-        return metaData = metaData.removeColumn(tenantId, tableName, familyName, columnName,
tableTimeStamp, tableSeqNum);
+    public PMetaData removeColumn(PName tenantId, String tableName, List<PColumn> columnsToRemove,
long tableTimeStamp,
+            long tableSeqNum) throws SQLException {
+        return metaData = metaData.removeColumn(tenantId, tableName, columnsToRemove, tableTimeStamp,
tableSeqNum);
     }
 
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
index bb4bb33..defad5b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
@@ -88,9 +88,9 @@ public class DelegateConnectionQueryServices extends DelegateQueryServices
imple
     }
 
     @Override
-    public PMetaData removeColumn(PName tenantId, String tableName, String familyName, String
columnName,
-            long tableTimeStamp, long tableSeqNum) throws SQLException {
-        return getDelegate().removeColumn(tenantId, tableName, familyName, columnName, tableTimeStamp,
tableSeqNum);
+    public PMetaData removeColumn(PName tenantId, String tableName, List<PColumn> columnsToRemove,
long tableTimeStamp,
+            long tableSeqNum) throws SQLException {
+        return getDelegate().removeColumn(tenantId, tableName, columnsToRemove, tableTimeStamp,
tableSeqNum);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java b/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
index 1b8ebda..cd4e2de 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
@@ -37,5 +37,5 @@ public interface MetaDataMutated {
     PMetaData addTable(PTable table) throws SQLException;
     PMetaData removeTable(PName tenantId, String tableName, String parentTableName, long
tableTimeStamp) throws SQLException;
     PMetaData addColumn(PName tenantId, String tableName, List<PColumn> columns, long
tableTimeStamp, long tableSeqNum, boolean isImmutableRows) throws SQLException;
-    PMetaData removeColumn(PName tenantId, String tableName, String familyName, String columnName,
long tableTimeStamp, long tableSeqNum) throws SQLException;
+    PMetaData removeColumn(PName tenantId, String tableName, List<PColumn> columnsToRemove,
long tableTimeStamp, long tableSeqNum) throws SQLException;
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/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 5ce2f93..0efbad6 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
@@ -2160,10 +2160,8 @@ public class MetaDataClient {
                     // If we've done any index metadata updates, don't bother trying to update
                     // client-side cache as it would be too painful. Just let it pull it
over from
                     // the server when needed.
-                    if (columnsToDrop.size() > 0 && indexesToDrop.isEmpty()) {
-                        for(PColumn columnToDrop : tableColumnsToDrop) {
-                            connection.removeColumn(tenantId, SchemaUtil.getTableName(schemaName,
tableName) , columnToDrop.getFamilyName().getString(), columnToDrop.getName().getString(),
result.getMutationTime(), seqNum);
-                        }
+                    if (tableColumnsToDrop.size() > 0 && indexesToDrop.isEmpty())
{
+                        connection.removeColumn(tenantId, SchemaUtil.getTableName(schemaName,
tableName) , tableColumnsToDrop, result.getMutationTime(), seqNum);
                     }
                     // If we have a VIEW, then only delete the metadata, and leave the table
data alone
                     if (table.getType() != PTableType.VIEW) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26816011/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
index 8b26709..0d75aa2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
@@ -365,38 +365,41 @@ public class PMetaDataImpl implements PMetaData {
     }
     
     @Override
-    public PMetaData removeColumn(PName tenantId, String tableName, String familyName, String
columnName, long tableTimeStamp, long tableSeqNum) throws SQLException {
+    public PMetaData removeColumn(PName tenantId, String tableName, List<PColumn> columnsToRemove,
long tableTimeStamp, long tableSeqNum) throws SQLException {
         PTableRef tableRef = metaData.get(new PTableKey(tenantId, tableName));
         if (tableRef == null) {
             return this;
         }
         PTable table = tableRef.table;
         PTableCache tables = metaData.clone();
-        PColumn column;
-        if (familyName == null) {
-            column = table.getPKColumn(columnName);
-        } else {
-            column = table.getColumnFamily(familyName).getColumn(columnName);
-        }
-        int positionOffset = 0;
-        int position = column.getPosition();
-        List<PColumn> oldColumns = table.getColumns();
-        if (table.getBucketNum() != null) {
-            position--;
-            positionOffset = 1;
-            oldColumns = oldColumns.subList(positionOffset, oldColumns.size());
-        }
-        List<PColumn> columns = Lists.newArrayListWithExpectedSize(oldColumns.size()
- 1);
-        columns.addAll(oldColumns.subList(0, position));
-        // Update position of columns that follow removed column
-        for (int i = position+1; i < oldColumns.size(); i++) {
-            PColumn oldColumn = oldColumns.get(i);
-            PColumn newColumn = new PColumnImpl(oldColumn.getName(), oldColumn.getFamilyName(),
oldColumn.getDataType(), oldColumn.getMaxLength(), oldColumn.getScale(), oldColumn.isNullable(),
i-1+positionOffset, oldColumn.getSortOrder(), oldColumn.getArraySize(), oldColumn.getViewConstant(),
oldColumn.isViewReferenced());
-            columns.add(newColumn);
+        for (PColumn columnToRemove : columnsToRemove) {
+            PColumn column;
+            String familyName = columnToRemove.getFamilyName().getString();
+            if (familyName == null) {
+                column = table.getPKColumn(columnToRemove.getName().getString());
+            } else {
+                column = table.getColumnFamily(familyName).getColumn(columnToRemove.getName().getString());
+            }
+            int positionOffset = 0;
+            int position = column.getPosition();
+            List<PColumn> oldColumns = table.getColumns();
+            if (table.getBucketNum() != null) {
+                position--;
+                positionOffset = 1;
+                oldColumns = oldColumns.subList(positionOffset, oldColumns.size());
+            }
+            List<PColumn> columns = Lists.newArrayListWithExpectedSize(oldColumns.size()
- 1);
+            columns.addAll(oldColumns.subList(0, position));
+            // Update position of columns that follow removed column
+            for (int i = position+1; i < oldColumns.size(); i++) {
+                PColumn oldColumn = oldColumns.get(i);
+                PColumn newColumn = new PColumnImpl(oldColumn.getName(), oldColumn.getFamilyName(),
oldColumn.getDataType(), oldColumn.getMaxLength(), oldColumn.getScale(), oldColumn.isNullable(),
i-1+positionOffset, oldColumn.getSortOrder(), oldColumn.getArraySize(), oldColumn.getViewConstant(),
oldColumn.isViewReferenced());
+                columns.add(newColumn);
+            }
+            
+            table = PTableImpl.makePTable(table, tableTimeStamp, tableSeqNum, columns);
         }
-        
-        PTable newTable = PTableImpl.makePTable(table, tableTimeStamp, tableSeqNum, columns);
-        tables.put(newTable.getKey(), newTable);
+        tables.put(table.getKey(), table);
         return new PMetaDataImpl(tables);
     }
 


Mime
View raw message