use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestCastFunctions method testCastNested.
@Test
public // nested: cast is nested in another cast, or another function.
void testCastNested() throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastNested.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final IntVector c0 = exec.getValueVectorById(new SchemaPath("add_cast", ExpressionPosition.UNKNOWN), IntVector.class);
final IntVector.Accessor a0 = c0.getAccessor();
int count = 0;
for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
final IntHolder holder0 = new IntHolder();
a0.get(i, holder0);
assertEquals(300, holder0.value);
++count;
}
assertEquals(5, count);
}
exec.close();
context.close();
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
assertTrue(!context.getExecutorState().isFailed());
}
use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestRepeatedFunction method testRepeated.
@Test
public void testRepeated() throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
boolean oneIsOne = false;
int size = 0;
final int[] sizes = { 1, 2, 0, 6 };
while (exec.next()) {
final IntVector c1 = exec.getValueVectorById(new SchemaPath("cnt", ExpressionPosition.UNKNOWN), IntVector.class);
final BitVector c2 = exec.getValueVectorById(new SchemaPath("has_min", ExpressionPosition.UNKNOWN), BitVector.class);
for (int i = 0; i < exec.getRecordCount(); i++) {
final int curSize = sizes[size % sizes.length];
assertEquals(curSize, c1.getAccessor().get(i));
switch(curSize) {
case 1:
assertEquals(oneIsOne, 1 == c2.getAccessor().get(i));
oneIsOne = !oneIsOne;
break;
case 2:
assertEquals(1, c2.getAccessor().get(i));
break;
case 0:
assertEquals(0, c2.getAccessor().get(i));
break;
case 6:
assertEquals(1, c2.getAccessor().get(i));
break;
}
size++;
}
}
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
assertTrue(!context.getExecutorState().isFailed());
}
use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestFillEmpties method testInt.
@Test
public void testInt() {
@SuppressWarnings("resource") IntVector vector = new IntVector(SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED), fixture.allocator());
vector.allocateNew();
// Create 1, 0, 2, but omit the 0.
IntVector.Mutator mutator = vector.getMutator();
mutator.setSafe(0, 1);
mutator.setSafe(2, 3);
visualize(vector, 3);
vector.close();
}
use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestFixedWidthWriter method testRollover.
/**
* The rollover method is used during vector overflow.
*/
@Test
public void testRollover() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
// Overflow occurs after writing the 11th row
index.index = 10;
writer.startRow();
writer.setInt(10);
// Overflow occurs
writer.preRollover();
for (int i = 0; i < 15; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
vector.getMutator().set(0, 10);
writer.postRollover();
index.index = 0;
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.setInt(10 + i);
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 5; i++) {
assertEquals(10 + i, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestFixedWidthWriter method testRolloverWithEmpties.
/**
* Simulate the case in which the tail end of an overflow
* batch has empties. <tt>preRollover()</tt> should back-fill
* them with the next offset prior to rollover.
*/
@Test
public void testRolloverWithEmpties() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
for (int i = 10; i < 15; i++) {
index.index = i;
writer.startRow();
writer.saveRow();
}
// Overflow occurs before writing the 16th row
index.index = 15;
writer.startRow();
// Overflow occurs. This should fill empty offsets.
writer.preRollover();
for (int i = 0; i < 10; i++) {
assertEquals(i, vector.getAccessor().get(i));
}
for (int i = 10; i < 15; i++) {
assertEquals(0, vector.getAccessor().get(i));
}
for (int i = 0; i < 20; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
writer.postRollover();
index.index = 0;
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.saveRow();
}
for (int i = 5; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setInt(i + 20);
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 5; i++) {
assertEquals(0, vector.getAccessor().get(i));
}
for (int i = 5; i < 10; i++) {
assertEquals(i + 20, vector.getAccessor().get(i));
}
}
}
Aggregations