Search in sources :

Example 11 with ScanOperatorExec

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

the class TestFileScan method testEmptyProject.

@Test
public void testEmptyProject() {
    ReaderCreator creator = negotiator -> {
        MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
        reader.batchLimit = 1;
        return reader;
    };
    // Select no columns
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.setProjection();
    builder.addReader(creator);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Expect data and implicit columns
    TupleMetadata expectedSchema = new SchemaBuilder().build();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow().addRow().build();
    // Schema should include implicit columns.
    assertTrue(scan.buildSchema());
    assertEquals(expected.container().getSchema(), scan.batchAccessor().schema());
    scan.batchAccessor().release();
    // Read one batch, should contain implicit columns
    assertTrue(scan.next());
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : RowSetUtilities(org.apache.drill.test.rowSet.RowSetUtilities) MetadataUtils(org.apache.drill.exec.record.metadata.MetadataUtils) Assert.assertTrue(org.junit.Assert.assertTrue) Types(org.apache.drill.common.types.Types) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) ScanFixture(org.apache.drill.exec.physical.impl.scan.v3.ScanFixture) Category(org.junit.experimental.categories.Category) MaterializedField(org.apache.drill.exec.record.MaterializedField) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) Assert.assertFalse(org.junit.Assert.assertFalse) EvfTest(org.apache.drill.categories.EvfTest) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) Assert.assertEquals(org.junit.Assert.assertEquals) BaseMockBatchReader(org.apache.drill.exec.physical.impl.scan.v3.BaseMockBatchReader) ScanFixture(org.apache.drill.exec.physical.impl.scan.v3.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 12 with ScanOperatorExec

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

the class TestScanOuputSchema method testProvidedSchema.

/**
 * Test an output schema.
 * <ul>
 * <li>Column a has an input type of VARCHAR, and output type of INT,
 * and the framework will insert an implicit conversion.</li>
 * <li>Column b has an output type of BIGINT, is projected, but is
 * not provided by the reader. It will use the default value of 20L.</li>
 * <li>Column c is not in the output schema, is not provided by the
 * reader, but is projected, so it will use the default null type
 * of VARCHAR, with a null value.</li>
 * </ul>
 */
@Test
public void testProvidedSchema() {
    TupleMetadata providedSchema = new SchemaBuilder().add("a", // Projected, in reader
    MinorType.INT).add("d", // Projected, not in reader
    MinorType.BIGINT).add("e", // Not projected, not in reader
    MinorType.BIGINT).buildSchema();
    providedSchema.metadata("d").setDefaultValue("20");
    providedSchema.metadata("e").setDefaultValue("30");
    BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder(fixture);
    builder.setProjection(new String[] { "a", "b", "d", "f" });
    builder.addReader(negotiator -> new MockSimpleReader(negotiator));
    builder.builder.providedSchema(providedSchema);
    builder.builder.nullType(Types.optional(MinorType.VARCHAR));
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).add("d", MinorType.BIGINT).addNullable("f", MinorType.VARCHAR).buildSchema();
    // Initial schema
    assertTrue(scan.buildSchema());
    {
        SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).build();
        RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    }
    // Batch with defaults and null types
    assertTrue(scan.next());
    {
        SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "foo", 20L, null).build();
        RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    }
    assertFalse(scan.next());
    scanFixture.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 13 with ScanOperatorExec

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

the class TestScanEarlySchema method testEOFOnFirstBatch.

@Test
public void testEOFOnFirstBatch() {
    ReaderCreator creator = negotiator -> {
        MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
        reader.batchLimit = 0;
        return reader;
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    // EOF. Returns a single empty batch with early schema
    // in order to provide an empty result set.
    assertTrue(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    RowSetUtilities.verify(RowSetBuilder.emptyBatch(fixture.allocator(), expectedSchema()), fixture.wrap(scan.batchAccessor().container()));
    assertFalse(scan.next());
    scanFixture.close();
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RowSetUtilities(org.apache.drill.test.rowSet.RowSetUtilities) Assert.assertFalse(org.junit.Assert.assertFalse) EvfTest(org.apache.drill.categories.EvfTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) Category(org.junit.experimental.categories.Category) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) Assert.assertEquals(org.junit.Assert.assertEquals) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Example 14 with ScanOperatorExec

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

the class TestScanLimit method testLimit0.

/**
 * LIMIT 0, to obtain only the schema.
 */
@Test
public void testLimit0() {
    TestFixture fixture = new TestFixture(0);
    ScanOperatorExec scan = fixture.scan;
    assertTrue(scan.buildSchema());
    BatchAccessor batch = scan.batchAccessor();
    assertEquals(0, batch.rowCount());
    assertEquals(1, batch.schema().getFieldCount());
    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 15 with ScanOperatorExec

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

the class TestScanLimit method testLimitOnEOF.

/**
 * LIMIT 100, at EOF of the first reader.
 */
@Test
public void testLimitOnEOF() {
    TestFixture fixture = new TestFixture(100);
    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(50, batch.rowCount());
    batch.release();
    // No second reader
    assertFalse(scan.next());
    fixture.close();
    scan.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)

Aggregations

ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)49 Test (org.junit.Test)47 EvfTest (org.apache.drill.categories.EvfTest)35 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)22 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)19 RowSetUtilities (org.apache.drill.test.rowSet.RowSetUtilities)16 Assert.assertEquals (org.junit.Assert.assertEquals)16 Assert.assertFalse (org.junit.Assert.assertFalse)16 Assert.assertTrue (org.junit.Assert.assertTrue)16 Category (org.junit.experimental.categories.Category)16 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)13 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)12 DataMode (org.apache.drill.common.types.TypeProtos.DataMode)11 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)11 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)11 MaterializedField (org.apache.drill.exec.record.MaterializedField)11 UserException (org.apache.drill.common.exceptions.UserException)9 BatchAccessor (org.apache.drill.exec.physical.impl.protocol.BatchAccessor)7 ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)6 ColumnBuilder (org.apache.drill.exec.record.metadata.ColumnBuilder)6