Source:
<code>private Ordering<Row> makeComparator( List<DimensionSpec> dimensions, List<AggregatorFactory> aggs, List<PostAggregator> postAggs ) { Ordering<Row> ordering = new Ordering<Row>() { @Override public int compare(Row left, Row right) { return Longs.compare(left.getTimestampFromEpoch(), right.getTimestampFromEpoch()); } }; Map<String, DimensionSpec> dimensionsMap = Maps.newHashMap(); for (DimensionSpec spec : dimensions) { dimensionsMap.put(spec.getOutputName(), spec); } Map<String, AggregatorFactory> aggregatorsMap = Maps.newHashMap(); for (final AggregatorFactory agg : aggs) { aggregatorsMap.put(agg.getName(), agg); } Map<String, PostAggregator> postAggregatorsMap = Maps.newHashMap(); for (PostAggregator postAgg : postAggs) { postAggregatorsMap.put(postAgg.getName(), postAgg); } for (OrderByColumnSpec columnSpec : columns) { String columnName = columnSpec.getDimension(); Ordering<Row> nextOrdering = null; if (dimensionsMap.containsKey(columnName)) { nextOrdering = dimensionOrdering(columnName); } else if (aggregatorsMap.containsKey(columnName)) { nextOrdering = metricOrdering(columnName, aggregatorsMap.get(columnName).getComparator()); <START> } else if (postAggregatorsMap.containsKey(columnName)) { <END> nextOrdering = metricOrdering(columnName, postAggregatorsMap.get(columnName).getComparator()); } if (nextOrdering == null) { throw new ISE("Unknown column in order clause[%s]", columnSpec); } switch (columnSpec.getDirection()) { case DESCENDING: nextOrdering = nextOrdering.reverse(); } ordering = ordering.compound(nextOrdering); } return ordering; }</code><technical_language>This if-else chain effectively flips order of precedence. Prior behavior (in event of equal named things) favor post-agg agg dimension. This flips behavior. In case aggregator a post aggregator named uniques (for example, a hyper uniques aggregator a hyper unique finalizer postAgg) sorting based aggregator instead of post-agg. Is a case covered unit tests</technical_language>

Target:
private Ordering<Row> makeComparator( List<DimensionSpec> dimensions, List<AggregatorFactory> aggs, List<PostAggregator> postAggs ) { Ordering<Row> ordering = new Ordering<Row>() { @Override public int compare(Row left, Row right) { return Longs.compare(left.getTimestampFromEpoch(), right.getTimestampFromEpoch()); } }; Map<String, DimensionSpec> dimensionsMap = Maps.newHashMap(); for (DimensionSpec spec : dimensions) { dimensionsMap.put(spec.getOutputName(), spec); } Map<String, AggregatorFactory> aggregatorsMap = Maps.newHashMap(); for (final AggregatorFactory agg : aggs) { aggregatorsMap.put(agg.getName(), agg); } Map<String, PostAggregator> postAggregatorsMap = Maps.newHashMap(); for (PostAggregator postAgg : postAggs) { postAggregatorsMap.put(postAgg.getName(), postAgg); } for (OrderByColumnSpec columnSpec : columns) { String columnName = columnSpec.getDimension(); Ordering<Row> nextOrdering = null; if (postAggregatorsMap.containsKey(columnName)) { nextOrdering = metricOrdering(columnName, postAggregatorsMap.get(columnName).getComparator()); } else if (aggregatorsMap.containsKey(columnName)) { nextOrdering = metricOrdering(columnName, aggregatorsMap.get(columnName).getComparator()); } else if (dimensionsMap.containsKey(columnName)) { nextOrdering = dimensionOrdering(columnName); } if (nextOrdering == null) { throw new ISE("Unknown column in order clause[%s]", columnSpec); } switch (columnSpec.getDirection()) { case DESCENDING: nextOrdering = nextOrdering.reverse(); } ordering = ordering.compound(nextOrdering); } return ordering; }