use of org.apache.drill.exec.vector.IntVector in project drill by apache.
the class TestFillEmpties method testInt.
@Test
public void testInt() {
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 apache.
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.asCharSource(DrillFileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8).read());
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 apache.
the class TestCastFunctions method testCastInt.
@Test
public // cast to int
void testCastInt() 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.asCharSource(DrillFileUtils.getResourceAsFile("/functions/cast/testCastInt.json"), Charsets.UTF_8).read());
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("varchar_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(1256, 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 apache.
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.asCharSource(DrillFileUtils.getResourceAsFile("/functions/cast/testCastNested.json"), Charsets.UTF_8).read());
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 apache.
the class TestAgg method oneKeyAgg.
@Test
public void oneKeyAgg() throws Throwable {
final SimpleRootExec exec = doTest("/agg/test1.json");
while (exec.next()) {
final BigIntVector cnt = exec.getValueVectorById(SchemaPath.getSimplePath("cnt"), BigIntVector.class);
final IntVector key = exec.getValueVectorById(SchemaPath.getSimplePath("blue"), IntVector.class);
final long[] cntArr = { 10001, 9999 };
final int[] keyArr = { Integer.MIN_VALUE, Integer.MAX_VALUE };
for (int i = 0; i < exec.getRecordCount(); i++) {
assertEquals((Long) cntArr[i], cnt.getAccessor().getObject(i));
assertEquals((Integer) keyArr[i], key.getAccessor().getObject(i));
}
}
if (exec.getContext().getExecutorState().getFailureCause() != null) {
throw exec.getContext().getExecutorState().getFailureCause();
}
assertTrue(!exec.getContext().getExecutorState().isFailed());
}
Aggregations