You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2021/09/09 00:26:03 UTC

[pinot] branch master updated: simplify association between Java Class and PinotDataType for faster mapping (#7402)

This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 58fcd5b  simplify association between Java Class and PinotDataType for faster mapping (#7402)
58fcd5b is described below

commit 58fcd5b724288ab24b2c899f165f2b192701110b
Author: Richard Startin <ri...@startree.ai>
AuthorDate: Thu Sep 9 01:25:48 2021 +0100

    simplify association between Java Class and PinotDataType for faster mapping (#7402)
    
    The change replaces the subclassed HashMaps in PinotDataType which store the association between Class and PinotDataTypes with plain if statements, which shows > 50% improvement in a microbenchmark.
---
 .../apache/pinot/common/utils/PinotDataType.java   | 92 ++++++++++++++--------
 1 file changed, 59 insertions(+), 33 deletions(-)

diff --git a/pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java b/pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java
index cb4b5fa..49406ba 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/utils/PinotDataType.java
@@ -20,8 +20,6 @@ package org.apache.pinot.common.utils;
 
 import java.sql.Timestamp;
 import java.util.Base64;
-import java.util.HashMap;
-import java.util.Map;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
 import org.apache.pinot.spi.data.FieldSpec;
@@ -774,33 +772,6 @@ public enum PinotDataType {
 
   OBJECT_ARRAY;
 
-  // 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);
-  }};
-
   /**
    * NOTE: override toInt(), toLong(), toFloat(), toDouble(), toBoolean(), toTimestamp(), toString(), and
    * toBytes() for single-value types.
@@ -1119,13 +1090,68 @@ public enum PinotDataType {
   }
 
   public static PinotDataType getSingleValueType(Class<?> cls) {
-    PinotDataType pdt = SINGLE_VALUE_TYPE_MAP.get(cls);
-    return (pdt != null) ? pdt : OBJECT;
+    if (cls == Integer.class) {
+      return INTEGER;
+    }
+    if (cls == Long.class) {
+      return LONG;
+    }
+    if (cls == Float.class) {
+      return FLOAT;
+    }
+    if (cls == Double.class) {
+      return DOUBLE;
+    }
+    if (cls == String.class) {
+      return STRING;
+    }
+    if (cls == byte[].class) {
+      return BYTES;
+    }
+    if (cls == Boolean.class) {
+      return BOOLEAN;
+    }
+    if (cls == Timestamp.class) {
+      return TIMESTAMP;
+    }
+    if (cls == Byte.class) {
+      return BYTE;
+    }
+    if (cls == Character.class) {
+      return CHARACTER;
+    }
+    if (cls == Short.class) {
+      return SHORT;
+    }
+    return OBJECT;
   }
 
   public static PinotDataType getMultiValueType(Class<?> cls) {
-    PinotDataType pdt = MULTI_VALUE_TYPE_MAP.get(cls);
-    return (pdt != null) ? pdt : OBJECT_ARRAY;
+    if (cls == Integer.class) {
+      return INTEGER_ARRAY;
+    }
+    if (cls == Long.class) {
+      return LONG_ARRAY;
+    }
+    if (cls == Float.class) {
+      return FLOAT_ARRAY;
+    }
+    if (cls == Double.class) {
+      return DOUBLE_ARRAY;
+    }
+    if (cls == String.class) {
+      return STRING_ARRAY;
+    }
+    if (cls == Byte.class) {
+      return BYTE_ARRAY;
+    }
+    if (cls == Character.class) {
+      return CHARACTER_ARRAY;
+    }
+    if (cls == Short.class) {
+      return SHORT_ARRAY;
+    }
+    return OBJECT_ARRAY;
   }
 
   private static int anyToInt(Object val) {

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org