Search in sources :

Example 1 with SchemaNegotiator

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

the class TestScanOperExecBasics method testExceptionOnOpen.

@Test
public void testExceptionOnOpen() {
    // Reader which fails on open with a known error message
    // using an exception other than UserException.
    MockEarlySchemaReader reader = new MockEarlySchemaReader() {

        @Override
        public boolean open(SchemaNegotiator schemaNegotiator) {
            openCalled = true;
            throw new IllegalStateException(ERROR_MSG);
        }
    };
    reader.batchLimit = 0;
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    try {
        scan.buildSchema();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertTrue(e.getCause() instanceof IllegalStateException);
    }
    assertTrue(reader.openCalled);
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
    assertTrue(reader.closeCalled);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test)

Example 2 with SchemaNegotiator

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

the class TestScanOperExecBasics method testUserExceptionOnOpen.

@Test
public void testUserExceptionOnOpen() {
    // Reader which fails on open with a known error message
    // using a UserException.
    MockEarlySchemaReader reader = new MockEarlySchemaReader() {

        @Override
        public boolean open(SchemaNegotiator schemaNegotiator) {
            openCalled = true;
            throw UserException.dataReadError().addContext(ERROR_MSG).build(logger);
        }
    };
    reader.batchLimit = 2;
    ScanFixture scanFixture = simpleFixture(reader);
    ScanOperatorExec scan = scanFixture.scanOp;
    try {
        scan.buildSchema();
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains(ERROR_MSG));
        assertNull(e.getCause());
    }
    assertTrue(reader.openCalled);
    assertEquals(0, scan.batchAccessor().rowCount());
    scanFixture.close();
    assertTrue(reader.closeCalled);
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test)

Example 3 with SchemaNegotiator

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

the class TestMockRowReader method testOverflow.

/**
 * Test a mock varchar column large enough to cause vector overflow.
 */
@Test
public void testOverflow() {
    int rowCount = ValueVector.MAX_ROW_COUNT;
    MockTableDef.MockColumn[] cols = new MockTableDef.MockColumn[] { new MockTableDef.MockColumn("a", MinorType.INT, DataMode.REQUIRED, null, null, null, null, null, null), new MockTableDef.MockColumn("b", MinorType.VARCHAR, DataMode.REQUIRED, 1000, null, null, null, null, null) };
    MockTableDef.MockScanEntry entry = new MockTableDef.MockScanEntry(rowCount, true, null, null, cols);
    MockSubScanPOP config = new MockSubScanPOP("dummy", true, Collections.singletonList(entry));
    ManagedReader<SchemaNegotiator> reader = new ExtendedMockBatchReader(entry);
    @SuppressWarnings("unchecked") List<ManagedReader<SchemaNegotiator>> readers = Collections.singletonList(reader);
    // Create options and the scan operator
    ScanFixture mockBatch = buildScan(config, readers);
    ScanOperatorExec scan = mockBatch.scanOp;
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next call, return with data, limited by batch size.
    int totalRowCount = 0;
    int batchCount = 0;
    while (scan.next()) {
        assertTrue(scan.batchAccessor().rowCount() < ValueVector.MAX_ROW_COUNT);
        BatchAccessor batchAccessor = scan.batchAccessor();
        totalRowCount += batchAccessor.rowCount();
        batchCount++;
        batchAccessor.release();
    }
    assertEquals(ValueVector.MAX_ROW_COUNT, totalRowCount);
    assertTrue(batchCount > 1);
    mockBatch.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) ManagedReader(org.apache.drill.exec.physical.impl.scan.framework.ManagedReader) ScanOperatorExec(org.apache.drill.exec.physical.impl.scan.ScanOperatorExec) BatchAccessor(org.apache.drill.exec.physical.impl.protocol.BatchAccessor) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 4 with SchemaNegotiator

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

the class TestMockRowReader method testOptional.

/**
 * Verify that the mock reader can generate nullable (optional) columns,
 * including filling values with nulls at some percentage, 25% by
 * default.
 */
