Search in sources :

Example 6 with UInt4Vector

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

the class TestBatchValidator method testRepeatedBadArrayOffset.

@Test
public void testRepeatedBadArrayOffset() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR, DataMode.REPEATED).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).add((Object) new String[] {}).add((Object) new String[] { "fred", "barney", "wilma" }).add((Object) new String[] { "dino" }).build();
    VectorAccessible va = batch.vectorAccessible();
    @SuppressWarnings("resource") ValueVector v = va.iterator().next().getValueVector();
    RepeatedVarCharVector vc = (RepeatedVarCharVector) v;
    @SuppressWarnings("resource") UInt4Vector ov = vc.getOffsetVector();
    ov.getMutator().set(3, 1);
    BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
    validator.validate();
    List<String> errors = validator.errors();
    assertEquals(1, errors.size());
    assertTrue(errors.get(0).contains("Decreasing offsets"));
    batch.clear();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) BatchValidator(org.apache.drill.exec.physical.impl.validate.BatchValidator) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) Test(org.junit.Test)

Example 7 with UInt4Vector

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

the class FixedWidthRepeatedReader method readAndStoreValueSizeInformation.

@SuppressWarnings("resource")
@Override
protected boolean readAndStoreValueSizeInformation() {
    int numLeftoverVals = 0;
    if (notFishedReadingList) {
        numLeftoverVals = repeatedValuesInCurrentList;
        readRecords(numLeftoverVals);
        notFishedReadingList = false;
        pageReader.valuesReadyToRead = 0;
        try {
            boolean stopReading = readPage();
            if (stopReading) {
                // hit the end of a row group
                return false;
            }
        } catch (IOException e) {
            throw new RuntimeException("Unexpected error reading parquet repeated column.", e);
        }
    }
    if (currDefLevel == -1) {
        currDefLevel = pageReader.definitionLevels.readInteger();
        definitionLevelsRead++;
    }
    int repLevel;
    if (columnDescriptor.getMaxDefinitionLevel() == currDefLevel) {
        if (repeatedValuesInCurrentList == -1 || notFishedReadingList) {
            repeatedValuesInCurrentList = 1;
            do {
                repLevel = pageReader.repetitionLevels.readInteger();
                if (repLevel > 0) {
                    repeatedValuesInCurrentList++;
                    currDefLevel = pageReader.definitionLevels.readInteger();
                    definitionLevelsRead++;
                    // we hit the end of this page, without confirmation that we reached the end of the current record
                    if (definitionLevelsRead == pageReader.currentPageCount) {
                        // to add it to the read )
                        if (totalValuesRead + pageReader.valuesReadyToRead + repeatedValuesInCurrentList != columnChunkMetaData.getValueCount()) {
                            notFishedReadingList = true;
                            // as those that spill into the next page will be added to the next batch
                            return true;
                        }
                    }
                }
            } while (repLevel != 0);
        }
    } else {
        repeatedValuesInCurrentList = 0;
    }
    // this should not fail
    final UInt4Vector offsets = valueVec.getOffsetVector();
    offsets.getMutator().setSafe(repeatedGroupsReadInCurrentPass + 1, offsets.getAccessor().get(repeatedGroupsReadInCurrentPass));
    // This field is being referenced in the superclass determineSize method, so we need to set it here
    // again going to make this the length in BYTES to avoid repetitive multiplication/division
    dataTypeLengthInBits = repeatedValuesInCurrentList * dataTypeLengthInBytes;
    return false;
}
Also used : IOException(java.io.IOException) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector)

Example 8 with UInt4Vector

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

the class TestBatchValidator method testVariableMissingLast.

@Test
public void testVariableMissingLast() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).add("x").add("y").add("z").build();
    // Here we are evil: stomp on the last offset to simulate corruption.
    // Don't do this in real code!
    VectorAccessible va = batch.vectorAccessible();
    @SuppressWarnings("resource") ValueVector v = va.iterator().next().getValueVector();
    VarCharVector vc = (VarCharVector) v;
    @SuppressWarnings("resource") UInt4Vector ov = vc.getOffsetVector();
    assertTrue(ov.getAccessor().get(3) > 0);
    ov.getMutator().set(3, 0);
    // Validator should catch the error.
    BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
    validator.validate();
    List<String> errors = validator.errors();
    assertEquals(1, errors.size());
    assertTrue(errors.get(0).contains("Decreasing offsets"));
    batch.clear();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) BatchValidator(org.apache.drill.exec.physical.impl.validate.BatchValidator) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) Test(org.junit.Test)

Example 9 with UInt4Vector

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

the class TestValueVector method testFixedType.

@Test
public void testFixedType() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE);
    // Create a new value vector for 1024 integers.
    try (final UInt4Vector vector = new UInt4Vector(field, allocator)) {
        final UInt4Vector.Mutator m = vector.getMutator();
        vector.allocateNew(1024);
        // Put and set a few values
        m.setSafe(0, 100);
        m.setSafe(1, 101);
        m.setSafe(100, 102);
        m.setSafe(1022, 103);
        m.setSafe(1023, 104);
        final UInt4Vector.Accessor accessor = vector.getAccessor();
        assertEquals(100, accessor.get(0));
        assertEquals(101, accessor.get(1));
        assertEquals(102, accessor.get(100));
        assertEquals(103, accessor.get(1022));
        assertEquals(104, accessor.get(1023));
    }
}
Also used : MaterializedField(org.apache.drill.exec.record.MaterializedField) NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)9 ValueVector (org.apache.drill.exec.vector.ValueVector)5 Test (org.junit.Test)5 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)4 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)4 VarCharVector (org.apache.drill.exec.vector.VarCharVector)4 BatchValidator (org.apache.drill.exec.physical.impl.validate.BatchValidator)3 BatchSchema (org.apache.drill.exec.record.BatchSchema)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 NullableUInt4Vector (org.apache.drill.exec.vector.NullableUInt4Vector)3 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)3 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)3 ExecTest (org.apache.drill.exec.ExecTest)2 IOException (java.io.IOException)1 BaseValueVector (org.apache.drill.exec.vector.BaseValueVector)1 BitVector (org.apache.drill.exec.vector.BitVector)1 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)1 MapVector (org.apache.drill.exec.vector.complex.MapVector)1 RepeatedListVector (org.apache.drill.exec.vector.complex.RepeatedListVector)1 RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)1