Search in sources :

Example 6 with OrderByExpression

use of org.apache.phoenix.expression.OrderByExpression in project phoenix by apache.

the class OrderedResultIterator method buildComparator.

/**
 * 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;
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) OrderByExpression(org.apache.phoenix.expression.OrderByExpression) Expression(org.apache.phoenix.expression.Expression) OrderByExpression(org.apache.phoenix.expression.OrderByExpression)

Aggregations

OrderByExpression (org.apache.phoenix.expression.OrderByExpression)6 Expression (org.apache.phoenix.expression.Expression)4 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 SQLExceptionInfo (org.apache.phoenix.exception.SQLExceptionInfo)1 AggregatingResultIterator (org.apache.phoenix.iterate.AggregatingResultIterator)1 BaseGroupedAggregatingResultIterator (org.apache.phoenix.iterate.BaseGroupedAggregatingResultIterator)1 DistinctAggregatingResultIterator (org.apache.phoenix.iterate.DistinctAggregatingResultIterator)1 FilterAggregatingResultIterator (org.apache.phoenix.iterate.FilterAggregatingResultIterator)1 FilterResultIterator (org.apache.phoenix.iterate.FilterResultIterator)1 GroupedAggregatingResultIterator (org.apache.phoenix.iterate.GroupedAggregatingResultIterator)1 LimitingResultIterator (org.apache.phoenix.iterate.LimitingResultIterator)1 LookAheadResultIterator (org.apache.phoenix.iterate.LookAheadResultIterator)1 OffsetResultIterator (org.apache.phoenix.iterate.OffsetResultIterator)1 OrderedAggregatingResultIterator (org.apache.phoenix.iterate.OrderedAggregatingResultIterator)1 OrderedResultIterator (org.apache.phoenix.iterate.OrderedResultIterator)1