use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestResultVectorCache method testBasics.
@Test
public void testBasics() {
final ResultVectorCache cache = new ResultVectorCacheImpl(fixture.allocator());
// Create a vector
final MaterializedField required = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.INT).setMode(DataMode.REQUIRED).build());
final ValueVector vector1 = cache.vectorFor(required);
assertTrue(vector1.getField().isEquivalent(required));
// Request the same schema, should get the same vector.
final ValueVector vector2 = cache.vectorFor(required);
assertSame(vector1, vector2);
// Non-permissive. Change in mode means different vector.
final MaterializedField optional = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.INT).setMode(DataMode.OPTIONAL).build());
final ValueVector vector3 = cache.vectorFor(optional);
assertTrue(vector3.getField().isEquivalent(optional));
assertNotSame(vector1, vector3);
// Asking for the required type again produces a new vector.
// Name is the key, and we can have only one type associated
// with each name.
final ValueVector vector4 = cache.vectorFor(required);
assertTrue(vector4.getField().isEquivalent(required));
assertNotSame(vector3, vector4);
assertNotSame(vector1, vector4);
// Varchar, no precision.
final MaterializedField varchar1 = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.REQUIRED).build());
final ValueVector vector5 = cache.vectorFor(varchar1);
assertTrue(vector5.getField().isEquivalent(varchar1));
// Varchar, with precision, no match.
final MaterializedField varchar2 = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.REQUIRED).setPrecision(10).build());
final ValueVector vector6 = cache.vectorFor(varchar2);
assertTrue(vector6.getField().isEquivalent(varchar2));
assertNotSame(vector5, vector6);
// Does match if same precision.
final ValueVector vector7 = cache.vectorFor(varchar2);
assertTrue(vector7.getField().isEquivalent(varchar2));
assertSame(vector6, vector7);
// Different names have different types
final MaterializedField varchar3 = MaterializedField.create("b", MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.REQUIRED).setPrecision(10).build());
final ValueVector vector8 = cache.vectorFor(varchar3);
assertTrue(vector8.getField().isEquivalent(varchar3));
assertSame(vector7, cache.vectorFor(varchar2));
assertSame(vector8, cache.vectorFor(varchar3));
((ResultVectorCacheImpl) cache).close();
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestResultVectorCache method testClose.
@Test
public void testClose() {
final ResultVectorCache cache = new ResultVectorCacheImpl(fixture.allocator());
// Create a vector
final MaterializedField required = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.INT).setMode(DataMode.REQUIRED).build());
final IntVector vector1 = (IntVector) cache.vectorFor(required);
vector1.allocateNew(100);
// Close the cache. Note: close is on the implementation, not
// the interface, because only the implementation should decide
// when to close.
// Close should release the allocated vector. If not, then
// this test suite will fail with a memory leak when shutting
// down the root allocator.
((ResultVectorCacheImpl) cache).close();
assertEquals(0, vector1.getBuffer().capacity());
}
use of org.apache.drill.exec.physical.resultSet.ResultVectorCache in project drill by apache.
the class TestResultVectorCache method testPermissive.
@Test
public void testPermissive() {
final ResultVectorCache cache = new ResultVectorCacheImpl(fixture.allocator(), true);
// Create a nullable vector
final MaterializedField optional = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.INT).setMode(DataMode.OPTIONAL).build());
final ValueVector vector1 = cache.vectorFor(optional);
// Ask for a required version of the same name and type.
// Should return the nullable version.
final MaterializedField required = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.INT).setMode(DataMode.REQUIRED).build());
final ValueVector vector2 = cache.vectorFor(required);
assertTrue(vector2.getField().isEquivalent(optional));
assertSame(vector1, vector2);
// Repeat with Varchar
final MaterializedField varchar1 = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.OPTIONAL).build());
final ValueVector vector3 = cache.vectorFor(varchar1);
final MaterializedField varchar2 = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.REQUIRED).build());
final ValueVector vector4 = cache.vectorFor(varchar2);
assertSame(vector3, vector4);
// Larger precision. Needs new vector.
final MaterializedField varchar3 = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.OPTIONAL).setPrecision(10).build());
final ValueVector vector5 = cache.vectorFor(varchar3);
assertTrue(vector5.getField().isEquivalent(varchar3));
assertNotSame(vector4, vector5);
// Smaller precision, reuse vector.
final ValueVector vector6 = cache.vectorFor(varchar1);
assertTrue(vector6.getField().isEquivalent(varchar3));
assertSame(vector5, vector6);
// Same precision, required: reuse vector.
final MaterializedField varchar4 = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.REQUIRED).setPrecision(5).build());
final ValueVector vector7 = cache.vectorFor(varchar4);
assertTrue(vector7.getField().isEquivalent(varchar3));
assertSame(vector5, vector7);
// TODO: Repeat with decimal precision and scale.
((ResultVectorCacheImpl) cache).close();
}
Aggregations