panbingkun commented on code in PR #47984: URL: https://github.com/apache/spark/pull/47984#discussion_r1772510920
########## sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/ArrayExpressionUtils.java: ########## @@ -19,158 +19,288 @@ import java.util.Arrays; import java.util.Comparator; +import scala.reflect.ClassTag$; + import org.apache.spark.sql.catalyst.util.ArrayData; import org.apache.spark.sql.catalyst.util.SQLOrderingUtil; -import org.apache.spark.sql.types.ByteType$; -import org.apache.spark.sql.types.BooleanType$; import org.apache.spark.sql.types.DataType; -import org.apache.spark.sql.types.DoubleType$; -import org.apache.spark.sql.types.FloatType$; -import org.apache.spark.sql.types.IntegerType$; -import org.apache.spark.sql.types.LongType$; -import org.apache.spark.sql.types.ShortType$; + +import static org.apache.spark.sql.types.DataTypes.BooleanType; +import static org.apache.spark.sql.types.DataTypes.ByteType; +import static org.apache.spark.sql.types.DataTypes.DoubleType; +import static org.apache.spark.sql.types.DataTypes.FloatType; +import static org.apache.spark.sql.types.DataTypes.IntegerType; +import static org.apache.spark.sql.types.DataTypes.LongType; +import static org.apache.spark.sql.types.DataTypes.ShortType; public class ArrayExpressionUtils { - private static final Comparator<Object> booleanComp = (o1, o2) -> { + // comparator + // Boolean ascending nullable comparator + private static final Comparator<Boolean> booleanComp = (o1, o2) -> { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } - boolean c1 = (Boolean) o1, c2 = (Boolean) o2; - return c1 == c2 ? 0 : (c1 ? 1 : -1); + return o1.equals(o2) ? 0 : (o1 ? 1 : -1); }; - private static final Comparator<Object> byteComp = (o1, o2) -> { + // Byte ascending nullable comparator + private static final Comparator<Byte> byteComp = (o1, o2) -> { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } - byte c1 = (Byte) o1, c2 = (Byte) o2; - return Byte.compare(c1, c2); + return Byte.compare(o1, o2); }; - private static final Comparator<Object> shortComp = (o1, o2) -> { + // Short ascending nullable comparator + private static final Comparator<Short> shortComp = (o1, o2) -> { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } - short c1 = (Short) o1, c2 = (Short) o2; - return Short.compare(c1, c2); + return Short.compare(o1, o2); }; - private static final Comparator<Object> integerComp = (o1, o2) -> { + // Integer ascending nullable comparator + private static final Comparator<Integer> integerComp = (o1, o2) -> { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } - int c1 = (Integer) o1, c2 = (Integer) o2; - return Integer.compare(c1, c2); + return Integer.compare(o1, o2); }; - private static final Comparator<Object> longComp = (o1, o2) -> { + // Long ascending nullable comparator + private static final Comparator<Long> longComp = (o1, o2) -> { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } - long c1 = (Long) o1, c2 = (Long) o2; - return Long.compare(c1, c2); + return Long.compare(o1, o2); }; - private static final Comparator<Object> floatComp = (o1, o2) -> { + // Float ascending nullable comparator + private static final Comparator<Float> floatComp = (o1, o2) -> { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } - float c1 = (Float) o1, c2 = (Float) o2; - return SQLOrderingUtil.compareFloats(c1, c2); + return SQLOrderingUtil.compareFloats(o1, o2); }; - private static final Comparator<Object> doubleComp = (o1, o2) -> { + // Double ascending nullable comparator + private static final Comparator<Double> doubleComp = (o1, o2) -> { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } - double c1 = (Double) o1, c2 = (Double) o2; - return SQLOrderingUtil.compareDoubles(c1, c2); + return SQLOrderingUtil.compareDoubles(o1, o2); }; - public static int binarySearchNullSafe(ArrayData data, Boolean value) { - return Arrays.binarySearch(data.toObjectArray(BooleanType$.MODULE$), value, booleanComp); + // boolean + // boolean non-nullable + public static int binarySearch(boolean[] data, boolean value) { Review Comment: Yea! ❤️ -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org