walterddr commented on a change in pull request #7581: URL: https://github.com/apache/pinot/pull/7581#discussion_r729909170
########## 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[]) { + return (boolean[]) value; + } else { + int[] ints = (int[]) value; + boolean[] booleans = new boolean[ints.length]; + for (int i = 0; i < ints.length; i++) { + booleans[i] = ints[i] == 1; Review comment: should this be `!= 0` ? ########## 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[]) { + return (boolean[]) value; + } else { + int[] ints = (int[]) value; + boolean[] booleans = new boolean[ints.length]; + for (int i = 0; i < ints.length; i++) { + booleans[i] = ints[i] == 1; Review comment: hmm. https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/BooleanUtils.html seems to consider 0 as false and everything else as true. this is also the convention I encountered the most. but yeah if we are already doing so. it's fine ########## 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[]) { + return (boolean[]) value; + } else { + int[] ints = (int[]) value; + boolean[] booleans = new boolean[ints.length]; + for (int i = 0; i < ints.length; i++) { + booleans[i] = ints[i] == 1; Review comment: hmm. https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/BooleanUtils.html seems to consider 0 as false and everything else as true. this is also the convention I encountered the most. but yeah if we are already doing so in SV. it's fine -- 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