[ https://issues.apache.org/jira/browse/PHOENIX-6267?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17251416#comment-17251416 ]
ASF GitHub Bot commented on PHOENIX-6267: ----------------------------------------- kadirozde commented on a change in pull request #1021: URL: https://github.com/apache/phoenix/pull/1021#discussion_r545496221 ########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java ########## @@ -458,6 +457,116 @@ public void testMultiTenantViewGlobalIndex() throws Exception { } } + @Test + public void testRowKeyComposition() throws Exception { + // For this test we are mapping isNamespaceEnabled to immutable, multitenant table + + try (Connection conn = DriverManager.getConnection(getUrl())) { + // View fixed, index variable + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, INT1", "TEXT1"); + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, INT1, TEXT4", "TEXT1"); + + // Variable lens in the middle. Both end with fixed + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, TEXT1, TEXT3, INT1", + "TEXT1, TEXT4, EMAIL1 DESC, DATE_TIME1 DESC, DOUBLE1"); + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, TEXT1, TEXT3, INT1", + "TEXT1, TEXT4, EMAIL1, DATE_TIME1 DESC, DOUBLE1"); + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, TEXT1, INT1", + "TEXT1, DATE_TIME1 DESC, DOUBLE1"); + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, TEXT1, INT1", + "TEXT1, DATE_TIME1 DESC, INT1, DOUBLE1"); + + // index ends with fix length, data var length + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, INT1, EMAIL1", + "TEXT1, DATE_TIME1 DESC, DOUBLE1"); + + // Desc separators + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, INT1", "TEXT1 DESC"); + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, INT1 DESC", "TEXT1 DESC"); + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1, INT1 DESC", "TEXT1"); + createTableForRowKeyTestsAndVerify(conn,"DATE_TIME1, TEXT3 DESC, INT1 DESC, TEXT2 DESC, TEXT4 DESC", "TEXT1 DESC, DOUBLE1 DESC"); + createTableForRowKeyTestsAndVerify(conn, "DATE_TIME1 DESC, TEXT3 DESC, INT1, DOUBLE1 DESC", "TEXT1"); Review comment: For example, Base table PK: PK1 View table PK : PK2 Index table PK : PK2, PK1, PK3 where where PK3 is nullable INTEGER in one case and CHAR[] in the other ---------------------------------------------------------------- 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: us...@infra.apache.org > View Index PK Fixed Width Field Truncation > ------------------------------------------- > > Key: PHOENIX-6267 > URL: https://issues.apache.org/jira/browse/PHOENIX-6267 > Project: Phoenix > Issue Type: Bug > Affects Versions: 5.0.0, 4.15.0, 4.14.3 > Reporter: Geoffrey Jacoby > Assignee: Gokcen Iskender > Priority: Blocker > Fix For: 5.1.0, 4.16.0 > > Attachments: PHOENIX-6267.4.x.001.patch, PHOENIX-6267.4.x.002.patch, > PHOENIX-6267.master.001.patch, PHOENIX-6267.master.002.patch, > PHOENIX-6267.master.003.patch, PHOENIX-6267.master.004.patch > > > 1. Create a table T > 2. Create a view V that extends the PK of T, where the last field of the > view's PK is a fixed width column C such as an INTEGER or BIGINT > 3. Create a view index VI on V that does NOT contain C in its index key > 4. Select C from the view with a query that runs against the view index > You will get the following error: > {code:java} > java.sql.SQLException: ERROR 201 (22000): Illegal data. Expected length of > at least 8 bytes, but had 7 > {code} > [~giskender], [~kadir], [~tkhurana] and I investigated. It appears the > problem comes from > IndexMaintainer.buildRowKey:707-713 > {code:java} > int length = stream.size(); > int minLength = length - maxTrailingNulls; > byte[] indexRowKey = stream.getBuffer(); > // Remove trailing nulls > while (length > minLength && indexRowKey[length-1] == > QueryConstants.SEPARATOR_BYTE) { > length--; > } > {code} > The logic to remove trailing separator bytes shouldn't run if the end of the > index key (i.e the end of the base PK) is a fixed width column. Otherwise, > we'll truncate whenever the last byte of the fixed width field happens to be > \x00 > > This only happens for view indexes (mutitenant or not) -- This message was sent by Atlassian Jira (v8.3.4#803005)