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

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_r545359432



##########
File path: 
phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
##########
@@ -694,16 +696,22 @@ private Void addDataColInfo(final PTable dataTable, 
Expression expression) {
                         output.write(ptr.get(), ptr.getOffset(), 
ptr.getLength());
                     }
                 }
+
                 if (!indexColumnType.isFixedWidth()) {
-                    
output.writeByte(SchemaUtil.getSeparatorByte(rowKeyOrderOptimizable, 
ptr.getLength() == 0, isIndexColumnDesc ? SortOrder.DESC : SortOrder.ASC));
+                    byte sepByte = 
SchemaUtil.getSeparatorByte(rowKeyOrderOptimizable, ptr.getLength() == 0, 
isIndexColumnDesc ? SortOrder.DESC : SortOrder.ASC);
+                    output.writeByte(sepByte);
+                    trailingVariableWitdthColumnNum++;
+                } else {
+                    trailingVariableWitdthColumnNum = 0;
                 }
             }
-            int length = stream.size();
-            int minLength = length - maxTrailingNulls;
             byte[] indexRowKey = stream.getBuffer();
             // Remove trailing nulls
-            while (length > minLength && indexRowKey[length-1] == 
QueryConstants.SEPARATOR_BYTE) {
+            int length = stream.size();
+            int minLength = length - maxTrailingNulls;
+            while (trailingVariableWitdthColumnNum > 0 && length > minLength 
&& indexRowKey[length-1] == QueryConstants.SEPARATOR_BYTE) {

Review comment:
       The existing code does not eliminate the separator if the data type is 
not nullable. It not clear why. The actual bug is in the calculation of 
maxTrailingNulls with view indexes.  So, in order not to impact some other 
cases, we should keep it here.




----------------------------------------------------------------
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.master.001.patch, PHOENIX-6267.master.002.patch, 
> PHOENIX-6267.master.003.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)

Reply via email to