Search in sources :

Example 76 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestRowBatchMerger method testFlatWithNulls.

@Test
public void testFlatWithNulls() {
    // Create the first batch
    RowSetSource first = makeFirst();
    // Create null columns
    NullColumnBuilder builder = new NullBuilderBuilder().build();
    ResolvedRow resolvedTuple = new ResolvedRow(builder);
    resolvedTuple.add(new TestProjection(resolvedTuple, 1));
    resolvedTuple.add(resolvedTuple.nullBuilder().add("null1"));
    resolvedTuple.add(resolvedTuple.nullBuilder().add("null2", Types.optional(MinorType.VARCHAR)));
    resolvedTuple.add(new TestProjection(resolvedTuple, 0));
    // Build the null values
    ResultVectorCache cache = new NullResultVectorCacheImpl(fixture.allocator());
    builder.build(cache);
    builder.load(first.rowSet().rowCount());
    // Do the merge
    VectorContainer output = new VectorContainer(fixture.allocator());
    resolvedTuple.project(first.rowSet().container(), output);
    output.setRecordCount(first.rowSet().rowCount());
    RowSet result = fixture.wrap(output);
    // Verify
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("null1", MinorType.INT).addNullable("null2", MinorType.VARCHAR).add("d", MinorType.VARCHAR).buildSchema();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, null, null, "barney").addRow(20, null, null, "wilma").build();
    new RowSetComparison(expected).verifyAndClearAll(result);
    builder.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) NullBuilderBuilder(org.apache.drill.exec.physical.impl.scan.project.NullColumnBuilder.NullBuilderBuilder) VectorContainer(org.apache.drill.exec.record.VectorContainer) ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResolvedRow(org.apache.drill.exec.physical.impl.scan.project.ResolvedTuple.ResolvedRow) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) NullResultVectorCacheImpl(org.apache.drill.exec.physical.resultSet.impl.NullResultVectorCacheImpl) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 77 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestScanLifecycleLimit method testLimitOnBatchEnd.

/**
 * LIMIT 50, same as batch size, to check boundary conditions.
 */
@Test
public void testLimitOnBatchEnd() {
    Pair<TwoReaderFactory, ScanLifecycle> pair = setupScan(50);
    TwoReaderFactory factory = pair.getLeft();
    ScanLifecycle scan = pair.getRight();
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet result = fixture.wrap(reader.output());
    assertEquals(50, result.rowCount());
    result.clear();
    // No second batch
    assertFalse(reader.next());
    reader.close();
    // No next reader, despite there being two, since we hit the limit.
    assertNull(scan.nextReader());
    scan.close();
    // Only the first of the two readers were created.
    assertEquals(1, factory.count());
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) Test(org.junit.Test)

Example 78 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestScanLifecycleLimit method testLimit0.

/**
 * LIMIT 0, to obtain only the schema.
 */
@Test
public void testLimit0() {
    Pair<TwoReaderFactory, ScanLifecycle> pair = setupScan(0);
    TwoReaderFactory factory = pair.getLeft();
    ScanLifecycle scan = pair.getRight();
    // Reader builds schema, but returns no data, though the reader
    // itself is happy to provide data.
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet result = fixture.wrap(reader.output());
    assertEquals(0, result.rowCount());
    assertEquals(1, result.schema().size());
    result.clear();
    // No second batch
    assertFalse(reader.next());
    reader.close();
    // No next reader, despite there being two, since we hit the limit.
    assertNull(scan.nextReader());
    scan.close();
    // Only the first of the two readers were created.
    assertEquals(1, factory.count());
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) Test(org.junit.Test)

Example 79 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestScanLifecycleLimit method testLimit1.

/**
 * LIMIT 1, simplest case
 */
@Test
public void testLimit1() {
    Pair<TwoReaderFactory, ScanLifecycle> pair = setupScan(1);
    TwoReaderFactory factory = pair.getLeft();
    ScanLifecycle scan = pair.getRight();
    // Reader builds schema, and stops after one row, though the reader
    // itself is happy to provide more.
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet result = fixture.wrap(reader.output());
    assertEquals(1, result.rowCount());
    assertEquals(1, result.schema().size());
    result.clear();
    // No second batch
    assertFalse(reader.next());
    reader.close();
    // No next reader, despite there being two, since we hit the limit.
    assertNull(scan.nextReader());
    scan.close();
    // Only the first of the two readers were created.
    assertEquals(1, factory.count());
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) Test(org.junit.Test)

Example 80 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestScanLifecycleTwoReaders method testExpandingSchemaAllowingSchemaChange.

/**
 * SELECT * FROM two readers, one (a, b), the other (a, b, c).
 * With schema change enabled, the third column shows up only
 * in the second batch, forcing a schema change downstream.
 */
@Test
public void testExpandingSchemaAllowingSchemaChange() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.allowSchemaChange(true);
    builder.readerFactory(new TwoReaderFactory() {

        @Override
        public ManagedReader firstReader(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 1);
        }

        @Override
        public ManagedReader secondReader(SchemaNegotiator negotiator) {
            return new MockThreeColReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    verifyStandardReader(scan, 0);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(MockThreeColReader.READER_SCHEMA).addRow(101, "wilma", 1001).addRow(102, "betty", 1002).build();
    RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
    assertFalse(reader.next());
    reader.close();
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator) ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Aggregations

RowSet (org.apache.drill.exec.physical.rowSet.RowSet)725 Test (org.junit.Test)690 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)583 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)574 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)297 ClusterTest (org.apache.drill.test.ClusterTest)253 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)233 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)137 SubOperatorTest (org.apache.drill.test.SubOperatorTest)128 JsonTest (org.apache.drill.categories.JsonTest)112 EvfTest (org.apache.drill.categories.EvfTest)107 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)97 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)63 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)61 QueryBuilder (org.apache.drill.test.QueryBuilder)61 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)60 OperatorTest (org.apache.drill.categories.OperatorTest)53 VectorContainer (org.apache.drill.exec.record.VectorContainer)31 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)28 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)27