Search in sources :

Example 31 with ScanOperatorExec

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

the class TestScanEarlySchema method testEarlySchemaLifecycleNoSchemaBatch.

@Test
public void testEarlySchemaLifecycleNoSchemaBatch() {
    // Create a mock reader, return one batch with data.
    ReaderCreator creator = negotiator -> {
        MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
        reader.batchLimit = 1;
        return reader;
    };
    // Create the scan operator
    BaseScanFixtureBuilder builder = simpleBuilder(creator);
    builder.enableSchemaBatch = false;
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    SingleRowSet expected = makeExpected();
    RowSetComparison verifier = new RowSetComparison(expected);
    // First batch: 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 32 with ScanOperatorExec

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

the class TestScanEarlySchema method testEarlySchemaLifecycle.

@Test
public void testEarlySchemaLifecycle() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    ObservableCreator creator = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            MockEarlySchemaReader reader = new MockEarlySchemaReader(negotiator);
            reader.batchLimit = 1;
            return reader;
        }
    };
    ScanFixture scanFixture = simpleFixture(creator);
    ScanOperatorExec scan = scanFixture.scanOp;
    SingleRowSet expected = makeExpected();
    RowSetComparison verifier = new RowSetComparison(expected);
    // First batch: return schema.
    assertTrue(scan.buildSchema());
    MockEarlySchemaReader reader = creator.reader();
    assertEquals(0, reader.batchCount);
    assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
    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 : 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 33 with ScanOperatorExec

use of org.apache.drill.exec.physical.impl.scan.ScanOperatorExec 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 34 with ScanOperatorExec

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

the class TestScanOverflow method runOverflowTest.

private void runOverflowTest(boolean eofWithData) {
    ObservableCreator creator1 = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            OverflowReader reader = new OverflowReader(negotiator);
            reader.batchLimit = 2;
            reader.reportEofWithOverflow = eofWithData;
            return reader;
        }
    };
    ObservableCreator creator2 = new ObservableCreator() {

        @Override
        public ManagedReader create(SchemaNegotiator negotiator) {
            OverflowReader reader = new OverflowReader(negotiator);
            reader.batchLimit = 2;
            return reader;
        }
    };
    BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder(fixture);
    builder.projectAll();
    builder.addReader(creator1);
    builder.addReader(creator2);
    // Want overflow, set size and row counts at their limits.
    builder.builder.batchByteLimit(ScanLifecycleBuilder.MAX_BATCH_BYTE_SIZE);
    builder.builder.batchRecordLimit(ScanLifecycleBuilder.MAX_BATCH_ROW_COUNT);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    assertTrue(scan.buildSchema());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // Second batch. Should be 1 less than the reader's row
    // count because the loader has its own one-row lookahead batch.
    assertTrue(scan.next());
    OverflowReader reader1 = creator1.reader();
    assertEquals(1, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    int prevRowCount = scan.batchAccessor().rowCount();
    assertEquals(reader1.rowCount - 1, prevRowCount);
    scan.batchAccessor().release();
    // Third batch, adds more data to the lookahead batch. Also overflows
    // so returned records is one less than total produced so far minus
    // those returned earlier.
    assertTrue(scan.next());
    assertEquals(2, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    assertEquals(reader1.rowCount - prevRowCount - 1, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    int prevReaderRowCount = reader1.rowCount;
    // Third batch. Returns the overflow row from the second batch of
    // the first reader.
    assertTrue(scan.next());
    assertEquals(eofWithData ? 2 : 3, reader1.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    assertEquals(1, scan.batchAccessor().rowCount());
    assertEquals(prevReaderRowCount, reader1.rowCount);
    scan.batchAccessor().release();
    // Second reader.
    assertTrue(scan.next());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // Second batch from second reader.
    assertTrue(scan.next());
    OverflowReader reader2 = creator2.reader();
    assertEquals(2, reader2.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // Third batch. Returns the overflow row from the second batch of
    // the second reader.
    assertTrue(scan.next());
    assertEquals(3, reader2.batchCount);
    assertEquals(1, scan.batchAccessor().schemaVersion());
    assertEquals(1, scan.batchAccessor().rowCount());
    assertEquals(prevReaderRowCount, reader2.rowCount);
    scan.batchAccessor().release();
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)

Example 35 with ScanOperatorExec

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

the class TestFileScan method testLateSchemaFileWildcards.

@Test
public void testLateSchemaFileWildcards() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    ReaderCreator creator = negotiator -> {
        MockLateSchemaReader reader = new MockLateSchemaReader(negotiator);
        reader.batchLimit = 1;
        reader.returnDataOnFirst = true;
        return reader;
    };
    // Create the scan operator
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.projectAllWithImplicit(3);
    builder.addReader(creator);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Create the expected result.
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).add(FileScanUtils.FULLY_QUALIFIED_NAME_COL, MinorType.VARCHAR).add(FileScanUtils.FILE_PATH_COL, MinorType.VARCHAR).add(FileScanUtils.FILE_NAME_COL, MinorType.VARCHAR).add(FileScanUtils.SUFFIX_COL, MinorType.VARCHAR).addNullable(FileScanUtils.partitionColName(0), MinorType.VARCHAR).addNullable(FileScanUtils.partitionColName(1), MinorType.VARCHAR).addNullable(FileScanUtils.partitionColName(2), MinorType.VARCHAR).buildSchema();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "fred", MOCK_FILE_FQN, MOCK_FILE_DIR_PATH, MOCK_FILE_NAME, MOCK_SUFFIX, MOCK_DIR0, MOCK_DIR1, null).addRow(20, "wilma", MOCK_FILE_FQN, MOCK_FILE_DIR_PATH, MOCK_FILE_NAME, MOCK_SUFFIX, MOCK_DIR0, MOCK_DIR1, null).build();
    assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
    // Next call, return with data.
    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)

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