Github user ramkrish86 commented on a diff in the pull request:
https://github.com/apache/incubator-phoenix/pull/8#discussion_r10120847
--- Diff:
phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java ---
@@ -123,83 +189,69 @@ public Object toObject(byte[] bytes, int offset, int
length, PDataType baseType,
return createPhoenixArray(bytes, offset, length, sortOrder,
baseType);
}
-
- public static void positionAtArrayElement(ImmutableBytesWritable ptr,
int arrayIndex, PDataType baseDataType) {
- byte[] bytes = ptr.get();
- int initPos = ptr.getOffset();
- int noOfElements = 0;
- noOfElements = Bytes.toInt(bytes, ptr.getOffset() +
Bytes.SIZEOF_BYTE, Bytes.SIZEOF_INT);
- int noOFElementsSize = Bytes.SIZEOF_INT;
- if(arrayIndex >= noOfElements) {
- throw new IndexOutOfBoundsException(
- "Invalid index "
- + arrayIndex
- + " specified, greater
than the no of elements in the array: "
- + noOfElements);
- }
- boolean useShort = true;
- int baseSize = Bytes.SIZEOF_SHORT;
- if (noOfElements < 0) {
- noOfElements = -noOfElements;
- baseSize = Bytes.SIZEOF_INT;
- useShort = false;
- }
- if (baseDataType.getByteSize() == null) {
- int offset = ptr.getOffset() + noOFElementsSize +
Bytes.SIZEOF_BYTE;
- int indexOffset = Bytes.toInt(bytes, offset) +
ptr.getOffset();
- int valArrayPostion = offset + Bytes.SIZEOF_INT;
- offset += Bytes.SIZEOF_INT;
- int currOff = 0;
- if (noOfElements > 1) {
- while (offset <= (initPos+ptr.getLength())) {
- int nextOff = 0;
- // Skip those many offsets as given in
the arrayIndex
- // If suppose there are 5 elements in
the array and the arrayIndex = 3
- // This means we need to read the 4th
element of the array
- // 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;
- nextOff = indexOffset;
- offset += baseSize;
- } else {
- currOff =
Bytes.toShort(bytes, offset, baseSize) + Short.MAX_VALUE;
- offset += baseSize;
- nextOff =
Bytes.toShort(bytes, offset, baseSize) + Short.MAX_VALUE;
- offset += baseSize;
- }
- } else {
- // If the arrayIndex is already
the last element then read the last before one element and the last element
- offset = indexOffset +
(Bytes.SIZEOF_INT * arrayIndex);
- if (arrayIndex == (noOfElements
- 1)) {
- currOff =
Bytes.toInt(bytes, offset, baseSize);
- nextOff = indexOffset;
- offset += baseSize;
- } else {
- currOff =
Bytes.toInt(bytes, offset, baseSize);
- offset += baseSize;
- nextOff =
Bytes.toInt(bytes, offset, baseSize);
- offset += baseSize;
- }
- }
- int elementLength = nextOff - currOff;
- ptr.set(bytes, currOff + initPos,
elementLength);
- break;
- }
- } else {
- ptr.set(bytes, valArrayPostion + initPos,
indexOffset - valArrayPostion);
- }
- } else {
- ptr.set(bytes,
- ptr.getOffset() + arrayIndex *
baseDataType.getByteSize()
- + noOFElementsSize +
Bytes.SIZEOF_BYTE, baseDataType.getByteSize());
- }
- }
+ public static void positionAtArrayElement(ImmutableBytesWritable ptr,
int arrayIndex, PDataType baseDataType) {
+ byte[] bytes = ptr.get();
+ int initPos = ptr.getOffset();
+ int noOfElements = 0;
+ noOfElements = Bytes.toInt(bytes, (ptr.getOffset() +
ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)),
+ Bytes.SIZEOF_INT);
+
+ if (arrayIndex >= noOfElements) { throw new
IndexOutOfBoundsException("Invalid index " + arrayIndex
+ + " specified, greater than the no of eloements in the
array: " + noOfElements); }
+ boolean useShort = true;
+ if (noOfElements < 0) {
+ noOfElements = -noOfElements;
+ useShort = false;
+ }
+
+ if (baseDataType.getByteSize() == null) {
--- End diff --
Should a character array be created with String of single element or
Character[]. Using Character[] creates an issue here
@Override
public int estimateByteSize(Object o) {
String value = (String) o;
return value.length();
}
So we need to use the String[]. Also passing expression.getByteSize() also
gives null only. Should we explicity read only one byte. This was the reason
why i added a || saying isCoercible(VARCHAR).
---
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.
---