exceptionfactory commented on code in PR #6013:
URL: https://github.com/apache/nifi/pull/6013#discussion_r868321774
##########
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java:
##########
@@ -233,6 +237,36 @@ public static Object convertType(final Object value, final
DataType dataType, fi
return null;
}
+ private static Object toUUID(Object value) {
+ if (value instanceof String) {
+ try {
+ return UUID.fromString((String)value);
+ } catch (Exception ex) {
+ throw new IllegalTypeConversionException(String.format("Could
not parse %s into a UUID", value), ex);
+ }
+ } else if (value instanceof byte[]) {
+ return uuidFromBytes((byte[])value);
+ } else if (value instanceof Byte[]) {
+ Byte[] array = (Byte[])value;
+ byte[] converted = new byte[array.length];
+ for (int x = 0; x < array.length; x++) {
+ converted[x] = array[x];
+ }
+ return uuidFromBytes(converted);
+ } else {
+ throw new IllegalTypeConversionException(value.getClass() + "
cannot be converted into a UUID");
Review Comment:
Is it possible for `value` to be `null` here, or is the caller of `toUUID()`
expected to filter out `null` values?
##########
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java:
##########
@@ -712,6 +746,20 @@ public static Object[] toArray(final Object value, final
String fieldName, final
return dest;
}
+ if (value instanceof UUID) {
+ UUID uuid = (UUID)value;
+ ByteBuffer buffer = ByteBuffer.allocate(16);
+ buffer.putLong(uuid.getMostSignificantBits());
+ buffer.putLong(uuid.getLeastSignificantBits());
+ Byte[] result = new Byte[16];
+ byte[] array = buffer.array();
+ for (int index = 0; index < array.length; index++) {
+ result[index] = array[index];
+ }
+
+ return result;
Review Comment:
What is the reason for returning an object `Byte[]` type versus a primitive
`byte[]` type? It makes sense to support both types on the `toUUID()` method,
but not following why the representation here is `Byte[]`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]