Search in sources :

Example 26 with ScanOperatorExec

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

the class TestScanOuputSchema method testStrictProvidedSchemaWithWildcard.

@Test
public void testStrictProvidedSchemaWithWildcard() {
    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");
    providedSchema.setProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, Boolean.TRUE.toString());
    BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder(fixture);
    // Project schema only
    builder.setProjection(RowSetTestUtils.projectAll());
    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("d", MinorType.BIGINT).add("e", MinorType.BIGINT).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, 20L, 30L).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 27 with ScanOperatorExec

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

the class TestFixedReceiver method testFixedReceiver.

/**
 * Test the standard string-to-type conversion using an ad-hoc conversion
 * from the input type (the type used by the row set builder) to the output
 * (vector) type.
 */
@Test
public void testFixedReceiver() {
    // Create the provided and output schemas
    TupleMetadata outputSchema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("fl", MinorType.FLOAT4).add("db", MinorType.FLOAT8).buildSchema();
    // Create the scan
    BaseScanFixtureBuilder builder = simpleBuilder(negotiator -> new MockReader(negotiator));
    builder.builder.providedSchema(outputSchema);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Load test data using converters
    assertTrue(scan.next());
    // Build the expected vector without a type converter.
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(11, 12, 13, 14L, 15.5F, 16.25D).addRow(127, 32757, Integer.MAX_VALUE, Long.MAX_VALUE, 10E6F, 10E200D).build();
    // Compare
    VectorContainer container = scan.batchAccessor().container();
    RowSetUtilities.verify(expected, fixture.wrap(container));
    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) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test)

Example 28 with ScanOperatorExec

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

the class TestScanEarlySchema method testEarlySchemaDataWithEof.

@Test
public void testEarlySchemaDataWithEof() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    ReaderCreator creator = negotiator -> {
        MockEarlySchemaReader reader = new MockEarlySchemaReader3(negotiator);
        reader.batchLimit = 1;
        return reader;
    };
    // Create the scan operator
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    SingleRowSet expected = makeExpected();
    RowSetComparison verifier = new RowSetComparison(expected);
    // First batch: return schema.
    assertTrue(scan.buildSchema());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next call, return with data.
    assertTrue(scan.next());
    verifier.verifyAndClearAll(fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next again: no-op
    assertFalse(scan.next());
    scanFixture.close();
    // Close again: no-op
    scan.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) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) EvfTest(org.apache.drill.categories.EvfTest) Test(org.junit.Test)

Example 29 with ScanOperatorExec

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

the class TestScanEarlySchema method testEOFOnSchema.

/**
 * Test EOF on the first batch. Is allowed, but will result in the scan operator
 * passing a null batch to the parent.
 */
@Test
public void testEOFOnSchema() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    ReaderCreator creator = negotiator -> new EofOnOpenReader(negotiator);
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    // EOF
    assertFalse(scan.buildSchema());
    assertEquals(0, scan.batchAccessor().rowCount());
    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 30 with ScanOperatorExec

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

the class TestScanEarlySchema method testMultipleReaders.

/**
 * Test normal case with multiple readers. These return
 * the same schema, so no schema change.
 */
@Test
public void testMultipleReaders() {
    ReaderCreator creator1 = negotiator -> new EofOnOpenReader(negotiator);
    ReaderCreator creator2 = negotiator -> {
        MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
        reader.batchLimit = 2;
        return reader;
    };
    ReaderCreator creator3 = negotiator -> {
        MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
        reader.batchLimit = 2;
        reader.startIndex = 100;
        return reader;
    };
    ScanFixture scanFixture = simpleFixture(creator1, creator2, creator3);
    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, scan.batchAccessor().schemaVersion());
    verifyBatch(0, scan.batchAccessor().container());
    // Third batch.
    assertTrue(scan.next());
    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.
    assertTrue(scan.next());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(100, scan.batchAccessor().container());
    // Second batch from second reader.
    assertTrue(scan.next());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(120, scan.batchAccessor().container());
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    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)

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