jonvex commented on code in PR #13711:
URL: https://github.com/apache/hudi/pull/13711#discussion_r2281046060


##########
hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroWrapperUtils.java:
##########
@@ -238,4 +231,121 @@ private static Pair<Boolean, String> 
getIsValueWrapperObfuscated(Object statsVal
     }
     return Pair.of(false, null);
   }
+
+  public enum PrimitiveWrapperType {
+    V1(Object.class, HoodieAvroWrapperUtils::wrapValueIntoAvro, 
HoodieAvroWrapperUtils::unwrapAvroValueWrapper),
+    NULL(Void.class, HoodieAvroWrapperUtils::wrapNull, 
HoodieAvroWrapperUtils::unwrapNull),
+    BOOLEAN(Boolean.class, HoodieAvroWrapperUtils::wrapBoolean, 
HoodieAvroWrapperUtils::unwrapBoolean),
+    INT(Integer.class, HoodieAvroWrapperUtils::wrapInt, 
HoodieAvroWrapperUtils::unwrapInt),
+    LONG(Long.class, HoodieAvroWrapperUtils::wrapLong, 
HoodieAvroWrapperUtils::unwrapLong),
+    FLOAT(Float.class, HoodieAvroWrapperUtils::wrapFloat, 
HoodieAvroWrapperUtils::unwrapFloat),
+    DOUBLE(Double.class, HoodieAvroWrapperUtils::wrapDouble, 
HoodieAvroWrapperUtils::unwrapDouble),
+    STRING(String.class, HoodieAvroWrapperUtils::wrapString, 
HoodieAvroWrapperUtils::unwrapString),
+    BYTES(ByteBuffer.class, HoodieAvroWrapperUtils::wrapBytes, 
HoodieAvroWrapperUtils::unwrapBytes);
+
+    private final Class<?> clazz;
+    private final Function<Comparable<?>, Object> wrapper;
+    private final Function<Object, Comparable<?>> unwrapper;
+
+    PrimitiveWrapperType(Class<?> clazz, Function<Comparable<?>, Object> 
wrapper, Function<Object, Comparable<?>> unwrapper) {
+      this.clazz = clazz;
+      this.wrapper = wrapper;
+      this.unwrapper = unwrapper;
+    }
+
+    Class<?> getClazz() {
+      return clazz;
+    }
+
+    Object wrap(Comparable<?> value) {
+      return wrapper.apply(value);
+    }
+
+    Comparable<?> unwrap(Object value) {
+      return unwrapper.apply(value);
+    }
+  }
+
+  private static Object wrapNull(Comparable<?> value) {
+    return value;
+  }
+
+  private static Object wrapBoolean(Comparable<?> value) {
+    return 
BooleanWrapper.newBuilder(BOOLEAN_WRAPPER_BUILDER_STUB.get()).setValue((Boolean)
 value).build();
+  }
+
+  private static Object wrapInt(Comparable<?> value) {
+    return 
IntWrapper.newBuilder(INT_WRAPPER_BUILDER_STUB.get()).setValue((Integer) 
value).build();
+  }
+
+  private static Object wrapLong(Comparable<?> value) {
+    return 
LongWrapper.newBuilder(LONG_WRAPPER_BUILDER_STUB.get()).setValue((Long) 
value).build();
+  }
+
+  private static Object wrapFloat(Comparable<?> value) {
+    return 
FloatWrapper.newBuilder(FLOAT_WRAPPER_BUILDER_STUB.get()).setValue((Float) 
value).build();
+  }
+
+  private static Object wrapDouble(Comparable<?> value) {
+    return 
DoubleWrapper.newBuilder(DOUBLE_WRAPPER_BUILDER_STUB.get()).setValue((Double) 
value).build();
+  }
+
+  private static Object wrapString(Comparable<?> value) {
+    return 
StringWrapper.newBuilder(STRING_WRAPPER_BUILDER_STUB.get()).setValue((String) 
value).build();
+  }
+
+  private static Object wrapBytes(Comparable<?> value) {
+    return 
BytesWrapper.newBuilder(BYTES_WRAPPER_BUILDER_STUB.get()).setValue((ByteBuffer) 
value).build();
+  }
+
+  public static Object wrapArray(Comparable<?> value, Function<Comparable<?>, 
Object> wrapper) {
+    List<Object> avroValues = OrderingValues.getValues((ArrayComparable) 
value).stream().map(wrapper::apply).collect(Collectors.toList());
+    return 
ArrayWrapper.newBuilder(ARRAY_WRAPPER_BUILDER_STUB.get()).setWrappedValues(avroValues).build();
+  }
+
+  private static Comparable<?> unwrapNull(Object val) {
+    return (Comparable<?>) val;
+  }
+
+  private static Comparable<?> unwrapBoolean(Object val) {
+    return ((BooleanWrapper) val).getValue();
+  }
+
+  private static Comparable<?> unwrapInt(Object val) {
+    return ((IntWrapper) val).getValue();
+  }
+
+  private static Comparable<?> unwrapLong(Object val) {
+    return ((LongWrapper) val).getValue();
+  }
+
+  private static Comparable<?> unwrapFloat(Object val) {
+    return ((FloatWrapper) val).getValue();
+  }
+
+  private static Comparable<?> unwrapDouble(Object val) {
+    return ((DoubleWrapper) val).getValue();
+  }
+
+  private static Comparable<?> unwrapString(Object val) {
+    return ((StringWrapper) val).getValue();
+  }
+
+  private static Comparable<?> unwrapBytes(Object val) {
+    return ((BytesWrapper) val).getValue();
+  }
+
+  public static Comparable<?> unwrapArray(Object val, Function<Object, 
Comparable<?>> unwrapper) {
+    ArrayWrapper arrayWrapper = (ArrayWrapper) val;
+    return OrderingValues.create(arrayWrapper.getWrappedValues().stream()
+        .map(unwrapper::apply)
+        .toArray(Comparable[]::new));
+  }
+
+  // NOTE: This branch could be hit b/c Avro records could be reconstructed
+  //       as {@code GenericRecord)
+  public static Comparable<?> unwrapGenericRecord(Object val) {

Review Comment:
   Investigate more and see if we can improve this



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

Reply via email to