You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/10/17 00:33:59 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #7581: add `BOOLEAN_ARRAY` and `TIMESTAMP_ARRAY` types

Jackie-Jiang commented on a change in pull request #7581:
URL: https://github.com/apache/pinot/pull/7581#discussion_r730147912



##########
File path: pinot-common/src/main/java/org/apache/pinot/common/utils/DataSchema.java
##########
@@ -434,54 +411,104 @@ public Serializable convertAndFormat(Object value) {
         case INT_ARRAY:
           return (int[]) value;
         case LONG_ARRAY:
-          if (value instanceof long[]) {
-            return (long[]) value;
-          } else {
-            int[] intValues = (int[]) value;
-            int length = intValues.length;
-            long[] longValues = new long[length];
-            for (int i = 0; i < length; i++) {
-              longValues[i] = intValues[i];
-            }
-            return longValues;
-          }
+          return toLongArray(value);
         case FLOAT_ARRAY:
           return (float[]) value;
         case DOUBLE_ARRAY:
-          if (value instanceof double[]) {
-            return (double[]) value;
-          } else if (value instanceof int[]) {
-            int[] intValues = (int[]) value;
-            int length = intValues.length;
-            double[] doubleValues = new double[length];
-            for (int i = 0; i < length; i++) {
-              doubleValues[i] = intValues[i];
-            }
-            return doubleValues;
-          } else if (value instanceof long[]) {
-            long[] longValues = (long[]) value;
-            int length = longValues.length;
-            double[] doubleValues = new double[length];
-            for (int i = 0; i < length; i++) {
-              doubleValues[i] = longValues[i];
-            }
-            return doubleValues;
-          } else {
-            float[] floatValues = (float[]) value;
-            int length = floatValues.length;
-            double[] doubleValues = new double[length];
-            for (int i = 0; i < length; i++) {
-              doubleValues[i] = floatValues[i];
-            }
-            return doubleValues;
-          }
+          return toDoubleArray(value);
         case STRING_ARRAY:
           return (String[]) value;
+        case BOOLEAN_ARRAY:
+          return toBooleanArray(value);
+        case TIMESTAMP_ARRAY:
+          return formatTimestampArray(value);
         default:
           throw new IllegalStateException(String.format("Cannot convert and format: '%s' to type: %s", value, this));
       }
     }
 
+    private static double[] toDoubleArray(Object value) {
+      if (value instanceof double[]) {
+        return (double[]) value;
+      } else if (value instanceof int[]) {
+        int[] intValues = (int[]) value;
+        int length = intValues.length;
+        double[] doubleValues = new double[length];
+        for (int i = 0; i < length; i++) {
+          doubleValues[i] = intValues[i];
+        }
+        return doubleValues;
+      } else if (value instanceof long[]) {
+        long[] longValues = (long[]) value;
+        int length = longValues.length;
+        double[] doubleValues = new double[length];
+        for (int i = 0; i < length; i++) {
+          doubleValues[i] = longValues[i];
+        }
+        return doubleValues;
+      } else {
+        float[] floatValues = (float[]) value;
+        int length = floatValues.length;
+        double[] doubleValues = new double[length];
+        for (int i = 0; i < length; i++) {
+          doubleValues[i] = floatValues[i];
+        }
+        return doubleValues;
+      }
+    }
+
+    private static long[] toLongArray(Object value) {
+      if (value instanceof long[]) {
+        return (long[]) value;
+      } else {
+        int[] intValues = (int[]) value;
+        int length = intValues.length;
+        long[] longValues = new long[length];
+        for (int i = 0; i < length; i++) {
+          longValues[i] = intValues[i];
+        }
+        return longValues;
+      }
+    }
+
+    private static boolean[] toBooleanArray(Object value) {
+      if (value instanceof boolean[]) {

Review comment:
       This `if` is not really possible because we never store `boolean[]` internal. Same for `Timestamp`

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/utils/DataSchema.java
##########
@@ -250,8 +251,17 @@ public int hashCode() {
     LONG_ARRAY,
     FLOAT_ARRAY,
     DOUBLE_ARRAY,
-    STRING_ARRAY;
-
+    STRING_ARRAY,
+    BOOLEAN_ARRAY /* Stored as INT_ARRAY */,

Review comment:
       (nit) Consider putting them before the `STRING_ARRAY` to keep all fixed-length ones together




-- 
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-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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