This is an automated email from the ASF dual-hosted git repository.
skadam pushed a commit to branch 4.x-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x-HBase-1.3 by this push:
new e728720 PHOENIX-5209 Cannot add non-PK column to table when the last
PK column is of type VARBINARY or ARRAY
e728720 is described below
commit e728720a8c7e8e50d5f464eabca1eea3ac476e86
Author: Toshihiro Suzuki <[email protected]>
AuthorDate: Sun Jun 9 22:25:18 2019 +0900
PHOENIX-5209 Cannot add non-PK column to table when the last PK column is
of type VARBINARY or ARRAY
Signed-off-by: s.kadam <[email protected]>
---
.../org/apache/phoenix/end2end/AlterTableIT.java | 24 ++++++++++++++++++++++
.../org/apache/phoenix/schema/MetaDataClient.java | 17 +++++++++++----
2 files changed, 37 insertions(+), 4 deletions(-)
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 c9b2ab1..669f1c1 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
@@ -1387,5 +1387,29 @@ public class AlterTableIT extends
ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testAddNonPKColumnWhenlastPKIsVARBINARYOrARRAY() throws
Exception {
+ String tableName1 = generateUniqueName();
+ String tableName2 = generateUniqueName();
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);
+ Statement stmt = conn.createStatement()) {
+ conn.setAutoCommit(false);
+
+ String ddl = "CREATE TABLE " + tableName1 + " (id VARBINARY
PRIMARY KEY, "
+ + "col1 INTEGER)";
+ stmt.execute(ddl);
+
+ String alterDdl = "ALTER TABLE " + tableName1 + " ADD col2
INTEGER";
+ stmt.execute(alterDdl);
+
+ String ddl2 = "CREATE TABLE " + tableName2 + " (id INTEGER ARRAY
PRIMARY KEY, "
+ + "col1 INTEGER)";
+ stmt.execute(ddl2);
+
+ String alterDdl2 = "ALTER TABLE " + tableName2 + " ADD col2
INTEGER";
+ stmt.execute(alterDdl2);
+ }
+ }
}
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 b9f22a9..093cd2e 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
@@ -3606,15 +3606,24 @@ public class MetaDataClient {
int position = table.getColumns().size();
- List<PColumn> currentPKs = table.getPKColumns();
- if (numCols > 0) {
+ boolean addPKColumns = false;
+ for (ColumnDef columnDef : columnDefs) {
+ if (columnDef.isPK()) {
+ addPKColumns = true;
+ break;
+ }
+ }
+ if (addPKColumns) {
+ List<PColumn> currentPKs = table.getPKColumns();
PColumn lastPK = currentPKs.get(currentPKs.size()-1);
- // Disallow adding columns if the last column is VARBIANRY.
+ // Disallow adding columns if the last column in the
primary key is VARBIANRY
+ // or ARRAY.
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.
+ // Disallow adding columns if last column in the primary
key 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();