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

    https://github.com/apache/nifi/pull/2570#discussion_r176436923
  
    --- Diff: 
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
 ---
    @@ -270,11 +290,33 @@ public static boolean isRecordTypeCompatible(final 
Object value) {
                 return (Object[]) value;
             }
     
    +        if (value instanceof String && 
RecordFieldType.BYTE.getDataType().equals(elementDataType)) {
    +            byte[] src = ((String) value).getBytes(charset);
    +            Byte[] dest = new Byte[src.length];
    +            for (int i = 0; i < src.length; i++) {
    +                dest[i] = src[i];
    +            }
    +            return dest;
    +        }
    +
    +        if (value instanceof byte[]) {
    +            byte[] src = (byte[]) value;
    +            Byte[] dest = new Byte[src.length];
    +            for (int i = 0; i < src.length; i++) {
    +                dest[i] = src[i];
    +            }
    +            return dest;
    +        }
    +
             throw new IllegalTypeConversionException("Cannot convert value [" 
+ value + "] of type " + value.getClass() + " to Object Array for field " + 
fieldName);
         }
     
    -    public static boolean isArrayTypeCompatible(final Object value) {
    -        return value != null && value instanceof Object[];
    +    public static boolean isArrayTypeCompatible(final Object value, final 
DataType elementDataType) {
    +        return value != null
    +                // Either an object array or a String to be converted to 
byte[] or a ByteBuffer (from Avro, e.g.)
    +                && (value instanceof Object[]
    +                || (value instanceof String && 
RecordFieldType.BYTE.getDataType().equals(elementDataType))
    +                || value instanceof ByteBuffer);
    --- End diff --
    
    I don't think we should be supporting ByteBuffer here, just byte[]. The 
more we allow for, the more complex this gets and the more error-prone and less 
consistent it will become. While Avro may use ByteBuffers, when we use an Avro 
Reader to create a Record, we should be doing the conversion there from 
ByteBuffer to byte[].


---

Reply via email to