You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2017/03/09 23:02:44 UTC

[31/50] [abbrv] phoenix git commit: PHOENIX-3703 Immutable multitenant tables created as non-encoded irrespective of encoding property

PHOENIX-3703 Immutable multitenant tables created as non-encoded irrespective of encoding property


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

Branch: refs/heads/omid
Commit: c387260cd87dc931f418e9cf35bf0d29d5cd8b7e
Parents: 6d36fa7
Author: Samarth <sa...@salesforce.com>
Authored: Tue Feb 28 17:57:55 2017 -0800
Committer: Samarth <sa...@salesforce.com>
Committed: Tue Feb 28 17:57:55 2017 -0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/CreateTableIT.java   | 85 +++++++++++++++++++-
 .../apache/phoenix/schema/MetaDataClient.java   | 30 +++----
 2 files changed, 97 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c387260c/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
index 633d93c..cec95f4 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
@@ -31,7 +31,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.List;
-import java.util.Map.Entry;
 import java.util.Properties;
 
 import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -44,13 +43,11 @@ import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.NewerTableAlreadyExistsException;
 import org.apache.phoenix.schema.PTable;
-import org.apache.phoenix.schema.PTable.EncodedCQCounter;
 import org.apache.phoenix.schema.PTable.ImmutableStorageScheme;
 import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.schema.SchemaNotFoundException;
 import org.apache.phoenix.schema.TableAlreadyExistsException;
-import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
@@ -559,4 +556,86 @@ public class CreateTableIT extends BaseClientManagedTimeIT {
         assertEquals(expectedEncodingScheme, table.getEncodingScheme());
         assertEquals(expectedStorageScheme, table.getImmutableStorageScheme());
     }
