use of org.apache.drill.exec.physical.config.Sort in project drill by axbaretto.
the class SortTestUtilities method makeCopierConfig.
@SuppressWarnings("resource")
public static Sort makeCopierConfig(String sortOrder, String nullOrder) {
FieldReference expr = FieldReference.getWithQuotedRef("key");
Ordering ordering = new Ordering(sortOrder, expr, nullOrder);
return new Sort(null, Lists.newArrayList(ordering), false);
}
use of org.apache.drill.exec.physical.config.Sort in project drill by axbaretto.
the class TestCopier method testEmptyInput.
@Test
public void testEmptyInput() throws Exception {
BatchSchema schema = SortTestUtilities.nonNullSchema();
List<BatchGroup> batches = new ArrayList<>();
Sort popConfig = SortTestUtilities.makeCopierConfig(Ordering.ORDER_ASC, Ordering.NULLS_UNSPECIFIED);
OperatorContext opContext = fixture.newOperatorContext(popConfig);
PriorityQueueCopierWrapper copier = new PriorityQueueCopierWrapper(opContext);
VectorContainer dest = new VectorContainer();
try {
// TODO: Create a vector allocator to pass as last parameter so
// that the test uses the same vector allocator as the production
// code. Only nuisance is that we don't have the required metadata
// readily at hand here...
@SuppressWarnings({ "resource", "unused" }) BatchMerger merger = copier.startMerge(schema, batches, dest, 10, null);
fail();
} catch (AssertionError e) {
// Expected
} finally {
opContext.close();
}
}
use of org.apache.drill.exec.physical.config.Sort in project drill by axbaretto.
the class TestSorter method testMapKey.
@Test
@Ignore("DRILL-5384")
public void testMapKey() throws Exception {
BatchSchema schema = new SchemaBuilder().addMap("map").add("key", MinorType.INT).add("value", MinorType.VARCHAR).resumeSchema().build();
SingleRowSet input = fixture.rowSetBuilder(schema).addRow(3, "third").addRow(1, "first").addRow(2, "second").withSv2().build();
SingleRowSet output = fixture.rowSetBuilder(schema).addRow(1, "first").addRow(2, "second").addRow(3, "third").build();
Sort popConfig = makeSortConfig("map.key", Ordering.ORDER_ASC, Ordering.NULLS_LAST);
runSorterTest(popConfig, input, output);
}
use of org.apache.drill.exec.physical.config.Sort in project drill by apache.
the class MergeSortWrapper method merge.
/**
* Merge the set of in-memory batches to produce a single logical output in the given
* destination container, indexed by an SV4.
*
* @param batchGroups the complete set of in-memory batches
* @param outputBatchSize output batch size for in-memory merge
* @return the sv4 for this operator
*/
public void merge(List<InputBatch> batchGroups, int outputBatchSize) {
// Add the buffered batches to a collection that MSorter can use.
// The builder takes ownership of the batches and will release them if
// an error occurs.
builder = new SortRecordBatchBuilder(context.getAllocator());
for (InputBatch group : batchGroups) {
RecordBatchData rbd = new RecordBatchData(group.getContainer(), context.getAllocator());
rbd.setSv2(group.getSv2());
builder.add(rbd);
}
batchGroups.clear();
try {
builder.build(destContainer);
sv4 = builder.getSv4();
Sort popConfig = context.getOperatorDefn();
mSorter = createNewMSorter(popConfig.getOrderings(), MAIN_MAPPING, LEFT_MAPPING, RIGHT_MAPPING);
mSorter.setup(context.getFragmentContext(), context.getAllocator(), sv4, destContainer, sv4.getCount(), outputBatchSize);
} catch (SchemaChangeException e) {
throw UserException.unsupportedError(e).message("Unexpected schema change - likely code error.").build(logger);
}
// For testing memory-leaks, inject exception after mSorter finishes setup
context.injectUnchecked(ExternalSortBatch.INTERRUPTION_AFTER_SETUP);
mSorter.sort();
// For testing memory-leak purpose, inject exception after mSorter finishes sorting
context.injectUnchecked(ExternalSortBatch.INTERRUPTION_AFTER_SORT);
sv4 = mSorter.getSV4();
// destContainer.buildSchema(SelectionVectorMode.FOUR_BYTE);
}
use of org.apache.drill.exec.physical.config.Sort in project drill by apache.
the class BaseSortWrapper method generateComparisons.
protected void generateComparisons(ClassGenerator<?> g, VectorAccessible batch, org.slf4j.Logger logger) {
g.setMappingSet(MAIN_MAPPING);
Sort popConfig = context.getOperatorDefn();
for (Ordering od : popConfig.getOrderings()) {
// first, we rewrite the evaluation stack for each side of the comparison.
ErrorCollector collector = new ErrorCollectorImpl();
final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector, context.getFragmentContext().getFunctionRegistry());
if (collector.hasErrors()) {
throw UserException.unsupportedError().message("Failure while materializing expression. " + collector.toErrorString()).build(logger);
}
g.setMappingSet(LEFT_MAPPING);
HoldingContainer left = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
g.setMappingSet(RIGHT_MAPPING);
HoldingContainer right = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
g.setMappingSet(MAIN_MAPPING);
// next we wrap the two comparison sides and add the expression block for the comparison.
LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getFragmentContext().getFunctionRegistry());
HoldingContainer out = g.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));
if (od.getDirection() == Direction.ASCENDING) {
jc._then()._return(out.getValue());
} else {
jc._then()._return(out.getValue().minus());
}
g.rotateBlock();
}
g.rotateBlock();
g.getEvalBlock()._return(JExpr.lit(0));
}
Aggregations