for (int depth = 0; depth < criteria.getElements().size(); depth++) {
Field field = schema.getField(depth);
Field.Type type = field.getType();
SortElement sortElement = criteria.getElements().get(depth);
Order sort = sortElement.getOrder();
RawComparator comparator = sortElement.getCustomComparator();
// Control for nulls, if field is nullable.
if (field.isNullable()) {
Criteria.NullOrder nullOrder = sortElement.getNullOrder();
if (n.nulls1.isSet(schema.getNullablePositionFromIndex(depth))) {
if (n.nulls2.isSet(schema.getNullablePositionFromIndex(depth))) {
// Both are null, so both are equal. No space is used. Continue.
continue;
} else {
// First is null
return (nullOrder == Criteria.NullOrder.NULL_SMALLEST && sort == Order.ASC) ? -1 : 1;
}
} else if (n.nulls2.isSet(schema.getNullablePositionFromIndex(depth))) {
// Second is null
return (nullOrder == Criteria.NullOrder.NULL_SMALLEST && sort == Order.ASC) ? 1 : -1;
}
}
if (comparator != null) {
//custom comparator for OBJECT
int length1 = WritableComparator.readVInt(b1, o.offset1);
int length2 = WritableComparator.readVInt(b2, o.offset2);
o.offset1 += WritableUtils.decodeVIntSize(b1[o.offset1]);
o.offset2 += WritableUtils.decodeVIntSize(b2[o.offset2]);
int comparison = comparator.compare(b1, o.offset1, length1, b2,
o.offset2, length2);
o.offset1 += length1;
o.offset2 += length2;
if (comparison != 0) {
return (sort == Order.ASC) ? comparison : -comparison;