@Test
public void testOptional() {
    int rowCount = 10;
    Map<String, Object> props = new HashMap<>();
    props.put("nulls", 50);
    MockTableDef.MockColumn[] cols = new MockTableDef.MockColumn[] { new MockTableDef.MockColumn("a", MinorType.INT, DataMode.OPTIONAL, null, null, null, null, null, null), new MockTableDef.MockColumn("b", MinorType.VARCHAR, DataMode.OPTIONAL, 10, null, null, null, null, props) };
    MockTableDef.MockScanEntry entry = new MockTableDef.MockScanEntry(rowCount, true, null, null, cols);
    MockSubScanPOP config = new MockSubScanPOP("dummy", true, Collections.singletonList(entry));
    ManagedReader<SchemaNegotiator> reader = new ExtendedMockBatchReader(entry);
    List<ManagedReader<SchemaNegotiator>> readers = Collections.singletonList(reader);
    // Create options and the scan operator
    ScanFixture mockBatch = buildScan(config, readers);
    ScanOperatorExec scan = mockBatch.scanOp;
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("a", MinorType.INT).addNullable("b", MinorType.VARCHAR, 10).build();
    BatchSchema expectedBatchSchema = new BatchSchema(SelectionVectorMode.NONE, expectedSchema.toFieldList());
    assertTrue(expectedBatchSchema.isEquivalent(scan.batchAccessor().schema()));
    assertEquals(0, scan.batchAccessor().rowCount());
    // Next call, return with data.
    assertTrue(scan.next());
    assertTrue(expectedBatchSchema.isEquivalent(scan.batchAccessor().schema()));
    assertEquals(rowCount, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    // EOF
    assertFalse(scan.next());
    mockBatch.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) HashMap(java.util.HashMap) ManagedReader(org.apache.drill.exec.physical.impl.scan.framework.ManagedReader) BatchSchema(org.apache.drill.exec.record.BatchSchema) 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) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 5 with SchemaNegotiator

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

the class TestMockRowReader method testBasics.

/**
 * Test the most basic case: required integers and strings.
 */
@Test
public void testBasics() {
    int rowCount = 10;
    MockTableDef.MockColumn[] cols = new MockTableDef.MockColumn[] { new MockTableDef.MockColumn("a", MinorType.INT, DataMode.REQUIRED, null, null, null, null, null, null), new MockTableDef.MockColumn("b", MinorType.VARCHAR, DataMode.REQUIRED, 10, null, null, null, null, null) };
    MockTableDef.MockScanEntry entry = new MockTableDef.MockScanEntry(rowCount, true, null, null, cols);
    MockSubScanPOP config = new MockSubScanPOP("dummy", true, Collections.singletonList(entry));
    ManagedReader<SchemaNegotiator> reader = new ExtendedMockBatchReader(entry);
    List<ManagedReader<SchemaNegotiator>> readers = Collections.singletonList(reader);
    // Create options and the scan operator
    ScanFixture mockBatch = buildScan(config, readers);
    ScanOperatorExec scan = mockBatch.scanOp;
    // First batch: build schema. The reader helps: it returns an
    // empty first batch.
    assertTrue(scan.buildSchema());
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR, // Width is reflected in meta-data
    10).buildSchema();
    BatchSchema expectedBatchSchema = new BatchSchema(SelectionVectorMode.NONE, expectedSchema.toFieldList());
    assertTrue(expectedBatchSchema.isEquivalent(scan.batchAccessor().schema()));
    assertEquals(0, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    // Next call, return with data.
    assertTrue(scan.next());
    assertTrue(expectedBatchSchema.isEquivalent(scan.batchAccessor().schema()));
    assertEquals(rowCount, scan.batchAccessor().rowCount());
    scan.batchAccessor().release();
    // EOF
    assertFalse(scan.next());
    mockBatch.close();
}
Also used : ScanFixture(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture) ManagedReader(org.apache.drill.exec.physical.impl.scan.framework.ManagedReader) BatchSchema(org.apache.drill.exec.record.BatchSchema) 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) SchemaNegotiator(org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Aggregations

SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.framework.SchemaNegotiator)8 ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)7 Test (org.junit.Test)7 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 SubOperatorTest (org.apache.drill.test.SubOperatorTest)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)4 UserException (org.apache.drill.common.exceptions.UserException)3 BatchSchema (org.apache.drill.exec.record.BatchSchema)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 KafkaAvroDeserializer (io.confluent.kafka.serializers.KafkaAvroDeserializer)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Schema (org.apache.avro.Schema)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 TypeProtos (org.apache.drill.common.types.TypeProtos)1