use of org.apache.drill.exec.physical.impl.scan.RowBatchReader in project drill by apache.
the class TestScanLifecycleTwoReaders method testSpecifiedColumnOrder.
/**
* {@code SELECT , b FROM} (b,a) then (a, b). The order of the project list
* drives the order of the results.
*/
@Test
public void testSpecifiedColumnOrder() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.projection(RowSetTestUtils.projectList("a", "b"));
builder.readerFactory(new TwoReaderFactory() {
@Override
public ManagedReader firstReader(SchemaNegotiator negotiator) {
return new MockReorderedReader(negotiator);
}
@Override
public ManagedReader secondReader(SchemaNegotiator negotiator) {
return new MockLateSchemaReader(negotiator, 1);
}
});
ScanLifecycle scan = buildScan(builder);
RowBatchReader reader = scan.nextReader();
reader = scan.nextReader();
assertTrue(reader.open());
assertTrue(reader.next());
RowSet expected = fixture.rowSetBuilder(SCHEMA).addRow(30, "barney").addRow(40, "betty").build();
RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
assertFalse(reader.next());
reader.close();
verifyStandardReader(scan, 0);
scan.close();
}
use of org.apache.drill.exec.physical.impl.scan.RowBatchReader in project drill by apache.
the class TestScanLifecycleTwoReaders method testColumnReorderingAB.
/**
* {@code SELECT * FROM} (a, b) then (b,a). The order of the first
* table drives the order of the results.
*/
@Test
public void testColumnReorderingAB() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.readerFactory(new TwoReaderFactory() {
@Override
public ManagedReader firstReader(SchemaNegotiator negotiator) {
return new MockLateSchemaReader(negotiator, 1);
}
@Override
public ManagedReader secondReader(SchemaNegotiator negotiator) {
return new MockReorderedReader(negotiator);
}
});
ScanLifecycle scan = buildScan(builder);
verifyStandardReader(scan, 0);
RowBatchReader reader = scan.nextReader();
reader = scan.nextReader();
assertTrue(reader.open());
assertTrue(reader.next());
RowSet expected = fixture.rowSetBuilder(SCHEMA).addRow(30, "barney").addRow(40, "betty").build();
RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
assertFalse(reader.next());
reader.close();
scan.close();
}
use of org.apache.drill.exec.physical.impl.scan.RowBatchReader in project drill by apache.
the class TestReaderErrors method testCloseError.
@Test
public void testCloseError() {
ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
builder.errorContext(b -> b.addContext("Scan context"));
builder.readerFactory(new SingleReaderFactory() {
@Override
public ManagedReader next(SchemaNegotiator negotiator) {
return new FailingReader(negotiator, "close");
}
});
ScanLifecycle scan = buildScan(builder);
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
assertFalse(reader.next());
try {
reader.close();
fail();
} catch (UserException e) {
// Expected
}
scan.close();
}
use of org.apache.drill.exec.physical.impl.scan.RowBatchReader in project drill by apache.
the class TestScanLifecycleLimit method testLimitOnSecondReader.
/**
* LIMIT 125: full first reader, limit on second
*/
@Test
public void testLimitOnSecondReader() {
Pair<TwoReaderFactory, ScanLifecycle> pair = setupScan(125);
TwoReaderFactory factory = pair.getLeft();
ScanLifecycle scan = pair.getRight();
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
// First batch
assertTrue(reader.next());
RowSet result = fixture.wrap(reader.output());
assertEquals(50, result.rowCount());
result.clear();
// Second batch
assertTrue(reader.next());
result = fixture.wrap(reader.output());
assertEquals(50, result.rowCount());
result.clear();
// No third batch
assertFalse(reader.next());
reader.close();
// Move to second reader.
reader = scan.nextReader();
assertNotNull(reader);
assertTrue(reader.open());
// First is limited
assertTrue(reader.next());
result = fixture.wrap(reader.output());
assertEquals(25, result.rowCount());
result.clear();
// No second batch
assertFalse(reader.next());
reader.close();
scan.close();
// Both readers were created.
assertEquals(2, factory.count());
}
use of org.apache.drill.exec.physical.impl.scan.RowBatchReader in project drill by apache.
the class TestScanLifecycleLimit method testLimitOnEOF.
/**
* LIMIT 100, at EOF of the first reader.
*/
@Test
public void testLimitOnEOF() {
Pair<TwoReaderFactory, ScanLifecycle> pair = setupScan(100);
TwoReaderFactory factory = pair.getLeft();
ScanLifecycle scan = pair.getRight();
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
// First batch
assertTrue(reader.next());
RowSet result = fixture.wrap(reader.output());
assertEquals(50, result.rowCount());
result.clear();
// Second batch
assertTrue(reader.next());
result = fixture.wrap(reader.output());
assertEquals(50, result.rowCount());
result.clear();
// No third 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());
}
Aggregations