in asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AbstractAGenericBinaryComparator.java [68:149]
protected final int compare(IAType leftType, TaggedValueReference leftValue, IAType rightType,
TaggedValueReference rightValue) throws HyracksDataException {
ATypeTag tag1 = leftValue.getTag();
ATypeTag tag2 = rightValue.getTag();
if (tag1 == null || tag2 == null) {
throw new IllegalStateException("Could not recognize the type of data.");
}
if (tag1 == ATypeTag.MISSING) {
return tag2 == ATypeTag.MISSING ? 0 : -1;
} else if (tag2 == ATypeTag.MISSING) {
return 1;
}
if (tag1 == ATypeTag.NULL) {
return tag2 == ATypeTag.NULL ? 0 : -1;
} else if (tag2 == ATypeTag.NULL) {
return 1;
}
byte[] b1 = leftValue.getByteArray();
int s1 = leftValue.getStartOffset();
int l1 = leftValue.getLength();
byte[] b2 = rightValue.getByteArray();
int s2 = rightValue.getStartOffset();
int l2 = rightValue.getLength();
if (ATypeHierarchy.isCompatible(tag1, tag2) && ATypeHierarchy.getTypeDomain(tag1) == Domain.NUMERIC) {
return ComparatorUtil.compareNumbers(tag1, b1, s1, tag2, b2, s2);
}
// currently only numbers are compatible. if two tags are not compatible, we compare the tags to generate order
if (tag1 != tag2) {
return Byte.compare(tag1.serialize(), tag2.serialize());
}
switch (tag1) {
case STRING:
return UTF8StringPointable.compare(b1, s1, l1, b2, s2, l2);
case UUID:
return AUUIDPartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case BOOLEAN:
return BooleanPointable.compare(b1, s1, l1, b2, s2, l2);
case TIME:
return Integer.compare(ATimeSerializerDeserializer.getChronon(b1, s1),
ATimeSerializerDeserializer.getChronon(b2, s2));
case DATE:
return Integer.compare(ADateSerializerDeserializer.getChronon(b1, s1),
ADateSerializerDeserializer.getChronon(b2, s2));
case YEARMONTHDURATION:
return Integer.compare(AYearMonthDurationSerializerDeserializer.getYearMonth(b1, s1),
AYearMonthDurationSerializerDeserializer.getYearMonth(b2, s2));
case DATETIME:
return Long.compare(ADateTimeSerializerDeserializer.getChronon(b1, s1),
ADateTimeSerializerDeserializer.getChronon(b2, s2));
case DAYTIMEDURATION:
return Long.compare(ADayTimeDurationSerializerDeserializer.getDayTime(b1, s1),
ADayTimeDurationSerializerDeserializer.getDayTime(b2, s2));
case RECTANGLE:
return ARectanglePartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case CIRCLE:
return ACirclePartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case POINT:
return APointPartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case POINT3D:
return APoint3DPartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case LINE:
return ALinePartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case POLYGON:
return APolygonPartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case GEOMETRY:
return AGeometryPartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case DURATION:
return ADurationPartialBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
case INTERVAL:
return compareInterval(b1, s1, l1, b2, s2, l2);
case BINARY:
return ByteArrayPointable.compare(b1, s1, l1, b2, s2, l2);
case ARRAY:
return compareArrays(leftType, leftValue, rightType, rightValue);
case OBJECT:
return compareRecords(leftType, b1, s1, rightType, b2, s2);
default:
return RawBinaryComparatorFactory.compare(b1, s1, l1, b2, s2, l2);
}
}