move row up/down for null metric ordering (#4681)

* move row up/down for null metric ordering

* addressed comments

* addressed changes
This commit is contained in:
Asif Mansoor Amanullah 2017-08-17 11:36:19 -05:00 committed by Himanshu
parent 786e7815c2
commit 37f85b08d2
1 changed files with 2 additions and 23 deletions

View File

@ -249,33 +249,12 @@ public class DefaultLimitSpec implements LimitSpec
private Ordering<Row> metricOrdering(final String column, final Comparator comparator)
{
return new Ordering<Row>()
{
@SuppressWarnings("unchecked")
@Override
public int compare(Row left, Row right)
{
return comparator.compare(left.getRaw(column), right.getRaw(column));
}
};
return Ordering.from(Comparator.comparing((Row row) -> row.getRaw(column), Comparator.nullsLast(comparator)));
}
private Ordering<Row> dimensionOrdering(final String dimension, final StringComparator comparator)
{
return Ordering.from(comparator)
.nullsFirst()
.onResultOf(
new Function<Row, String>()
{
@Override
public String apply(Row input)
{
// Multi-value dimensions have all been flattened at this point;
final List<String> dimList = input.getDimension(dimension);
return dimList.isEmpty() ? null : dimList.get(0);
}
}
);
return Ordering.from(Comparator.comparing((Row row) -> row.getDimension(dimension).isEmpty() ? null : row.getDimension(dimension).get(0), Comparator.nullsFirst(comparator)));
}
@Override