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

    https://github.com/apache/incubator-phoenix/pull/8#discussion_r10001103
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java ---
    @@ -77,9 +130,47 @@ public int toBytes(Object object, byte[] bytes, int 
offset) {
             if (array == null || array.baseType == null) {
                 return 0;
             }
    -       return PDataType.fromTypeId((array.baseType.getSqlType() + 
Types.ARRAY)).estimateByteSize(object);
    +        return estimateByteSize(object, null, 
PDataType.fromTypeId((array.baseType.getSqlType() + Types.ARRAY)));
        }
     
    +   // Estimates the size of the given array and also calculates the number 
of nulls and its repetition factor
    +    public int estimateByteSize(Object o, Pair<Integer, Integer> 
nullsVsNullRepeationCounter, PDataType baseType) {
    +        if (baseType.isFixedWidth()) { return baseType.getByteSize(); }
    +        if (baseType.isArrayType()) {
    +            PhoenixArray array = (PhoenixArray)o;
    +            int noOfElements = array.numElements;
    +            int totalVarSize = 0;
    +            int nullsRepeationCounter = 0;
    +            int nulls = 0;
    +            int totalNulls = 0;
    +            for (int i = 0; i < noOfElements; i++) {
    +                totalVarSize += array.estimateByteSize(i);
    +                if (!PDataType.fromTypeId((baseType.getSqlType() - 
Types.ARRAY)).isFixedWidth()) {
    +                    if (array.isNull(i)) {
    +                        nulls++;
    +                    } else {
    +                        if (nulls > 0) {
    +                            totalNulls += nulls;
    --- End diff --
    
    Are you punting on having this size be correct if there are nulls that 
repeat more than 255 times? If so (and I think this is fine, as it's probably 
an edge case), please add a comment here to that effect.


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