Search in sources :

Example 16 with ResultVectorCache

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();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 17 with ResultVectorCache

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());
}
Also used : ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) IntVector(org.apache.drill.exec.vector.IntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 18 with ResultVectorCache

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();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ResultVectorCache (org.apache.drill.exec.physical.resultSet.ResultVectorCache)18 SubOperatorTest (org.apache.drill.test.SubOperatorTest)18 Test (org.junit.Test)18 NullResultVectorCacheImpl (org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl)15 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)15 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)15 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)14 NullBuilderBuilder (org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder)7 VectorContainer (org.apache.drill.exec.record.VectorContainer)7 EvfTest (org.apache.drill.categories.EvfTest)5 ResolvedRow (org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)4 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)4 ArrayList (java.util.ArrayList)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 ValueVector (org.apache.drill.exec.vector.ValueVector)2 IntVector (org.apache.drill.exec.vector.IntVector)1