use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by axbaretto.
the class TestFixedWidthWriter method testRollover.
/**
* The rollover method is used during vector overflow.
*/
@Test
public void testRollover() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
// Overflow occurs after writing the 11th row
index.index = 10;
writer.startRow();
writer.setInt(10);
// Overflow occurs
writer.preRollover();
for (int i = 0; i < 15; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
vector.getMutator().set(0, 10);
writer.postRollover();
index.index = 0;
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.setInt(10 + i);
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 5; i++) {
assertEquals(10 + i, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by axbaretto.
the class TestFixedWidthWriter method testRolloverWithEmpties.
/**
* Simulate the case in which the tail end of an overflow
* batch has empties. <tt>preRollover()</tt> should back-fill
* them with the next offset prior to rollover.
*/
@Test
public void testRolloverWithEmpties() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
for (int i = 10; i < 15; i++) {
index.index = i;
writer.startRow();
writer.saveRow();
}
// Overflow occurs before writing the 16th row
index.index = 15;
writer.startRow();
// Overflow occurs. This should fill empty offsets.
writer.preRollover();
for (int i = 0; i < 10; i++) {
assertEquals(i, vector.getAccessor().get(i));
}
for (int i = 10; i < 15; i++) {
assertEquals(0, vector.getAccessor().get(i));
}
for (int i = 0; i < 20; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
writer.postRollover();
index.index = 0;
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.saveRow();
}
for (int i = 5; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setInt(i + 20);
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 5; i++) {
assertEquals(0, vector.getAccessor().get(i));
}
for (int i = 5; i < 10; i++) {
assertEquals(i + 20, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter 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.accessor.ColumnAccessors.IntColumnWriter in project drill by apache.
the class TestFixedWidthWriter method testRollover.
/**
* The rollover method is used during vector overflow.
*/
@Test
public void testRollover() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 10; i++) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
// Overflow occurs after writing the 11th row
index.index = 10;
writer.startRow();
writer.setInt(10);
// Overflow occurs
writer.preRollover();
for (int i = 0; i < 15; i++) {
vector.getMutator().set(i, 0xdeadbeef);
}
vector.getMutator().set(0, 10);
writer.postRollover();
index.index = 0;
writer.saveRow();
for (int i = 1; i < 5; i++) {
index.index = i;
writer.startRow();
writer.setInt(10 + i);
writer.saveRow();
}
writer.endWrite();
for (int i = 0; i < 5; i++) {
assertEquals(10 + i, vector.getAccessor().get(i));
}
}
}
use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by apache.
the class TestFixedWidthWriter method testFillEmpties.
/**
* Required, fixed-width vectors are back-filling with 0 to fill in missing
* values. While using zero is not strictly SQL compliant, it is better
* than failing. (The SQL solution would be to fill with nulls, but a
* required vector does not support nulls...)
*/
@Test
public void testFillEmpties() {
try (IntVector vector = allocVector(1000)) {
TestIndex index = new TestIndex();
IntColumnWriter writer = makeWriter(vector, index);
writer.startWrite();
for (int i = 0; i < 501; i += 5) {
index.index = i;
writer.startRow();
writer.setInt(i);
writer.saveRow();
}
// At end, vector index defined to point one past the
// last row. That is, the vector index gives the row count.
index.index = 504;
writer.endWrite();
for (int i = 0; i < 504; i++) {
assertEquals("Mismatch on " + i, (i % 5) == 0 ? i : 0, vector.getAccessor().get(i));
}
}
}
Aggregations