Search in sources :

Example 31 with ScanFixture

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

the class TestColumnsArrayFramework method testColumnsProjection.

/**
 * Test projecting just the `columns` column.
 */
@Test
public void testColumnsProjection() {
    // Create a mock reader, return two batches: one schema-only, another with data.
    DummyColumnsReader reader = new DummyColumnsReader(new SchemaBuilder().addArray(ColumnsScanFramework.COLUMNS_COL, MinorType.VARCHAR).buildSchema());
    // Create the scan operator
    ColumnsScanFixtureBuilder builder = new ColumnsScanFixtureBuilder();
    builder.setProjection(RowSetTestUtils.projectList(ColumnsScanFramework.COLUMNS_COL));
    builder.addReader(reader);
    builder.builder.requireColumnsArray(true);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Start the one and only reader, and check the columns
    // schema info.
    assertTrue(scan.buildSchema());
    assertNotNull(reader.negotiator);
    assertTrue(reader.negotiator.columnsArrayProjected());
    assertNull(reader.negotiator.projectedIndexes());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 32 with ScanFixture

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

the class TestFileScanFramework method testEmptyProject.

@Test
public void testEmptyProject() {
    MockEarlySchemaReader reader = new MockEarlySchemaReader();
    reader.batchLimit = 1;
    // Select no columns
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.setProjection();
    builder.addReader(reader);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Expect data and implicit columns
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(new SchemaBuilder()).build();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow().addRow().build();
    // Schema should include implicit columns.
    assertTrue(scan.buildSchema());
    assertEquals(expectedSchema, 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 : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 33 with ScanFixture

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

the class TestFileScanFramework method testMapProject.

@Test
public void testMapProject() {
    MockMapReader reader = new MockMapReader();
    reader.batchLimit = 1;
    // Select one of the two map columns
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.setProjection("m1.a");
    builder.addReader(reader);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Expect data and implicit columns
    SchemaBuilder schemaBuilder = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).resumeSchema();
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addSingleCol(new Object[] { 10 }).addSingleCol(new Object[] { 20 }).build();
    assertTrue(scan.buildSchema());
    assertEquals(expectedSchema, scan.batchAccessor().schema());
    scan.batchAccessor().release();
    assertTrue(scan.next());
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // EOF
    assertFalse(scan.next());
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 34 with ScanFixture

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

the class TestFileScanFramework method testFullProject.

/**
 * Exercise the major project operations: subset of table
 * columns, implicit, partition, missing columns, and output
 * order (and positions) different than table. These cases
 * are more fully test on lower level components; here we verify
 * that the components are wired up correctly.
 */
@Test
public void testFullProject() {
    MockEarlySchemaReader reader = new MockEarlySchemaReader();
    reader.batchLimit = 1;
    // Select table and implicit columns.
    FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
    builder.setProjection("dir0", "b", "filename", "c", "suffix");
    builder.addReader(reader);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Expect data and implicit columns
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("dir0", MinorType.VARCHAR).addNullable("b", MinorType.VARCHAR, 10).add("filename", MinorType.VARCHAR).addNullable("c", MinorType.INT).add("suffix", MinorType.VARCHAR);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(MOCK_DIR0, "fred", MOCK_FILE_NAME, null, MOCK_SUFFIX).addRow(MOCK_DIR0, "wilma", MOCK_FILE_NAME, null, MOCK_SUFFIX).build();
    // Schema should include implicit columns.
    assertTrue(scan.buildSchema());
    assertEquals(expectedSchema, 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 : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 35 with ScanFixture

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

the class TestScanOperExecSmoothing method testSchemaSmoothing.

/**
 * Test the ability of the scan operator to "smooth" out schema changes
 * by reusing the type from a previous reader, if known. That is,
 * given three readers:<br>
 * (a, b)<br>
 * (b)<br>
 * (a, b)<br>
 * Then the type of column a should be preserved for the second reader that
 * does not include a. This works if a is nullable. If so, a's type will
 * be used for the empty column, rather than the usual nullable int.
 * <p>
 * Full testing of smoothing is done in
 * {#link TestScanProjector}. Here we just make sure that the
 * smoothing logic is available via the scan operator.
 */
@Test
public void testSchemaSmoothing() {
    // Reader returns (a, b)
    MockEarlySchemaReader reader1 = new MockEarlySchemaReader();
    reader1.batchLimit = 1;
    // Reader returns (a)
    MockOneColEarlySchemaReader reader2 = new MockOneColEarlySchemaReader();
    reader2.batchLimit = 1;
    reader2.startIndex = 100;
    // Reader returns (a, b)
    MockEarlySchemaReader reader3 = new MockEarlySchemaReader();
    reader3.batchLimit = 1;
    reader3.startIndex = 200;
    BaseScanFixtureBuilder builder = new BaseScanFixtureBuilder();
    builder.setProjection(new String[] { "a", "b" });
    builder.addReader(reader1);
    builder.addReader(reader2);
    builder.addReader(reader3);
    ScanFixture scanFixture = builder.build();
    ScanOperatorExec scan = scanFixture.scanOp;
    // Schema based on (a, b)
    assertTrue(scan.buildSchema());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    scan.batchAccessor().release();
    // Batch from (a, b) reader 1
    assertTrue(scan.next());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(0, scan.batchAccessor().container());
    // Batch from (a) reader 2
    // Due to schema smoothing, b vector type is left unchanged,
    // but is null filled.
    assertTrue(scan.next());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    SingleRowSet expected = fixture.rowSetBuilder(scan.batchAccessor().schema()).addRow(111, null).addRow(121, null).build();
    RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
    // Batch from (a, b) reader 3
    // Recycles b again, back to being a table column.
    assertTrue(scan.next());
    assertEquals(1, scan.batchAccessor().schemaVersion());
    verifyBatch(200, scan.batchAccessor().container());
    assertFalse(scan.next());
    scanFixture.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) Test(org.junit.Test)

Aggregations

ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)52 Test (org.junit.Test)51 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)17 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)15 SubOperatorTest (org.apache.drill.test.SubOperatorTest)13 UserException (org.apache.drill.common.exceptions.UserException)9 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)8 BatchAccessor (org.apache.drill.exec.physical.impl.protocol.BatchAccessor)7 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator)7 BatchSchema (org.apache.drill.exec.record.BatchSchema)7 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)6 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)5 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)5 ManagedReader (org.apache.drill.exec.physical.impl.scan.framework.ManagedReader)5 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)5 HashMap (java.util.HashMap)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 VectorContainer (org.apache.drill.exec.record.VectorContainer)1