PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/sort/two_key_sort.json"), Charsets.UTF_8));
FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
FragmentContext context = new FragmentContext(bitContext, FragmentHandle.getDefaultInstance(), connection, null, registry);
SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
int previousInt = Integer.MIN_VALUE;
long previousLong = Long.MAX_VALUE;
int recordCount = 0;
int batchCount = 0;
while(exec.next()){
batchCount++;
IntVector c1 = exec.getValueVectorById(new SchemaPath("blue", ExpressionPosition.UNKNOWN), IntVector.class);
BigIntVector c2 = exec.getValueVectorById(new SchemaPath("alt", ExpressionPosition.UNKNOWN), BigIntVector.class);
IntVector.Accessor a1 = c1.getAccessor();
BigIntVector.Accessor a2 = c2.getAccessor();
for(int i =0; i < c1.getAccessor().getValueCount(); i++){
recordCount++;
assert previousInt <= a1.get(i);
if(previousInt != a1.get(i)){
previousLong = Long.MAX_VALUE;
previousInt = a1.get(i);
}
assert previousLong >= a2.get(i);
//System.out.println(previousInt + "\t" + a2.get(i));
}
}
System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount));
if(context.getFailureCause() != null){
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}