Search in sources :

Example 6 with BatchAccessor

use of org.apache.drill.exec.physical.impl.protocol.BatchAccessor in project drill by apache.

the class TestScanLimit method testLimit1.

/**
 * LIMIT 1, simplest case
 */
@Test
public void testLimit1() {
    TestFixture fixture = new TestFixture(1);
    ScanOperatorExec scan = fixture.scan;
    // Reader builds schema, and stops after one row, though the reader
    // itself is happy to provide more.
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    BatchAccessor batch = scan.batchAccessor();
    assertEquals(1, batch.rowCount());
    batch.release();
    // No second batch or second reader
    assertFalse(scan.next());
    fixture.close();
    // Only the first of the two readers were created.
    assertEquals(1, fixture.createCount());
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) BatchAccessor(org.apache.drill.exec.physical.impl.protocol.BatchAccessor) Test(org.junit.Test)

Example 7 with BatchAccessor

use of org.apache.drill.exec.physical.impl.protocol.BatchAccessor in project drill by apache.

the class TestScanLimit method testLimitOnSecondBatch.

/**
 * LIMIT 75, halfway through second batch.
 */
@Test
public void testLimitOnSecondBatch() {
    TestFixture fixture = new TestFixture(75);
    ScanOperatorExec scan = fixture.scan;
    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());
    fixture.close();
    // Only the first of the two readers were created.
    assertEquals(1, fixture.createCount());
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) BatchAccessor(org.apache.drill.exec.physical.impl.protocol.BatchAccessor) Test(org.junit.Test)

Example 8 with BatchAccessor

use of org.apache.drill.exec.physical.impl.protocol.BatchAccessor 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)

Example 9 with BatchAccessor

use of org.apache.drill.exec.physical.impl.protocol.BatchAccessor in project drill by apache.

the class TestScanLimit method testLimitOnBatchEnd.

/**
 * LIMIT 50, same as batch size, to check boundary conditions.
 */
@Test
public void testLimitOnBatchEnd() {
    TestFixture fixture = new TestFixture(50);
    ScanOperatorExec scan = fixture.scan;
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    BatchAccessor batch = scan.batchAccessor();
    assertEquals(50, batch.rowCount());
    batch.release();
    // No second batch or second reader
    assertFalse(scan.next());
    fixture.close();
    // Only the first of the two readers were created.
    assertEquals(1, fixture.createCount());
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) BatchAccessor(org.apache.drill.exec.physical.impl.protocol.BatchAccessor) Test(org.junit.Test)

Example 10 with BatchAccessor

use of org.apache.drill.exec.physical.impl.protocol.BatchAccessor in project drill by apache.

the class TestScanOperExecLimit method testLimit0.

/**
 * LIMIT 0, to obtain only the schema.
 */
@Test
public void testLimit0() {
    Mock50RowReader reader1 = new Mock50RowReader();
    Mock50RowReader reader2 = new Mock50RowReader();
    BaseScanFixtureBuilder builder = simpleBuilder(reader1, reader2);
    builder.builder.limit(0);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertTrue(scan.next());
    BatchAccessor batch = scan.batchAccessor();
    assertEquals(0, batch.rowCount());
    assertEquals(1, batch.schema().getFieldCount());
    batch.release();
    // No second batch or 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)

Aggregations

BatchAccessor (org.apache.drill.exec.physical.impl.protocol.BatchAccessor)13 Test (org.junit.Test)13 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)7 ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)7 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)1 ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)1 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator)1 SubOperatorTest (org.apache.drill.test.SubOperatorTest)1