Github user ramkrish86 commented on a diff in the pull request:

    https://github.com/apache/incubator-phoenix/pull/8#discussion_r10005433
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java ---
    @@ -160,44 +236,85 @@ public static void 
positionAtArrayElement(ImmutableBytesWritable ptr, int arrayI
                                        // So inorder to know the length of the 
4th element we will read the offset of 4th element and the offset of 5th 
element.
                                        // Subtracting the offset of 5th 
element and 4th element will give the length of 4th element
                                        // So we could just skip reading the 
other elements.
    +                                   
                                        if(useShort) {
                                                // If the arrayIndex is already 
the last element then read the last before one element and the last element
                                                offset = indexOffset + 
(Bytes.SIZEOF_SHORT * arrayIndex);
                                                if (arrayIndex == (noOfElements 
- 1)) {
                                                        currOff = 
Bytes.toShort(bytes, offset, baseSize) + Short.MAX_VALUE;
    +                                                   ptr.set(bytes, currOff 
+ initPos, 1);
    +                                                   
if(ptr.compareTo(QueryConstants.SEPARATOR_BYTE_ARRAY) == 0) {
    +                                                       // null found
    +                                                       currOff+=2;
    --- End diff --
    
    What ever the null element points to is nothing but the offset where we 
have marked the null counter prefixed with a seprator byte. Hence the currOff i 
would add +2 to it so that while calculating the next element's length these 2 
bytes are avoided.  
    The subtraction of the seperator byte at the end of the curr element is 
done below 
    
         +                                      if(currOff + initPos + 
elementLength == indexOffset) {
         +                                          // Subtract 3 bytes - 1 for 
the seperator for the element and the 2 sepeator bytes at the end
         +                                          ptr.set(bytes, currOff + 
initPos, elementLength - 3);
         +                                      } else {
         +                                          // In case of odd number of 
elements the end seperator would not be there
         +                                          ptr.set(bytes, currOff + 
initPos, elementLength - 1);
         +                                      }


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to