Search in sources :

Example 31 with RowBatchReader

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

the class TestScanLifecycleBasics method testEarlySchemaEmptyWithProject.

/**
 * Test SELECT a from an early-schema table of () (that is,
 * a schema that consists of zero columns.
 */
@Test
public void testEarlySchemaEmptyWithProject() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectList("a"));
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockEmptySchemaReader(negotiator);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    // Early schema: so output schema is available after open
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("a", MinorType.INT).build();
    assertEquals(expectedSchema, scan.outputSchema());
    assertTrue(reader.next());
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addSingleCol(null).addSingleCol(null).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) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) 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)

Example 32 with RowBatchReader

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

the class TestScanLifecycleBasics method testNullReader.

/**
 * Single reader empty schema, EOF on first next().
 * Since both no schema and no rows, we assume this to be a
 * null (not empty) result set, so no output schema.
 */
@Test
public void testNullReader() {
    ScanLifecycleBuilder builder = new ScanLifecycleBuilder();
    builder.readerFactory(new SingleReaderFactory() {

        @Override
        public ManagedReader next(SchemaNegotiator negotiator) {
            return new MockLateSchemaReader(negotiator, 0);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertFalse(reader.next());
    assertFalse(scan.hasOutputSchema());
    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) 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)

Example 33 with RowBatchReader

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

the class TestFileScanLifecycle method testSingleCol.

@Test
public void testSingleCol() {
    FileScanLifecycleBuilder builder = new FileScanLifecycleBuilder();
    builder.projection(RowSetTestUtils.projectList(FileScanUtils.FILE_NAME_COL, SchemaPath.DYNAMIC_STAR));
    builder.rootDir(MOCK_ROOT_PATH);
    builder.fileSplits(Collections.singletonList(new DummyFileWork(MOCK_FILE_PATH)));
    builder.readerFactory(new FileReaderFactory() {

        @Override
        public ManagedReader newReader(FileSchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    assertSame(ProjectionType.ALL, scan.schemaTracker().projectionType());
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    TupleMetadata expectedSchema = new SchemaBuilder().add(FileScanUtils.FILE_NAME_COL, IMPLICIT_COL_TYPE).addAll(SCHEMA).build();
    RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(MOCK_FILE_NAME, 10, "fred").addRow(MOCK_FILE_NAME, 20, "wilma").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) DummyFileWork(org.apache.drill.exec.physical.impl.scan.v3.file.BaseFileScanTest.DummyFileWork) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.ScanLifecycle) BaseTestScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.BaseTestScanLifecycle) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 34 with RowBatchReader

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

the class TestFileScanLifecycle method testCtorUserError.

/**
 * Verify that errors thrown from file-based readers include the file name
 * in addition to the scan and reader level error contexts.
 */
@Test
public void testCtorUserError() {
    FileScanLifecycleBuilder builder = new FileScanLifecycleBuilder();
    builder.errorContext(b -> b.addContext("Scan context"));
    builder.rootDir(MOCK_ROOT_PATH);
    builder.maxPartitionDepth(3);
    builder.projection(FileScanUtils.projectAllWithMetadata(3));
    builder.fileSplits(Collections.singletonList(new DummyFileWork(MOCK_FILE_PATH)));
    builder.useLegacyWildcardExpansion(true);
    builder.readerFactory(new FileReaderFactory() {

        @Override
        public ManagedReader newReader(FileSchemaNegotiator negotiator) {
            return new FailingReader(negotiator, "ctor-u");
        }
    });
    ScanLifecycle scan = buildScan(builder);
    RowBatchReader reader = scan.nextReader();
    try {
        reader.open();
        fail();
    } catch (UserException e) {
        String msg = e.getMessage();
        assertTrue(msg.contains("Oops ctor"));
        assertTrue(msg.contains("My custom context"));
        assertTrue(msg.contains("Scan context"));
        assertTrue(msg.contains(MOCK_FILE_NAME));
        assertNull(e.getCause());
    }
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) DummyFileWork(org.apache.drill.exec.physical.impl.scan.v3.file.BaseFileScanTest.DummyFileWork) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) UserException(org.apache.drill.common.exceptions.UserException) ScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.ScanLifecycle) BaseTestScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.BaseTestScanLifecycle) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 35 with RowBatchReader

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

the class TestFileScanLifecycle method testNoImplicit.

/**
 * Sanity test that the file scan framework works the same as the base framework
 * when no implicit columns are present.
 */
@Test
public void testNoImplicit() {
    FileScanLifecycleBuilder builder = new FileScanLifecycleBuilder();
    builder.rootDir(MOCK_ROOT_PATH);
    builder.fileSplits(Collections.singletonList(new DummyFileWork(MOCK_FILE_PATH)));
    builder.readerFactory(new FileReaderFactory() {

        @Override
        public ManagedReader newReader(FileSchemaNegotiator negotiator) {
            return new MockEarlySchemaReader(negotiator, 1);
        }
    });
    ScanLifecycle scan = buildScan(builder);
    assertSame(ProjectionType.ALL, scan.schemaTracker().projectionType());
    RowBatchReader reader = scan.nextReader();
    assertTrue(reader.open());
    assertTrue(reader.next());
    RowSetUtilities.verify(simpleExpected(0), fixture.wrap(reader.output()));
    assertFalse(reader.next());
    reader.close();
    scan.close();
}
Also used : RowBatchReader(org.apache.drill.exec.physical.impl.scan.RowBatchReader) DummyFileWork(org.apache.drill.exec.physical.impl.scan.v3.file.BaseFileScanTest.DummyFileWork) ManagedReader(org.apache.drill.exec.physical.impl.scan.v3.ManagedReader) ScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.ScanLifecycle) BaseTestScanLifecycle(org.apache.drill.exec.physical.impl.scan.v3.lifecycle.BaseTestScanLifecycle) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Aggregations

RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)51 Test (org.junit.Test)48 ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)43 EvfTest (org.apache.drill.categories.EvfTest)42 ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)37 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator)37 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)28 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)13 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)13 UserException (org.apache.drill.common.exceptions.UserException)12 DummyFileWork (org.apache.drill.exec.physical.impl.scan.v3.file.BaseFileScanTest.DummyFileWork)6 BaseTestScanLifecycle (org.apache.drill.exec.physical.impl.scan.v3.lifecycle.BaseTestScanLifecycle)6 ScanLifecycle (org.apache.drill.exec.physical.impl.scan.v3.lifecycle.ScanLifecycle)6 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 EarlyEofException (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader.EarlyEofException)1 VectorContainer (org.apache.drill.exec.record.VectorContainer)1 Path (org.apache.hadoop.fs.Path)1