PHOENIX-3445 Add a CREATE IMMUTABLE TABLE construct to make immutable tables more explicit
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/be6861c8 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/be6861c8 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/be6861c8 Branch: refs/heads/encodecolumns2 Commit: be6861c8963d8ee05caa4c5aabc78fd05bd59605 Parents: 01ef5d5 Author: Thomas D'Silva <tdsi...@salesforce.com> Authored: Mon Nov 28 17:08:27 2016 -0800 Committer: Thomas D'Silva <tdsi...@salesforce.com> Committed: Thu Dec 22 13:03:27 2016 -0800 ---------------------------------------------------------------------- .../apache/phoenix/end2end/AlterTableIT.java | 40 +++++++++++++++++++- .../phoenix/end2end/AlterTableWithViewsIT.java | 4 ++ .../apache/phoenix/schema/MetaDataClient.java | 4 ++ 3 files changed, 47 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/be6861c8/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 173a3be..3084a92 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 @@ -2502,6 +2502,44 @@ public class AlterTableIT extends ParallelStatsDisabledIT { assertFalse(rs.next()); } } - + + @Test + public void testAlterImmutableRowsPropertyForOneCellPerKeyValueColumnStorageScheme() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + String ddl = "CREATE TABLE " + dataTableFullName + " (\n" + +"ID VARCHAR(15) NOT NULL,\n" + +"CREATED_DATE DATE,\n" + +"CREATION_TIME BIGINT,\n" + +"CONSTRAINT PK PRIMARY KEY (ID))"; + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.createStatement().execute(ddl); + assertImmutableRows(conn, dataTableFullName, false); + ddl = "ALTER TABLE " + dataTableFullName + " SET IMMUTABLE_ROWS = true"; + conn.createStatement().execute(ddl); + assertImmutableRows(conn, dataTableFullName, true); + } + + @Test + public void testAlterImmutableRowsPropertyForOneCellPerColumnFamilyStorageScheme() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + String ddl = "CREATE TABLE " + dataTableFullName + " (\n" + +"ID VARCHAR(15) NOT NULL,\n" + +"CREATED_DATE DATE,\n" + +"CREATION_TIME BIGINT,\n" + +"CONSTRAINT PK PRIMARY KEY (ID)) IMMUTABLE_ROWS=true"; + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.createStatement().execute(ddl); + assertImmutableRows(conn, dataTableFullName, true); + try { + ddl = "ALTER TABLE " + dataTableFullName + " SET IMMUTABLE_ROWS = false"; + conn.createStatement().execute(ddl); + fail(); + } + catch(SQLException e) { + assertEquals(SQLExceptionCode.CANNOT_ALTER_IMMUTABLE_ROWS_PROPERTY.getErrorCode(), e.getErrorCode()); + } + assertImmutableRows(conn, dataTableFullName, true); + } + } http://git-wip-us.apache.org/repos/asf/phoenix/blob/be6861c8/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java index e0bbb10..310071f 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java @@ -19,6 +19,7 @@ package org.apache.phoenix.end2end; import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE; import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -32,6 +33,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.Arrays; import java.util.Collection; +import java.util.Properties; import org.apache.commons.lang.ArrayUtils; import org.apache.hadoop.hbase.client.HTableInterface; @@ -45,6 +47,8 @@ import org.apache.phoenix.schema.PNameFactory; import org.apache.phoenix.schema.PTable; import org.apache.phoenix.schema.PTableKey; import org.apache.phoenix.schema.PTableType; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.SchemaUtil; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; http://git-wip-us.apache.org/repos/asf/phoenix/blob/be6861c8/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 a7144bb..06aa479 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 @@ -3049,6 +3049,10 @@ public class MetaDataClient { Boolean isImmutableRows = null; if (isImmutableRowsProp != null) { if (isImmutableRowsProp.booleanValue() != table.isImmutableRows()) { + if (table.getStorageScheme() != StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN) { + throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_IMMUTABLE_ROWS_PROPERTY) + .setSchemaName(schemaName).setTableName(tableName).build().buildException(); + } isImmutableRows = isImmutableRowsProp; changingPhoenixTableProperty = true; }