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();
}
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;
}
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();
}
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));
}
}
Aggregations