@Override protected int compare(Tuple t1, Tuple t2) { for (int i = 0; i < orderByColumns.size(); i++) { OrderByExpression order = orderByColumns.get(i); Expression orderExpr = order.getExpression(); boolean isNull1 = !orderExpr.evaluate(t1, ptr1) || ptr1.getLength() == 0; boolean isNull2 = !orderExpr.evaluate(t2, ptr2) || ptr2.getLength() == 0; if (isNull1 && isNull2) { continue; } else if (isNull1) { return order.isNullsLast() ? 1 : -1; } else if (isNull2) { return order.isNullsLast() ? -1 : 1; } int cmp = ptr1.compareTo(ptr2); if (cmp == 0) { continue; } return order.isAscending() ? cmp : -cmp; } return 0; }