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

    https://github.com/apache/incubator-phoenix/pull/8#discussion_r10156848
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java ---
    @@ -214,150 +281,205 @@ public Object toObject(Object object, PDataType 
actualType, SortOrder sortOrder)
                return toObject(object, actualType);
        }
        
    -   // Making this private
        /**
    -    * The format of the byte buffer looks like this for variable length 
array elements
    -    * <noofelements><Offset of the index array><elements><offset array>
    -    * where <noOfelements> - vint
    -    * <offset of the index array> - int
    -    * <elements>  - these are the values
    -    * <offset array> - offset of every element written as INT/SHORT
    -    * 
    +    * ser
    +    * @param byteStream
    +    * @param oStream
         * @param array
    -    * @param buffer
         * @param noOfElements
    -    * @param byteSize
    -    * @param capacity 
    +    * @param baseType
    +    * @param capacity
         * @return
         */
    -   private byte[] bytesFromByteBuffer(PhoenixArray array, ByteBuffer 
buffer,
    -                   int noOfElements, PDataType baseType, int capacity) {
    -           int temp = noOfElements;
    -        if (buffer == null) return null;
    -        buffer.put(ARRAY_SERIALIZATION_VERSION);
    -        buffer.putInt(noOfElements);
    -        if (!baseType.isFixedWidth() || 
baseType.isCoercibleTo(PDataType.VARCHAR)) {
    -            int fillerForOffsetByteArray = buffer.position();
    -            buffer.position(fillerForOffsetByteArray + Bytes.SIZEOF_INT);
    -            ByteBuffer offsetArray = ByteBuffer.allocate(capacity);
    -            if(noOfElements < 0){
    -                   noOfElements = -noOfElements;
    +    private byte[] createArrayBytes(TrustedByteArrayOutputStream 
byteStream, DataOutputStream oStream,
    +            PhoenixArray array, int noOfElements, PDataType baseType) {
    +        try {
    +            if (!baseType.isFixedWidth()) {
    +                int[] offsetPos = new int[noOfElements];
    +                int nulls = 0;
    +                for (int i = 0; i < noOfElements; i++) {
    +                    byte[] bytes = array.toBytes(i);
    +                    if (bytes.length == 0) {
    +                        offsetPos[i] = byteStream.size();
    +                        nulls++;
    +                    } else {
    +                        nulls = serializeNulls(oStream, nulls);
    +                        offsetPos[i] = byteStream.size();
    +                        oStream.write(bytes, 0, bytes.length);
    +                        oStream.write(QueryConstants.SEPARATOR_BYTE);
    +                    }
    +                }
    +                // Double seperator byte to show end of the non null array
    +                PArrayDataType.writeEndSeperatorForVarLengthArray(oStream);
    +                noOfElements = 
PArrayDataType.serailizeOffsetArrayIntoStream(oStream, byteStream, noOfElements,
    +                        offsetPos[offsetPos.length - 1], offsetPos);
    +            } else {
    +                for (int i = 0; i < noOfElements; i++) {
    +                    byte[] bytes = array.toBytes(i);
    +                    int length = bytes.length;
    +                    if(baseType == PDataType.CHAR) {
    --- End diff --
    
    Just do a write first of the bytes, then have a loop that does a write of 
the StringUtil.SPACE_UTF8. Don't allocate another byte array here.


---
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