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

    https://github.com/apache/incubator-phoenix/pull/8#discussion_r9980802
  
    --- 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 --
    
    Good catch.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. To do so, please top-post your response.
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
infrastruct...@apache.org or file a JIRA ticket with INFRA.
---

Reply via email to