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