use of org.apache.drill.exec.vector.IntVector in project drill by apache.
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 apache.
the class TestFixedWidthWriter method testFillEmpties.
/**
* Required, fixed-width vectors are back-filling with 0 to fill in missing
* values. While using zero is not strictly SQL compliant, it is better
* than failing. (The SQL solution would be to fill with nulls, but a
* required vector does not support nulls...)
*/
@Test
public void testFillEmpties() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 501; i += 5) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
// At end, vector index defined to point one past the
// last row. That is, the vector index gives the row count.
index.index = 504;
writer.endWrite();
for (int i = 0; i < 504; i++) {
assertEquals("Mismatch on " + i, (i % 5) == 0 ? i : 0, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.IntVector in project drill by apache.
the class TestShortArrays method testReAllocZeroSize.
/**
* Test that a zero-length vector, on reAlloc, will default
* to 256 bytes. (Previously the code just doubled zero
* forever.)
*/
@Test
public void testReAllocZeroSize() {
try (IntVector vector = new IntVector(SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED), fixture.allocator())) {
vector.allocateNew(0);
vector.reAlloc();
assertEquals(256 / 4, vector.getValueCapacity());
}
}
use of org.apache.drill.exec.vector.IntVector in project drill by apache.
the class TestMathFunctions method testBasicMathFunctions.
@Test
public void testBasicMathFunctions(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
mockDrillbitContext(bitContext);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContext context = new FragmentContext(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.getFailureCause() != null) {
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}
use of org.apache.drill.exec.vector.IntVector in project drill by apache.
the class ExpressionTest method testSpecial.
@Test
public void testSpecial(@Injectable final RecordBatch batch, @Injectable ValueVector vector) throws Exception {
final TypeProtos.MajorType type = Types.optional(MinorType.INT);
final TypedFieldId tfid = new TypedFieldId(type, false, 0);
new NonStrictExpectations() {
@NonStrict
VectorWrapper<?> wrapper;
{
batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN));
result = tfid;
batch.getValueAccessorById(IntVector.class, tfid.getFieldIds());
result = wrapper;
wrapper.getValueVector();
result = new IntVector(MaterializedField.create("result", type), RootAllocatorFactory.newRoot(c));
}
};
System.out.println(getExpressionCode("1 + 1", batch));
}
Aggregations