Skip to content

Commit

Permalink
fixup! use sorted bucket merger in qaf and group by routing/pk
Browse files Browse the repository at this point in the history
  • Loading branch information
msbt committed Mar 17, 2015
1 parent 0197f15 commit be31078
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
16 changes: 14 additions & 2 deletions sql/src/main/java/io/crate/planner/PlanNodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,22 @@ public static MergeNode localMerge(List<Projection> projections,
return node;
}

/**
* Create a MergeNode which uses a {@link io.crate.operation.merge.SortingBucketMerger}
* as it expects sorted input and produces sorted output.
*
* @param projections the projections to include in the resulting MergeNode
* @param orderBy {@linkplain io.crate.analyze.OrderBy} containing sorting parameters
* @param sourceSymbols the input symbols for this mergeNode
* @param orderBySymbols the symbols to sort on. If this is null,
* {@linkplain io.crate.analyze.OrderBy#orderBySymbols()}
* will be used
* @param previousNode the previous planNode to derive inputtypes from
*/
public static MergeNode sortedLocalMerge(List<Projection> projections,
@Nullable List<Symbol> orderBySymbols,
List<Symbol> sourceSymbols,
OrderBy orderBy,
List<Symbol> sourceSymbols,
@Nullable List<Symbol> orderBySymbols,
DQLPlanNode previousNode) {
int[] orderByIndices = OrderByPositionVisitor.orderByPositions(
MoreObjects.firstNonNull(orderBySymbols, orderBy.orderBySymbols()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ private AnalyzedRelation normalSelect(QueriedTable table,
// and we merge sorted with SortedBucketMerger
mergeNode = PlanNodeBuilder.sortedLocalMerge(
ImmutableList.<Projection>of(tnp),
orderByInputColumns,
allOutputs,
orderBy,
allOutputs,
orderByInputColumns,
collectNode
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private AnalyzedRelation optimizedReduceOnCollectorGroupBy(QueriedTable table, T
if (!ignoreSorting && collectorTopN && orderBy != null && orderBy.isSorted()) {
// handler receives sorted results from collectnodes
// we can do the sorting with a sorting bucket merger
localMergeNode = PlanNodeBuilder.sortedLocalMerge(handlerProjections, null, table.querySpec().outputs(), orderBy, collectNode);
localMergeNode = PlanNodeBuilder.sortedLocalMerge(handlerProjections, orderBy, table.querySpec().outputs(), null, collectNode);
handlerProjections.add(
projectionBuilder.topNProjection(
table.querySpec().outputs(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setUp() throws Exception {
" \"areaInSqKm\" float," +
" capital string," +
" continent string," +
" type byte," +
" type int," +
" \"continentName\" string," +
" \"countryCode\" string," +
" \"countryName\" string," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private byte[] generateRowSource() throws IOException {
.field("continent", new BytesArray(buffer, 0, 4).toUtf8())
.field("countryCode", new BytesArray(buffer, 4, 8).toUtf8())
.field("countryName", new BytesArray(buffer, 8, 24).toUtf8())
.field("type", buffer[25])
.field("type", getRandom().nextInt(100_000))
.field("population", random.nextInt(Integer.MAX_VALUE))
.endObject()
.bytes().toBytes();
Expand Down

0 comments on commit be31078

Please sign in to comment.