[ 
https://issues.apache.org/jira/browse/PHOENIX-6220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17231717#comment-17231717
 ] 

ASF GitHub Bot commented on PHOENIX-6220:
-----------------------------------------

swaroopak commented on a change in pull request #963:
URL: https://github.com/apache/phoenix/pull/963#discussion_r523134203



##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
##########
@@ -622,6 +622,97 @@ public void testMultiTenantImmutableTableMetadata() throws 
Exception {
         }
     }
 
+    @Test
+    public void testCreateIndexWithDifferentStorageAndEncoding() throws 
Exception {
+        verifyIndexSchemeChange(false, false);
+        verifyIndexSchemeChange(false, true);
+        verifyIndexSchemeChange(true, false);
+        verifyIndexSchemeChange(true, true);
+
+        String tableName = generateUniqueName();
+        String indexName = generateUniqueName();
+        String createTableDDL = "create IMMUTABLE TABLE " + tableName + "(id 
char(1) NOT NULL, col1 char(1), col2 char(1) "
+                + "CONSTRAINT NAME_PK PRIMARY KEY (id)) 
IMMUTABLE_STORAGE_SCHEME=SINGLE_CELL_ARRAY_WITH_OFFSETS";
+        String createIndexDDL = "create INDEX " + indexName + " ON " + 
tableName + " (col1) INCLUDE (col2) 
IMMUTABLE_STORAGE_SCHEME=ONE_CELL_PER_COLUMN";
+
+        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute(createTableDDL);
+            
assertColumnEncodingMetadata(QualifierEncodingScheme.TWO_BYTE_QUALIFIERS,
+                    ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS, 
tableName, conn);
+
+            boolean failed = false;
+            try {
+                conn.createStatement().execute(createIndexDDL);
+            } catch (SQLException e) {
+                assertEquals(e.getErrorCode(), 
SQLExceptionCode.INVALID_IMMUTABLE_STORAGE_SCHEME_CHANGE.getErrorCode());
+                failed = true;
+            }
+            assertEquals(true, failed);
+        }
+    }
+
+    private void verifyIndexSchemeChange(boolean immutable, boolean 
multiTenant) throws Exception{
+        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+        String nonEncodedOneCellPerColumnTable = generateUniqueName();
+        String createTableDDL;
+        String createIndexDDL;
+        String tableName= "[TABLE_NAME]";
+        String indexName= "[INDEX_NAME]";
+        String createTableBaseDDL = "create " + (immutable? " IMMUTABLE ":"") 
+ " TABLE [TABLE_NAME] ("
+                + " id char(1) NOT NULL," + " col1 integer NOT NULL,"
+                + " col2 bigint NOT NULL,"
+                + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) 
MULTI_TENANT=" + (multiTenant? "true,":"false,");
+
+        String createIndexBaseDDL = "create index [INDEX_NAME] ON [TABLE_NAME] 
(col1) INCLUDE (col2) ";
+
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            createTableDDL = createTableBaseDDL.replace(tableName, 
nonEncodedOneCellPerColumnTable);
+            createTableDDL += "IMMUTABLE_STORAGE_SCHEME=ONE_CELL_PER_COLUMN, 
COLUMN_ENCODED_BYTES=0";
+            conn.createStatement().execute(createTableDDL);
+            
assertColumnEncodingMetadata(QualifierEncodingScheme.NON_ENCODED_QUALIFIERS,
+                    ImmutableStorageScheme.ONE_CELL_PER_COLUMN,
+                    nonEncodedOneCellPerColumnTable, conn);
+
+            String idxName = "IDX_" + generateUniqueName();
+            // Don't specify anything to see if it inherits from parent
+            createIndexDDL = createIndexBaseDDL.replace(indexName, 
idxName).replace(tableName, nonEncodedOneCellPerColumnTable);

Review comment:
       This is new! Any reason to not use`String.format()` instead?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


> CREATE INDEX shouldn't ignore IMMUTABLE_STORAGE_SCHEME and 
> COLUMN_ENDCODED_BYTES  
> ----------------------------------------------------------------------------------
>
>                 Key: PHOENIX-6220
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6220
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Gokcen Iskender
>            Assignee: Gokcen Iskender
>            Priority: Major
>         Attachments: PHOENIX-6220.4.x.001.patch, PHOENIX-6220.4.x.002.patch
>
>
> IMMUTABLE_STORAGE_SCHEME and COLUMN_ENCODED_BYTES that is specified in CREATE 
> INDEX needs to be respected. Today, it is ignored and value is just gotten 
> from the parent. Parent table can still use ONE_CELL_PER_COLUMN storage 
> scheme. If the parent table is using COLUMN_ENCODED_BYTES=0 (none), we 
> recommend using COLUMN_ENCODED_BYTES=2 for the index table by default (can be 
> overriden) when SINGLE_CELL storage scheme is used. 2-byte column mapping 
> enables to define 65535 columns which should be enough.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to