use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class ExpressionTest method testSpecial.
@Test
public void testSpecial() throws Exception {
final RecordBatch batch = mock(RecordBatch.class);
final VectorWrapper wrapper = mock(VectorWrapper.class);
final TypeProtos.MajorType type = Types.optional(MinorType.INT);
final TypedFieldId tfid = new TypedFieldId(type, false, 0);
when(wrapper.getValueVector()).thenReturn(new IntVector(MaterializedField.create("result", type), RootAllocatorFactory.newRoot(c)));
when(batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN))).thenReturn(tfid);
when(batch.getValueAccessorById(IntVector.class, tfid.getFieldIds())).thenReturn(wrapper);
System.out.println(getExpressionCode("1 + 1", batch));
}
use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestMathFunctions method testBasicMathFunctions.
@Test
public void testBasicMathFunctions() 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("/functions/simple_math_functions.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class);
final Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class);
final IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class);
final Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class);
assertEquals(exec.getRecordCount(), 1);
assertEquals(intMulVector.getAccessor().get(0), 2);
assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0);
assertEquals(intAddVector.getAccessor().get(0), 3);
assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0);
}
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 TestToNullable method testFixedWidth.
@SuppressWarnings("resource")
@Test
public void testFixedWidth() {
MaterializedField intSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED);
IntVector intVector = new IntVector(intSchema, fixture.allocator());
IntVector.Mutator intMutator = intVector.getMutator();
intVector.allocateNew(100);
for (int i = 0; i < 100; i++) {
intMutator.set(i, i * 10);
}
intMutator.setValueCount(100);
MaterializedField nullableIntSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.OPTIONAL);
NullableIntVector nullableIntVector = new NullableIntVector(nullableIntSchema, fixture.allocator());
intVector.toNullable(nullableIntVector);
assertEquals(0, intVector.getAccessor().getValueCount());
NullableIntVector.Accessor niAccessor = nullableIntVector.getAccessor();
assertEquals(100, niAccessor.getValueCount());
for (int i = 0; i < 100; i++) {
assertFalse(niAccessor.isNull(i));
assertEquals(i * 10, niAccessor.get(i));
}
nullableIntVector.clear();
// Don't clear the intVector, it should be empty.
// If it is not, the test will fail with a memory leak error.
}
use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestFixedWidthWriter method allocVector.
private IntVector allocVector(int size) {
MaterializedField field = SchemaBuilder.columnSchema("x", MinorType.INT, DataMode.REQUIRED);
IntVector vector = new IntVector(field, fixture.allocator());
vector.allocateNew(size);
for (int i = 0; i < size; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
return vector;
}
use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.
the class TestFixedWidthWriter method testSizeLimit.
/**
* Test resize monitoring. Add a listener to an int writer,
* capture each resize, and refuse a resize when the number
* of ints exceeds 8K values. This will trigger an overflow,
* which will throw an exception which we then check for.
*/
@Test
public void testSizeLimit() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.bindListener(new ColumnWriterListener() {
int totalAlloc = 4096;
@Override
public void overflowed(ScalarWriter writer) {
throw new IllegalStateException("overflow called");
}
@Override
public boolean canExpand(ScalarWriter writer, int delta) {
// System.out.println("Delta: " + delta);
totalAlloc += delta;
return totalAlloc < 16_384 * 4;
}
});
writer.startWrite();
try {
for (int i = 0; ; i++) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("overflow called"));
}
// Should have failed on 8192, which doubled vector
// to 16K, which was rejected.
assertEquals(8192, index.index);
}
}
Aggregations