/** * Builds a comparator from the list of columns in ORDER BY clause. * @param orderByExpressions the columns in ORDER BY clause. * @return the comparator built from the list of columns in ORDER BY clause. */ // ImmutableBytesWritable.Comparator doesn't implement generics @SuppressWarnings("unchecked") private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) { Ordering<ResultEntry> ordering = null; int pos = 0; for (OrderByExpression col : orderByExpressions) { Expression e = col.getExpression(); Comparator<ImmutableBytesWritable> comparator = e.getSortOrder() == SortOrder.DESC && !e.getDataType().isFixedWidth() ? buildDescVarLengthComparator() : new ImmutableBytesWritable.Comparator(); Ordering<ImmutableBytesWritable> o = Ordering.from(comparator); if(!col.isAscending()) o = o.reverse(); o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst(); Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++)); ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering); } return ordering; }
/** * Builds a comparator from the list of columns in ORDER BY clause. * @param orderByExpressions the columns in ORDER BY clause. * @return the comparator built from the list of columns in ORDER BY clause. */ // ImmutableBytesWritable.Comparator doesn't implement generics @SuppressWarnings("unchecked") private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) { Ordering<ResultEntry> ordering = null; int pos = 0; for (OrderByExpression col : orderByExpressions) { Expression e = col.getExpression(); Comparator<ImmutableBytesWritable> comparator = e.getSortOrder() == SortOrder.DESC && !e.getDataType().isFixedWidth() ? buildDescVarLengthComparator() : new ImmutableBytesWritable.Comparator(); Ordering<ImmutableBytesWritable> o = Ordering.from(comparator); if(!col.isAscending()) o = o.reverse(); o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst(); Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++)); ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering); } return ordering; }
/** * Builds a comparator from the list of columns in ORDER BY clause. * @param orderByExpressions the columns in ORDER BY clause. * @return the comparator built from the list of columns in ORDER BY clause. */ // ImmutableBytesWritable.Comparator doesn't implement generics @SuppressWarnings("unchecked") private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) { Ordering<ResultEntry> ordering = null; int pos = 0; for (OrderByExpression col : orderByExpressions) { Expression e = col.getExpression(); Comparator<ImmutableBytesWritable> comparator = e.getSortOrder() == SortOrder.DESC && !e.getDataType().isFixedWidth() ? buildDescVarLengthComparator() : new ImmutableBytesWritable.Comparator(); Ordering<ImmutableBytesWritable> o = Ordering.from(comparator); if(!col.isAscending()) o = o.reverse(); o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst(); Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++)); ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering); } return ordering; }