You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/12/17 02:57:49 UTC

[GitHub] [phoenix] gokceni commented on a change in pull request #1021: PHOENIX-6267 View Index PK Fixed Width Field Truncation

gokceni commented on a change in pull request #1021:
URL: https://github.com/apache/phoenix/pull/1021#discussion_r544774816



##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
##########
@@ -458,6 +457,113 @@ public void testMultiTenantViewGlobalIndex() throws Exception {
         }
     }
 
+    @Test
+    public void testRowKeyComposition() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            // View fixed, index variable
+            createTableForRowKeyTests(conn, "DATE_TIME1, INT1", "TEXT1");
+
+            // Variable lens in the middle. Both end with fixed
+            createTableForRowKeyTests(conn, "DATE_TIME1, TEXT1, TEXT3, INT1",
+                    "TEXT1, TEXT4, EMAIL1 DESC, DATE_TIME1 DESC, DOUBLE1");
+            createTableForRowKeyTests(conn, "DATE_TIME1, TEXT1, TEXT3, INT1",
+                    "TEXT1, TEXT4, EMAIL1, DATE_TIME1 DESC, DOUBLE1");
+            createTableForRowKeyTests(conn, "DATE_TIME1, TEXT1, INT1",
+                    "TEXT1, DATE_TIME1 DESC, DOUBLE1");
+            createTableForRowKeyTests(conn, "DATE_TIME1, TEXT1, INT1",
+                    "TEXT1, DATE_TIME1 DESC, INT1, DOUBLE1");
+
+            // index ends with fix length, data var length
+            createTableForRowKeyTests(conn, "DATE_TIME1, INT1, EMAIL1",
+                    "TEXT1, DATE_TIME1 DESC, DOUBLE1");
+
+            // Desc separators
+            createTableForRowKeyTests(conn, "DATE_TIME1, INT1", "TEXT1 DESC");
+            createTableForRowKeyTests(conn, "DATE_TIME1, INT1 DESC", "TEXT1 DESC");
+            createTableForRowKeyTests(conn, "DATE_TIME1, INT1 DESC", "TEXT1");
+            createTableForRowKeyTests(conn,"DATE_TIME1, TEXT3 DESC, INT1 DESC, TEXT2 DESC, TEXT4 DESC", "TEXT1 DESC, DOUBLE1 DESC");
+            createTableForRowKeyTests(conn, "DATE_TIME1 DESC, TEXT3 DESC, INT1, DOUBLE1 DESC", "TEXT1");
+
+            // Both index and data end with var length
+            createTableForRowKeyTests(conn,"DATE_TIME1 DESC, TEXT3 DESC, INT1, TEXT4, EMAIL1", "TEXT1");
+            createTableForRowKeyTests(conn,"DATE_TIME1 DESC, TEXT3, INT1, EMAIL1", "TEXT1, TEXT4");
+        }
+    }
+
+    private void createTableForRowKeyTests(Connection conn, String viewPkColumns, String indexPKColumns)
+            throws SQLException {
+        final String fullTableName = "TBL_"+generateUniqueName();
+        final String fullViewName = "VW_" + generateUniqueName();
+        final String fullIndexName = "IDX_" + generateUniqueName();
+        String keyPrefix = "9Ab";
+        String tableDdl = String.format("CREATE TABLE IF NOT EXISTS %s "
+                + "   (ORGANIZATION_ID CHAR(15) NOT NULL, KEY_PREFIX CHAR(3) NOT NULL, LAST_UPDATE DATE "
+                + "   CONSTRAINT PK PRIMARY KEY (ORGANIZATION_ID, KEY_PREFIX)"
+                + " )VERSIONS=1, IMMUTABLE_ROWS=%s, MULTI_TENANT=%s, REPLICATION_SCOPE=1, IMMUTABLE_STORAGE_SCHEME=ONE_CELL_PER_COLUMN, COLUMN_ENCODED_BYTES=0", fullTableName, (isNamespaceMapped? "true" : "false"),(isNamespaceMapped? "true" : "false"));
+        String viewDdl = String.format("CREATE VIEW IF NOT EXISTS %s (DATE_TIME1 DATE NOT NULL, TEXT1 VARCHAR, TEXT3 VARCHAR, INT1 BIGINT NOT NULL, DATE_TIME2 DATE, DATE_TIME3 DATE, INT2 BIGINT, INT3 INTEGER, DOUBLE1 DECIMAL(12, 3), "
+                + "DOUBLE2 DECIMAL(12, 3), DOUBLE3 DECIMAL(12, 3), TEXT2 VARCHAR, TEXT4 VARCHAR, EMAIL1 VARCHAR, PHONE1 VARCHAR, URL1 VARCHAR "

Review comment:
       @gjacoby126 Let's keep it so that we can play with more scenarios in the future :) 
   
   I had to change the code a bit because unit tests were failing. Now the code looks more like the the datarowkey generation. 




----------------------------------------------------------------
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:
users@infra.apache.org