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

    https://github.com/apache/incubator-phoenix/pull/18#discussion_r10554640
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java ---
    @@ -211,25 +211,33 @@ public boolean 
isSizeCompatible(ImmutableBytesWritable ptr, Object value,
        }
        
        public void coerceBytes(ImmutableBytesWritable ptr, Object value, 
PDataType actualType, Integer maxLength, Integer scale,
    -            Integer desiredMaxLength, Integer desiredScale, PDataType 
desiredType) {
    -       if (ptr.getLength() == 0 || value == null) {
    -           return;
    -       }
    -       if (Objects.equal(maxLength, desiredMaxLength)) {
    -           return;
    -       }
    -       // TODO: handle bit inversion
    -       // TODO: handle coerce between different types
    -       // TODO: validate that maxLength and desiredMaxLength come through 
as expected
    -       // TODO: handle when value == null correct, as you may need to 
re-write due to coercian to different type
    -       // or bit inversion
    -       //FIXME: don't write number of elements in the case of fixed width 
arrays as it will mess up sort order
    -       PhoenixArray pArr = (PhoenixArray) value;
    -       pArr = new PhoenixArray(pArr, desiredMaxLength);
    -        PDataType baseType = PDataType.fromTypeId(actualType.getSqlType()
    -                - PDataType.ARRAY_TYPE_BASE);
    -       ptr.set(toBytes(pArr, baseType));
    -   }
    +            Integer desiredMaxLength, Integer desiredScale, PDataType 
desiredType, 
    +            SortOrder actualModifer, SortOrder expectedModifier) {
    +        if (ptr.getLength() == 0) { // a zero length ptr means null which 
will not be coerced to anything different
    +            return;
    +        }
    +        // If the length is not changing (or there is no fixed length) and
    +        // the existing type and the new type will serialize to the same 
bytes and
    +        // the sort order is not changing, then ptr already points to the 
correct
    +        // set of bytes and there's nothing to do
    +        if ((Objects.equal(maxLength, desiredMaxLength) || maxLength == 
null || desiredMaxLength == null)
    +                && actualType.isBytesComparableWith(desiredType) && 
actualModifer == expectedModifier) { 
    +            return; 
    +        }
    +        if (Objects.equal(maxLength, desiredMaxLength)) { 
    +            return; 
    +        }
    +        // We should call coerceBytes for CHAR as we need to pad up the 
CHAR based on 
    +        // maxLength which will not happen for the other cases
    +        PhoenixArray pArr = (PhoenixArray)value;
    +        // TODO: handle coerce between different types
    --- End diff --
    
    These too?


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