in athena-federation-sdk/src/main/java/com/amazonaws/athena/connector/lambda/data/ArrowTypeComparator.java [48:108]
public static int compare(ArrowType arrowType, Object lhs, Object rhs)
{
if (lhs == null && rhs == null) {
return 0;
}
else if (lhs == null) {
return 1;
}
else if (rhs == null) {
return -1;
}
Types.MinorType type = Types.getMinorTypeForArrowType(arrowType);
switch (type) {
case INT:
case UINT4:
return Integer.compare((int) lhs, (int) rhs);
case TINYINT:
case UINT1:
return Byte.compare((byte) lhs, (byte) rhs);
case SMALLINT:
return Short.compare((short) lhs, (short) rhs);
case UINT2:
return Character.compare((char) lhs, (char) rhs);
case BIGINT:
case UINT8:
return Long.compare((long) lhs, (long) rhs);
case FLOAT8:
return Double.compare((double) lhs, (double) rhs);
case FLOAT4:
return Float.compare((float) lhs, (float) rhs);
case VARCHAR:
return lhs.toString().compareTo(rhs.toString());
case VARBINARY:
return Arrays.compareUnsigned((byte[]) lhs, (byte[]) rhs);
case DECIMAL:
return ((BigDecimal) lhs).compareTo((BigDecimal) rhs);
case BIT:
return Boolean.compare((boolean) lhs, (boolean) rhs);
case DATEMILLI:
return ((LocalDateTime) lhs).compareTo((LocalDateTime) rhs);
case DATEDAY:
return ((Integer) lhs).compareTo((Integer) rhs);
case LIST:
case STRUCT: // struct maps to java.util.map
//This could lead to thrashing if used to sort a collection
if (lhs.equals(rhs)) {
return 0;
}
else if (lhs.hashCode() < rhs.hashCode()) {
return -1;
}
else {
return 1;
}
default:
//logging because throwing in a comparator gets swallowed in many unit tests that use equality asserts
logger.warn("compare: Unknown type " + type + " object: " + lhs.getClass());
throw new IllegalArgumentException("Unknown type " + type + " object: " + lhs.getClass());
}
}