Jackie-Jiang commented on a change in pull request #7402: URL: https://github.com/apache/pinot/pull/7402#discussion_r703811135
########## File path: pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java ########## @@ -1119,13 +1160,11 @@ public PinotDataType getSingleValueType() { } public static PinotDataType getSingleValueType(Class<?> cls) { - PinotDataType pdt = SINGLE_VALUE_TYPE_MAP.get(cls); - return (pdt != null) ? pdt : OBJECT; + return null == cls ? OBJECT : SINGLE_VALUE_TYPE_MAPPING.apply(cls); Review comment: The input can never be `null`, and we can remove the null check here ########## File path: pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java ########## @@ -31,6 +30,8 @@ import org.apache.pinot.spi.utils.JsonUtils; import org.apache.pinot.spi.utils.TimestampUtils; +import static org.apache.pinot.common.utils.MemoizedClassFunction.memoize; Review comment: (code style) avoid static import for production class ########## File path: pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java ########## @@ -776,30 +777,70 @@ public String toString(Object value) { // Mapping Java class type to PinotDataType, for SV and MV value separately. // OBJECT and OBJECT_ARRAY are default type for unknown Java types. - private static final Map<Class<?>, PinotDataType> SINGLE_VALUE_TYPE_MAP = new HashMap<Class<?>, PinotDataType>() {{ - put(Boolean.class, BOOLEAN); - put(Byte.class, BYTE); - put(Character.class, CHARACTER); - put(Short.class, SHORT); - put(Integer.class, INTEGER); - put(Long.class, LONG); - put(Float.class, FLOAT); - put(Double.class, DOUBLE); - put(Timestamp.class, TIMESTAMP); - put(String.class, STRING); - put(byte[].class, BYTES); - }}; - - private static final Map<Class<?>, PinotDataType> MULTI_VALUE_TYPE_MAP = new HashMap<Class<?>, PinotDataType>() {{ - put(Byte.class, BYTE_ARRAY); - put(Character.class, CHARACTER_ARRAY); - put(Short.class, SHORT_ARRAY); - put(Integer.class, INTEGER_ARRAY); - put(Long.class, LONG_ARRAY); - put(Float.class, FLOAT_ARRAY); - put(Double.class, DOUBLE_ARRAY); - put(String.class, STRING_ARRAY); - }}; + private static final Function<Class<?>, PinotDataType> SINGLE_VALUE_TYPE_MAPPING = memoize(cls -> { Review comment: Suggest directly storing it as a `ClassValue` instead of `Function` for clarity. Don't see the value of modeling it as a function -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org