PHOENIX-4711 Unable to set property on table with VARBINARY as last column
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a18fd1e1 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a18fd1e1 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a18fd1e1 Branch: refs/heads/system-catalog Commit: a18fd1e133f5a2785e0ade236d72028b3d6854da Parents: 49c0232 Author: James Taylor <jtay...@salesforce.com> Authored: Thu Apr 26 17:13:48 2018 -0700 Committer: James Taylor <jtay...@salesforce.com> Committed: Fri Apr 27 11:41:56 2018 -0700 ---------------------------------------------------------------------- .../apache/phoenix/end2end/AlterTableIT.java | 12 ++++++----- .../apache/phoenix/schema/MetaDataClient.java | 22 +++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/a18fd1e1/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 dd895dc..b1949ed 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 @@ -116,12 +116,14 @@ public class AlterTableIT extends ParallelStatsDisabledIT { Connection conn = DriverManager.getConnection(getUrl(), props); conn.setAutoCommit(false); - try { - String ddl = "CREATE TABLE " + dataTableFullName + - " (a_string varchar not null, a_binary varbinary not null, col1 integer" + - " CONSTRAINT pk PRIMARY KEY (a_string, a_binary)) " + tableDDLOptions; - createTestTable(getUrl(), ddl); + String ddl = "CREATE TABLE " + dataTableFullName + + " (a_string varchar not null, a_binary varbinary not null, col1 integer" + + " CONSTRAINT pk PRIMARY KEY (a_string, a_binary)) " + tableDDLOptions; + createTestTable(getUrl(), ddl); + + conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " SET DISABLE_WAL = true"); + try { ddl = "ALTER TABLE " + dataTableFullName + " ADD b_string VARCHAR NULL PRIMARY KEY"; PreparedStatement stmt = conn.prepareStatement(ddl); stmt.execute(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/a18fd1e1/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 b15072a..a3d2baf 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 @@ -3259,16 +3259,18 @@ public class MetaDataClient { int position = table.getColumns().size(); List<PColumn> currentPKs = table.getPKColumns(); - PColumn lastPK = currentPKs.get(currentPKs.size()-1); - // Disallow adding columns if the last column is VARBIANRY. - if (lastPK.getDataType() == PVarbinary.INSTANCE || lastPK.getDataType().isArrayType()) { - throw new SQLExceptionInfo.Builder(SQLExceptionCode.VARBINARY_LAST_PK) - .setColumnName(lastPK.getName().getString()).build().buildException(); - } - // Disallow adding columns if last column is fixed width and nullable. - if (lastPK.isNullable() && lastPK.getDataType().isFixedWidth()) { - throw new SQLExceptionInfo.Builder(SQLExceptionCode.NULLABLE_FIXED_WIDTH_LAST_PK) - .setColumnName(lastPK.getName().getString()).build().buildException(); + if (numCols > 0) { + PColumn lastPK = currentPKs.get(currentPKs.size()-1); + // Disallow adding columns if the last column is VARBIANRY. + if (lastPK.getDataType() == PVarbinary.INSTANCE || lastPK.getDataType().isArrayType()) { + throw new SQLExceptionInfo.Builder(SQLExceptionCode.VARBINARY_LAST_PK) + .setColumnName(lastPK.getName().getString()).build().buildException(); + } + // Disallow adding columns if last column is fixed width and nullable. + if (lastPK.isNullable() && lastPK.getDataType().isFixedWidth()) { + throw new SQLExceptionInfo.Builder(SQLExceptionCode.NULLABLE_FIXED_WIDTH_LAST_PK) + .setColumnName(lastPK.getName().getString()).build().buildException(); + } }