+    
+    @Test
+    public void testMultiTenantImmutableTableMetadata() throws Exception {
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        String nonEncodedOneCellPerColumnMultiTenantTable = "nonEncodedOneCellPerColumnMultiTenantTable".toUpperCase();
+        String twoByteQualifierEncodedOneCellPerColumnMultiTenantTable = "twoByteQualifierEncodedOneCellPerColumnMultiTenantTable"
+                .toUpperCase();
+        String oneByteQualifierEncodedOneCellPerColumnMultiTenantTable = "oneByteQualifierEncodedOneCellPerColumnMultiTenantTable"
+                .toUpperCase();
+        String twoByteQualifierSingleCellArrayWithOffsetsMultitenantTable = "twoByteQualifierSingleCellArrayWithOffsetsMultitenantTable"
+                .toUpperCase();
+        String oneByteQualifierSingleCellArrayWithOffsetsMultitenantTable = "oneByteQualifierSingleCellArrayWithOffsetsMultitenantTable"
+                .toUpperCase();
+        String createTableDDL;
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            createTableDDL = "create IMMUTABLE TABLE " + nonEncodedOneCellPerColumnMultiTenantTable + " ("
+                    + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL,"
+                    + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) MULTI_TENANT=true, COLUMN_ENCODED_BYTES=0";
+            conn.createStatement().execute(createTableDDL);
+            assertColumnEncodingMetadata(QualifierEncodingScheme.NON_ENCODED_QUALIFIERS,
+                    ImmutableStorageScheme.ONE_CELL_PER_COLUMN, nonEncodedOneCellPerColumnMultiTenantTable, conn);
+        }
+        ts = nextTimestamp();
+        props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            createTableDDL = "create IMMUTABLE table " + twoByteQualifierEncodedOneCellPerColumnMultiTenantTable + " ("
+                    + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL,"
+                    + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) MULTI_TENANT=true";
+            conn.createStatement().execute(createTableDDL);
+            assertColumnEncodingMetadata(QualifierEncodingScheme.TWO_BYTE_QUALIFIERS,
+                    ImmutableStorageScheme.ONE_CELL_PER_COLUMN,
+                    twoByteQualifierEncodedOneCellPerColumnMultiTenantTable, conn);
+        }
+        ts = nextTimestamp();
+        props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            createTableDDL = "create IMMUTABLE table " + oneByteQualifierEncodedOneCellPerColumnMultiTenantTable + " ("
+                    + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL,"
+                    + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) MULTI_TENANT=true, COLUMN_ENCODED_BYTES = 1";
+            conn.createStatement().execute(createTableDDL);
+            assertColumnEncodingMetadata(QualifierEncodingScheme.ONE_BYTE_QUALIFIERS,
+                    ImmutableStorageScheme.ONE_CELL_PER_COLUMN,
+                    oneByteQualifierEncodedOneCellPerColumnMultiTenantTable, conn);
+        }
+        ts = nextTimestamp();
+        props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            createTableDDL = "create IMMUTABLE table "
+                    + twoByteQualifierSingleCellArrayWithOffsetsMultitenantTable
+                    + " ("
+                    + " id char(1) NOT NULL,"
+                    + " col1 integer NOT NULL,"
+                    + " col2 bigint NOT NULL,"
+                    + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) MULTI_TENANT=true, IMMUTABLE_STORAGE_SCHEME=SINGLE_CELL_ARRAY_WITH_OFFSETS";
+            conn.createStatement().execute(createTableDDL);
+            assertColumnEncodingMetadata(QualifierEncodingScheme.TWO_BYTE_QUALIFIERS,
+                    ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS,
+                    twoByteQualifierSingleCellArrayWithOffsetsMultitenantTable, conn);
+        }
+        ts = nextTimestamp();
+        props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            createTableDDL = "create IMMUTABLE table "
+                    + oneByteQualifierSingleCellArrayWithOffsetsMultitenantTable
+                    + " ("
+                    + " id char(1) NOT NULL,"
+                    + " col1 integer NOT NULL,"
+                    + " col2 bigint NOT NULL,"
+                    + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) MULTI_TENANT=true, IMMUTABLE_STORAGE_SCHEME=SINGLE_CELL_ARRAY_WITH_OFFSETS, COLUMN_ENCODED_BYTES=1";
+            conn.createStatement().execute(createTableDDL);
+            assertColumnEncodingMetadata(QualifierEncodingScheme.ONE_BYTE_QUALIFIERS,
+                    ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS,
+                    oneByteQualifierSingleCellArrayWithOffsetsMultitenantTable, conn);
+
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c387260c/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 c8179e8..262047c 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
@@ -2144,34 +2144,34 @@ public class MetaDataClient {
                     if (isImmutableRows) {
                         immutableStorageScheme =
                                 (ImmutableStorageScheme) TableProperty.IMMUTABLE_STORAGE_SCHEME
-                                        .getValue(tableProps);
+                                .getValue(tableProps);
                         if (immutableStorageScheme == null) {
                             if (multiTenant) {
                                 immutableStorageScheme =
                                         ImmutableStorageScheme
-                                                .valueOf(connection
-                                                        .getQueryServices()
-                                                        .getProps()
-                                                        .get(
-                                                            QueryServices.DEFAULT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
-                                                            QueryServicesOptions.DEFAULT_MULTITENANT_IMMUTABLE_STORAGE_SCHEME));
+                                        .valueOf(connection
+                                                .getQueryServices()
+                                                .getProps()
+                                                .get(
+                                                        QueryServices.DEFAULT_MULTITENANT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
+                                                        QueryServicesOptions.DEFAULT_MULTITENANT_IMMUTABLE_STORAGE_SCHEME));
                             } else {
                                 immutableStorageScheme =
                                         ImmutableStorageScheme
-                                                .valueOf(connection
-                                                        .getQueryServices()
-                                                        .getProps()
-                                                        .get(
-                                                            QueryServices.DEFAULT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
-                                                            QueryServicesOptions.DEFAULT_IMMUTABLE_STORAGE_SCHEME));
+                                        .valueOf(connection
+                                                .getQueryServices()
+                                                .getProps()
+                                                .get(
+                                                        QueryServices.DEFAULT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
+                                                        QueryServicesOptions.DEFAULT_IMMUTABLE_STORAGE_SCHEME));
                             }
                         }
                         if (immutableStorageScheme != ONE_CELL_PER_COLUMN
                                 && encodingScheme == NON_ENCODED_QUALIFIERS) {
                             throw new SQLExceptionInfo.Builder(
                                     SQLExceptionCode.INVALID_IMMUTABLE_STORAGE_SCHEME_AND_COLUMN_QUALIFIER_BYTES)
-                                    .setSchemaName(schemaName).setTableName(tableName).build()
-                                    .buildException();
+                            .setSchemaName(schemaName).setTableName(tableName).build()
+                            .buildException();
                         }
                     } 
                 }