use of org.apache.drill.common.logical.data.Order.Ordering in project drill by apache.
the class OrderTest method test_Ordering_roundTripDescAndNullsLast.
@Test
public void test_Ordering_roundTripDescAndNullsLast() {
Ordering src = new Ordering(Direction.DESCENDING, null, NullDirection.LAST);
Ordering reconstituted = new Ordering(src.getDirection(), (LogicalExpression) null, src.getNullDirection());
assertThat(reconstituted.getDirection(), equalTo(RelFieldCollation.Direction.DESCENDING));
assertThat(reconstituted.getNullDirection(), equalTo(NullDirection.LAST));
}
use of org.apache.drill.common.logical.data.Order.Ordering in project drill by apache.
the class TestSortImpl method makeSortImpl.
/**
* Create the sort implementation to be used by test.
*
* @param fixture operator fixture
* @param sortOrder sort order as specified by {@link Ordering}
* @param nullOrder null order as specified by {@link Ordering}
* @return the initialized sort implementation, ready to do work
*/
public static SortImpl makeSortImpl(OperatorFixture fixture, String sortOrder, String nullOrder) {
FieldReference expr = FieldReference.getWithQuotedRef("key");
Ordering ordering = new Ordering(sortOrder, expr, nullOrder);
Sort popConfig = new Sort(null, Lists.newArrayList(ordering), false);
OperatorContext opContext = fixture.newOperatorContext(popConfig);
QueryId queryId = QueryId.newBuilder().setPart1(1234).setPart2(5678).build();
FragmentHandle handle = FragmentHandle.newBuilder().setMajorFragmentId(2).setMinorFragmentId(3).setQueryId(queryId).build();
SortConfig sortConfig = new SortConfig(opContext.getFragmentContext().getConfig(), opContext.getFragmentContext().getOptions());
SpillSet spillSet = new SpillSet(opContext.getFragmentContext().getConfig(), handle, popConfig);
PriorityQueueCopierWrapper copierHolder = new PriorityQueueCopierWrapper(opContext);
SpilledRuns spilledRuns = new SpilledRuns(opContext, spillSet, copierHolder);
dest = new VectorContainer(opContext.getAllocator());
return new SortImpl(opContext, sortConfig, spilledRuns, dest);
}
use of org.apache.drill.common.logical.data.Order.Ordering in project drill by apache.
the class TestSorter method makeSortConfig.
public static Sort makeSortConfig(String key, 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.common.logical.data.Order.Ordering in project drill by apache.
the class SortTestUtilities method makeCopierConfig.
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.common.logical.data.Order.Ordering in project drill by apache.
the class OrderedPartitionRecordBatch method buildTable.
private void buildTable() {
// Get all samples from distributed map
SortRecordBatchBuilder containerBuilder = new SortRecordBatchBuilder(context.getAllocator());
VectorContainer allSamplesContainer = new VectorContainer();
VectorContainer candidatePartitionTable = new VectorContainer();
CachedVectorContainer wrap = null;
try {
for (CachedVectorContainer w : mmap.get(mapKey)) {
containerBuilder.add(w.get());
}
containerBuilder.build(allSamplesContainer);
List<Ordering> orderDefs = Lists.newArrayList();
int i = 0;
for (Ordering od : popConfig.getOrderings()) {
SchemaPath sp = SchemaPath.getSimplePath("f" + i++);
orderDefs.add(new Ordering(od.getDirection(), new FieldReference(sp)));
}
// sort the data incoming samples.
SelectionVector4 newSv4 = containerBuilder.getSv4();
Sorter sorter = SortBatch.createNewSorter(context, orderDefs, allSamplesContainer);
try {
sorter.setup(context, newSv4, allSamplesContainer);
} catch (SchemaChangeException e) {
throw schemaChangeException(e, logger);
}
sorter.sort(newSv4, allSamplesContainer);
// Copy every Nth record from the samples into a candidate partition table, where N = totalSampledRecords/partitions
// Attempt to push this to the distributed map. Only the first candidate to get pushed will be used.
SampleCopier copier = null;
List<ValueVector> localAllocationVectors = Lists.newArrayList();
copier = getCopier(newSv4, allSamplesContainer, candidatePartitionTable, orderDefs, localAllocationVectors);
int allocationSize = 50;
while (true) {
for (ValueVector vv : localAllocationVectors) {
AllocationHelper.allocate(vv, samplingFactor * partitions, allocationSize);
}
int skipRecords = containerBuilder.getSv4().getTotalCount() / partitions;
if (copier.copyRecords(skipRecords, skipRecords, partitions - 1)) {
assert copier.getOutputRecords() == partitions - 1 : String.format("output records: %d partitions: %d", copier.getOutputRecords(), partitions);
candidatePartitionTable.setValueCount(copier.getOutputRecords());
break;
} else {
candidatePartitionTable.zeroVectors();
allocationSize *= 2;
}
}
candidatePartitionTable.setRecordCount(copier.getOutputRecords());
WritableBatch batch = WritableBatch.getBatchNoHVWrap(candidatePartitionTable.getRecordCount(), candidatePartitionTable, false);
wrap = new CachedVectorContainer(batch, context.getAllocator());
tableMap.putIfAbsent(mapKey + "final", wrap, 1, TimeUnit.MINUTES);
} finally {
candidatePartitionTable.clear();
allSamplesContainer.clear();
containerBuilder.clear();
containerBuilder.close();
if (wrap != null) {
wrap.clear();
}
}
}
Aggregations