Search in sources :

Example 1 with BitVector

use of org.apache.drill.exec.vector.BitVector in project drill by apache.

the class TestValueVector method testBitVector.

@Test
public void testBitVector() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, BitHolder.TYPE);
    // Create a new value vector for 1024 integers
    try (final BitVector vector = new BitVector(field, allocator)) {
        final BitVector.Mutator m = vector.getMutator();
        vector.allocateNew(1024);
        // Put and set a few values
        m.set(0, 1);
        m.set(1, 0);
        m.set(100, 0);
        m.set(1022, 1);
        final BitVector.Accessor accessor = vector.getAccessor();
        assertEquals(1, accessor.get(0));
        assertEquals(0, accessor.get(1));
        assertEquals(0, accessor.get(100));
        assertEquals(1, accessor.get(1022));
        // test setting the same value twice
        m.set(0, 1);
        m.set(0, 1);
        m.set(1, 0);
        m.set(1, 0);
        assertEquals(1, accessor.get(0));
        assertEquals(0, accessor.get(1));
        // test toggling the values
        m.set(0, 0);
        m.set(1, 1);
        assertEquals(0, accessor.get(0));
        assertEquals(1, accessor.get(1));
        // Ensure unallocated space returns 0
        assertEquals(0, accessor.get(3));
    }
}
Also used : BitVector(org.apache.drill.exec.vector.BitVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 2 with BitVector

use of org.apache.drill.exec.vector.BitVector in project drill by apache.

the class TestValueVector method testVectors.

/**
   * Convenience method that allows running tests on various {@link ValueVector vector} instances.
   *
   * @param test test function to execute
   */
private void testVectors(VectorVerifier test) throws Exception {
    final MaterializedField[] fields = { MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, BitHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, VarCharHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedListVector.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, MapVector.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedMapVector.TYPE) };
    final ValueVector[] vectors = { new UInt4Vector(fields[0], allocator), new BitVector(fields[1], allocator), new VarCharVector(fields[2], allocator), new NullableVarCharVector(fields[3], allocator), new RepeatedListVector(fields[4], allocator, null), new MapVector(fields[5], allocator, null), new RepeatedMapVector(fields[6], allocator, null) };
    try {
        for (final ValueVector vector : vectors) {
            test.verify(vector);
        }
    } finally {
        AutoCloseables.close(vectors);
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseValueVector(org.apache.drill.exec.vector.BaseValueVector) BitVector(org.apache.drill.exec.vector.BitVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Example 3 with BitVector

use of org.apache.drill.exec.vector.BitVector in project drill by apache.

the class TestValueVector method testBitVectorReallocation.

@Test(expected = OversizedAllocationException.class)
public void testBitVectorReallocation() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE);
    final BitVector vector = new BitVector(field, allocator);
    // edge case 1: buffer size ~ max value capacity
    final int expectedValueCapacity = 1 << 29;
    try {
        vector.allocateNew(expectedValueCapacity);
        assertEquals(expectedValueCapacity, vector.getValueCapacity());
        vector.reAlloc();
        assertEquals(expectedValueCapacity * 2, vector.getValueCapacity());
    } finally {
        vector.close();
    }
    // common: value count < MAX_VALUE_ALLOCATION
    try {
        vector.allocateNew(expectedValueCapacity);
        for (int i = 0; i < 3; i++) {
            // expand buffer size
            vector.reAlloc();
        }
        assertEquals(Integer.MAX_VALUE, vector.getValueCapacity());
        // buffer size ~ max allocation
        vector.reAlloc();
        assertEquals(Integer.MAX_VALUE, vector.getValueCapacity());
        // overflow
        vector.reAlloc();
    } finally {
        vector.close();
    }
}
Also used : BitVector(org.apache.drill.exec.vector.BitVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 4 with BitVector

use of org.apache.drill.exec.vector.BitVector in project drill by apache.

the class TestRepeatedFunction method testRepeated.

@Test
public void testRepeated(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    //    System.out.println(System.getProperty("java.class.path"));
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(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.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) BitVector(org.apache.drill.exec.vector.BitVector) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest)

Example 5 with BitVector

use of org.apache.drill.exec.vector.BitVector in project drill by apache.

the class BooleanGen method setValue.

@Override
public void setValue(ValueVector v, int index) {
    BitVector vector = (BitVector) v;
    vector.getMutator().set(index, value());
}
Also used : BitVector(org.apache.drill.exec.vector.BitVector)

Aggregations

BitVector (org.apache.drill.exec.vector.BitVector)6 Test (org.junit.Test)4 ExecTest (org.apache.drill.exec.ExecTest)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 Properties (java.util.Properties)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)1 FragmentContext (org.apache.drill.exec.ops.FragmentContext)1 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)1 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)1 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)1 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)1 BaseValueVector (org.apache.drill.exec.vector.BaseValueVector)1 IntVector (org.apache.drill.exec.vector.IntVector)1 NullableUInt4Vector (org.apache.drill.exec.vector.NullableUInt4Vector)1 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)1 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)1 ValueVector (org.apache.drill.exec.vector.ValueVector)1 VarCharVector (org.apache.drill.exec.vector.VarCharVector)1