Search in sources :

Example 16 with IntVector

use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.

the class TestFixedWidthWriter method testRestartRow.

@Test
public void testRestartRow() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write rows, rewriting every other row.
        writer.startRow();
        index.index = 0;
        for (int i = 0; i < 50; i++) {
            writer.setInt(i);
            if (i % 2 == 0) {
                writer.saveRow();
                writer.startRow();
                index.index++;
            } else {
                writer.restartRow();
            }
        }
        writer.endWrite();
        for (int i = 0; i < 25; i++) {
            assertEquals(2 * i, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 17 with IntVector

use of org.apache.drill.exec.vector.IntVector in project drill by axbaretto.

the class TestVectorLimits method testFixedVector.

/**
 * Test a vector directly using the vector mutator to ensure
 * that the <tt>setScalar</tt> method works for the maximum
 * row count.
 * <p>
 * This test is a proxy for all the other fixed types, since all
 * share the same code template.
 */
@Test
public void testFixedVector() {
    // Create a non-nullable int vector: a typical fixed-size vector
    @SuppressWarnings("resource") IntVector vector = new IntVector(makeField(MinorType.INT, DataMode.REQUIRED), fixture.allocator());
    // Sanity test of generated constants.
    assertTrue(IntVector.MAX_SCALAR_COUNT <= ValueVector.MAX_ROW_COUNT);
    assertEquals(4, IntVector.VALUE_WIDTH);
    assertTrue(IntVector.NET_MAX_SCALAR_SIZE <= ValueVector.MAX_BUFFER_SIZE);
    // Allocate a default size, small vector. Forces test of
    // the auto-grow (setSafe()) aspect of setScalar().
    vector.allocateNew();
    // Write to the vector until it complains. At that point,
    // we should have written up to the static fixed value count
    // (which is computed to stay below the capacity limit.)
    IntVector.Mutator mutator = vector.getMutator();
    for (int i = 0; i < 2 * ValueVector.MAX_ROW_COUNT; i++) {
        try {
            mutator.setScalar(i, i);
        } catch (VectorOverflowException e) {
            assertEquals(IntVector.MAX_SCALAR_COUNT, i);
            break;
        }
    }
    // The vector should be below the allocation limit. Since this
    // is an int vector, in practice the size will be far below
    // the overall limit (if the limit stays at 16 MB.) But, it should
    // be at the type-specific limit since we filled up the vector.
    assertEquals(IntVector.NET_MAX_SCALAR_SIZE, vector.getBuffer().getActualMemoryConsumed());
    vector.close();
}
Also used : NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) IntVector(org.apache.drill.exec.vector.IntVector) RepeatedIntVector(org.apache.drill.exec.vector.RepeatedIntVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

Example 18 with IntVector

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

the class TestHiveUDFs method testUDF.

@Test
public void testUDF() throws Throwable {
    String planString = Resources.toString(Resources.getResource("functions/hive/UDF.json"), Charsets.UTF_8);
    List<QueryDataBatch> results = testPhysicalWithResults(planString);
    RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
    for (QueryDataBatch result : results) {
        batchLoader.load(result.getHeader().getDef(), result.getData());
        if (batchLoader.getRecordCount() <= 0) {
            result.release();
            batchLoader.clear();
            continue;
        }
        // Output columns and types
        // 1. str1 : VarChar
        // 2. str1Length : Int
        // 3. str1Ascii : Int
        // 4. flt1 : Float4
        // 5. pow : Float8
        VarCharVector str1V = (VarCharVector) batchLoader.getValueAccessorById(VarCharVector.class, 0).getValueVector();
        BigIntVector str1LengthV = (BigIntVector) batchLoader.getValueAccessorById(BigIntVector.class, 1).getValueVector();
        IntVector str1AsciiV = (IntVector) batchLoader.getValueAccessorById(IntVector.class, 2).getValueVector();
        Float4Vector flt1V = (Float4Vector) batchLoader.getValueAccessorById(Float4Vector.class, 3).getValueVector();
        NullableFloat8Vector powV = (NullableFloat8Vector) batchLoader.getValueAccessorById(NullableFloat8Vector.class, 4).getValueVector();
        for (int i = 0; i < batchLoader.getRecordCount(); i++) {
            String str1 = new String(str1V.getAccessor().get(i), Charsets.UTF_8);
            long str1Length = str1LengthV.getAccessor().get(i);
            assertTrue(str1.length() == str1Length);
            float flt1 = flt1V.getAccessor().get(i);
            double pow = 0;
            if (!powV.getAccessor().isNull(i)) {
                pow = powV.getAccessor().get(i);
                assertTrue(Math.pow(flt1, 2.0) == pow);
            }
        }
        result.release();
        batchLoader.clear();
    }
}
Also used : NullableFloat8Vector(org.apache.drill.exec.vector.NullableFloat8Vector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) Float4Vector(org.apache.drill.exec.vector.Float4Vector) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) HiveStorageTest(org.apache.drill.categories.HiveStorageTest) Test(org.junit.Test) SlowTest(org.apache.drill.categories.SlowTest)

Example 19 with IntVector

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

the class LateralJoinBatch method getRowIdToRowCountMapping.

/**
 * Creates a map of rowId to number of rows with that rowId in the right
 * incoming batch of Lateral Join. It is expected from UnnestRecordBatch to
 * add an implicit column of IntVectorType with each output row. All the array
 * records belonging to same row in left incoming will have same rowId in the
 * Unnest output batch.
 *
 * @return - map of rowId to rowCount in right batch
 */
@SuppressWarnings("unused")
private Map<Integer, Integer> getRowIdToRowCountMapping() {
    final Map<Integer, Integer> indexToFreq = new HashMap<>();
    final IntVector rowIdVector = (IntVector) implicitVector;
    int prevRowId = rowIdVector.getAccessor().get(rightJoinIndex);
    int countRows = 1;
    for (int i = rightJoinIndex + 1; i < right.getRecordCount(); ++i) {
        int currentRowId = rowIdVector.getAccessor().get(i);
        if (prevRowId == currentRowId) {
            ++countRows;
        } else {
            indexToFreq.put(prevRowId, countRows);
            prevRowId = currentRowId;
            countRows = 1;
        }
    }
    indexToFreq.put(prevRowId, countRows);
    return indexToFreq;
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) HashMap(java.util.HashMap)

Example 20 with IntVector

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

the class HashPartition method appendBatch.

/**
 *  Append the incoming batch (actually only the vectors of that batch) into the tmp list
 */
public void appendBatch(VectorAccessible batch) {
    assert numPartitions == 1;
    int recordCount = batch.getRecordCount();
    currHVVector = new IntVector(MaterializedField.create(HASH_VALUE_COLUMN_NAME, HVtype), allocator);
    currHVVector.allocateNew(recordCount);
    try {
        // For every record in the build batch, hash the key columns and keep the result
        for (int ind = 0; ind < recordCount; ind++) {
            int hashCode = getBuildHashCode(ind);
            // store the hash value in the new HV column
            currHVVector.getMutator().set(ind, hashCode);
        }
    } catch (SchemaChangeException sce) {
    }
    VectorContainer container = new VectorContainer();
    List<ValueVector> vectors = Lists.newArrayList();
    for (VectorWrapper<?> v : batch) {
        TransferPair tp = v.getValueVector().getTransferPair(allocator);
        tp.transfer();
        vectors.add(tp.getTo());
    }
    container.addCollection(vectors);
    // the HV vector is added as an extra "column"
    container.add(currHVVector);
    container.setRecordCount(recordCount);
    container.buildSchema(BatchSchema.SelectionVectorMode.NONE);
    tmpBatchesList.add(container);
    partitionBatchesCount++;
    currHVVector = null;
    numInMemoryRecords += recordCount;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) TransferPair(org.apache.drill.exec.record.TransferPair) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) IntVector(org.apache.drill.exec.vector.IntVector) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Aggregations

IntVector (org.apache.drill.exec.vector.IntVector)69 Test (org.junit.Test)56 BigIntVector (org.apache.drill.exec.vector.BigIntVector)26 SchemaPath (org.apache.drill.common.expression.SchemaPath)23 ExecTest (org.apache.drill.exec.ExecTest)22 SubOperatorTest (org.apache.drill.test.SubOperatorTest)21 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)18 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)18 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)18 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)18 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)18 OperatorTest (org.apache.drill.categories.OperatorTest)14 IntColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter)14 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)13 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)12 UserClientConnection (org.apache.drill.exec.rpc.UserClientConnection)12 BigIntHolder (org.apache.drill.exec.expr.holders.BigIntHolder)6 IntHolder (org.apache.drill.exec.expr.holders.IntHolder)6 FragmentContext (org.apache.drill.exec.ops.FragmentContext)6 MaterializedField (org.apache.drill.exec.record.MaterializedField)6