Github user JamesRTaylor commented on a diff in the pull request:
https://github.com/apache/incubator-phoenix/pull/8#discussion_r10005946
--- 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 --
All this method needs to do is set a bytes ptr to the element at a given
position. The loop is confusing IHMO. The byte at the offset of a null element
should point to a zero byte. Does it?
I think all this code could be replaced with those three lines I included
above without any loop. You just need a helper function that gives you the
offset given a position (taking into account if the offsets are stored as
shorts versus ints).
---
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.
---