Search in sources :

Example 21 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecEarlySchema method testMultipleReaders.

/**
 * Test normal case with multiple readers. These return
 * the same schema, so no schema change.
 */
@Test
public void testMultipleReaders() {
    MockNullEarlySchemaReader nullReader = new MockNullEarlySchemaReader();
    MockEarlySchemaReader reader1 = new MockEarlySchemaReader();
    reader1.batchLimit = 2;
    MockEarlySchemaReader reader2 = new MockEarlySchemaReader();
    reader2.batchLimit = 2;
    reader2.startIndex = 100;
    ScanFixture scanFixture = simpleFixture(nullReader, reader1, reader2);
    ScanOperatorExec scan = scanFixture.scanOp;
    // First batch, schema only.
    assertTrue(scan.buildSchema());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // Second batch.
    assertTrue(scan.next());
    assertEquals(1, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(0, scan.batchAccessor().container());
    // Third batch.
    assertTrue(scan.next());
    assertEquals(2, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(20, scan.batchAccessor().container());
    // Second reader. First batch includes data, no special first-batch
    // handling for the second reader.
    assertFalse(reader1.closeCalled);
    assertFalse(reader2.openCalled);
    assertTrue(scan.next());
    assertTrue(reader1.closeCalled);
    assertTrue(reader2.openCalled);
    assertEquals(1, reader2.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(100, scan.batchAccessor().container());
    // Second batch from second reader.
    assertTrue(scan.next());
    assertEquals(2, reader2.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(120, scan.batchAccessor().container());
    // EOF
    assertFalse(scan.next());
    assertTrue(reader2.closeCalled);
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) Test(org.junit.Test)

Example 22 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecLimit method testLimitOnEOF.

/**
 * LIMIT 100, at EOF of the first reader.
 */
@Test
public void testLimitOnEOF() {
    Mock50RowReader reader1 = new Mock50RowReader();
    Mock50RowReader reader2 = new Mock50RowReader();
    BaseScanFixtureBuilder builder = simpleBuilder(reader1, reader2);
    builder.builder.limit(100);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    BatchAccessor batch = scan.batchAccessor();
    assertEquals(50, batch.rowCount());
    batch.release();
    assertTrue(scan.next());
    batch = scan.batchAccessor();
    assertEquals(50, batch.rowCount());
    batch.release();
    // No second reader
    assertFalse(scan.next());
    scanFixture.close();
    assertTrue(reader1.openCalled);
    assertFalse(reader2.openCalled);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) BatchAccessor(org.apache.drill.exec.physical.impl.protocol.BatchAccessor) Test(org.junit.Test)

Example 23 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecLimit method testLimitOnScondBatch.

/**
 * LIMIT 75, halfway through second batch.
 */
@Test
public void testLimitOnScondBatch() {
    Mock50RowReader reader1 = new Mock50RowReader();
    Mock50RowReader reader2 = new Mock50RowReader();
    BaseScanFixtureBuilder builder = simpleBuilder(reader1, reader2);
    builder.builder.limit(75);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    BatchAccessor batch = scan.batchAccessor();
    assertEquals(50, batch.rowCount());
    batch.release();
    assertTrue(scan.next());
    batch = scan.batchAccessor();
    assertEquals(25, batch.rowCount());
    batch.release();
    // No second reader
    assertFalse(scan.next());
    scanFixture.close();
    assertTrue(reader1.openCalled);
    assertFalse(reader2.openCalled);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) BatchAccessor(org.apache.drill.exec.physical.impl.protocol.BatchAccessor) Test(org.junit.Test)

Example 24 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestScanOperExecOverflow method runOverflowTest.

private void runOverflowTest(boolean eofWithData) {
    OverflowReader reader1 = new OverflowReader();
    reader1.batchLimit = 2;
    reader1.reportEofWithOverflow = eofWithData;
    MockEarlySchemaReader reader2 = new MockEarlySchemaReader();
    reader2.batchLimit = 2;
    BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder();
    builder.projectAll();
    builder.addReader(reader1);
    builder.addReader(reader2);
    // Want overflow, set size and row counts at their limits.
    builder.builder.batchByteLimit(ScanSchemaOrchestrator.MAX_BATCH_BYTE_SIZE);
    builder.builder.batchRecordLimit(ScanSchemaOrchestrator.MAX_BATCH_ROW_COUNT);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // Second batch. Should be 1 less than the reader's row
    // count because the loader has its own one-row lookahead batch.
    assertTrue(scan.next());
    assertEquals(1, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    int prevRowCount = scan.batchAccessor().rowCount();
    assertEquals(reader1.rowCount - 1, prevRowCount);
    scan.batchAccessor().release();
    // Third batch, adds more data to the lookahead batch. Also overflows
    // so returned records is one less than total produced so far minus
    // those returned earlier.
    assertTrue(scan.next());
    assertEquals(2, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    assertEquals(reader1.rowCount - prevRowCount - 1, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    int prevReaderRowCount = reader1.rowCount;
    // Third batch. Returns the overflow row from the second batch of
    // the first reader.
    assertTrue(scan.next());
    assertEquals(eofWithData ? 2 : 3, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    assertEquals(1, scan.batchAccessor().rowCount());
    assertEquals(prevReaderRowCount, reader1.rowCount);
    scan.batchAccessor().release();
    // Second reader.
    assertTrue(scan.next());
    assertEquals(2, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // Second batch from second reader.
    assertTrue(scan.next());
    assertEquals(2, reader2.batchCount);
    assertEquals(2, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)

Example 25 with ScanFixture

use of org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture in project drill by apache.

the class TestMockRowReader method testOverflow.

/**
 * Test a mock varchar column large enough to cause vector overflow.
 */
@Test
public void testOverflow() {
    int rowCount = ValueVector.MAX_ROW_COUNT;
    MockTableDef.MockColumn[] cols = new MockTableDef.MockColumn[] { new MockTableDef.MockColumn("a", MinorType.INT, DataMode.REQUIRED, null, null, null, null, null, null), new MockTableDef.MockColumn("b", MinorType.VARCHAR, DataMode.REQUIRED, 1000, null, null, null, null, null) };
    MockTableDef.MockScanEntry entry = new MockTableDef.MockScanEntry(rowCount, true, null, null, cols);
    MockSubScanPOP config = new MockSubScanPOP("dummy", true, Collections.singletonList(entry));
    ManagedReader<SchemaNegotiator> reader = new ExtendedMockBatchReader(entry);
    @SuppressWarnings("unchecked") List<ManagedReader<SchemaNegotiator>> readers = Collections.singletonList(reader);
    // Create options and the scan operator
    ScanFixture mockBatch = buildScan(config, readers);
    ScanOperatorExec scan = mockBatch.scanOp;
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next call, return with data, limited by batch size.
    int totalRowCount = 0;
    int batchCount = 0;
    while (scan.next()) {
        assertTrue(scan.batchAccessor().rowCount() < ValueVector.MAX_ROW_COUNT);
        BatchAccessor batchAccessor = scan.batchAccessor();
        totalRowCount += batchAccessor.rowCount();
        batchCount++;
        batchAccessor.release();
    }
    assertEquals(ValueVector.MAX_ROW_COUNT, totalRowCount);
    assertTrue(batchCount > 1);
    mockBatch.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) ManagedReader(org.apache.drill.exec.physical.impl.scan.framework.ManagedReader) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) BatchAccessor(org.apache.drill.exec.physical.impl.protocol.BatchAccessor) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Aggregations

ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)52 Test (org.junit.Test)51 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)17 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)15 SubOperatorTest (org.apache.drill.test.SubOperatorTest)13 UserException (org.apache.drill.common.exceptions.UserException)9 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)8 BatchAccessor (org.apache.drill.exec.physical.impl.protocol.BatchAccessor)7 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator)7 BatchSchema (org.apache.drill.exec.record.BatchSchema)7 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)6 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)5 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)5 ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)5 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)5 HashMap (java.util.HashMap)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 VectorContainer (org.apache.drill.exec.record.VectorContainer)1