Search in sources :

Example 16 with SingleRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.

the class TestScanOrchestratorLateSchema method testLateSchemaWildcard.

/**
 * Test SELECT * from an early-schema table of (a, b)
 */
@Test
public void testLateSchemaWildcard() {
    ScanOrchestratorBuilder builder = new MockScanBuilder();
    // SELECT * ...
    builder.projection(RowSetTestUtils.projectAll());
    ScanSchemaOrchestrator orchestrator = new ScanSchemaOrchestrator(fixture.allocator(), builder);
    // ... FROM table
    ReaderSchemaOrchestrator reader = orchestrator.startReader();
    // Create the table loader
    ResultSetLoader loader = reader.makeTableLoader(null);
    // Late schema: no batch provided up front.
    assertFalse(reader.hasSchema());
    // Start a batch and discover a schema: (a, b)
    reader.startBatch();
    RowSetLoader writer = loader.writer();
    writer.addColumn(SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED));
    writer.addColumn(SchemaBuilder.columnSchema("b", MinorType.VARCHAR, DataMode.REQUIRED));
    // Create a batch of data using the discovered schema
    writer.addRow(1, "fred").addRow(2, "wilma");
    reader.endBatch();
    // Verify
    TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
    SingleRowSet expected = fixture.rowSetBuilder(tableSchema).addRow(1, "fred").addRow(2, "wilma").build();
    new RowSetComparison(expected).verifyAndClearAll(fixture.wrap(orchestrator.output()));
    orchestrator.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) ScanOrchestratorBuilder(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator.ScanOrchestratorBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MockScanBuilder(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.MockScanBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) ScanSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator) ReaderSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ReaderSchemaOrchestrator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 17 with SingleRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.

the class TestDirectConverter method testStringToDateTimeDefault.

/**
 * Test VARCHAR to DATE, TIME and TIMESTAMP conversion
 * using default ISO formats.
 */
@Test
public void testStringToDateTimeDefault() {
    TupleMetadata outputSchema = new SchemaBuilder().add("date", MinorType.DATE).add("time", MinorType.TIME).add("ts", MinorType.TIMESTAMP).buildSchema();
    TupleMetadata inputSchema = new SchemaBuilder().add("date", MinorType.VARCHAR).add("time", MinorType.VARCHAR).add("ts", MinorType.VARCHAR).buildSchema();
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.createConvertersFor(inputSchema);
    RowSet actual = testFixture.addRow("2019-03-28", "12:34:56", "2019-03-28T12:34:56").build();
    LocalTime lt = LocalTime.of(12, 34, 56);
    LocalDate ld = LocalDate.of(2019, 3, 28);
    Instant ts = LocalDateTime.of(ld, lt).toInstant(ZoneOffset.UTC);
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(ld, lt, ts).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) LocalTime(java.time.LocalTime) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) Instant(java.time.Instant) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) LocalDate(java.time.LocalDate) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 18 with SingleRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.

the class TestDirectConverter method testImplicitConversionIntTruncation.

/**
 * The column accessors provide only int setters. For performance, the int value is
 * assumed to be of the correct range for the target column. If not, truncation of
 * the highest bytes occurs.
 * <p>
 * The assumption is, if the reader or other code expects that overflow might
 * occur, that code should be implemented in the client (or in a type conversion
 * shim), leaving the normal code path to optimize for the 99% of the cases where
 * the value is in the proper range.
 */
@Test
public void testImplicitConversionIntTruncation() {
    TupleMetadata schema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).buildSchema();
    // Test allowed implicit conversions.
    RowSet actual = new RowSetBuilder(fixture.allocator(), schema).addRow(Byte.MAX_VALUE + 1, Short.MAX_VALUE + 1).addRow(Byte.MAX_VALUE + 2, Short.MAX_VALUE + 2).build();
    // Build the expected vector without a type converter.
    final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(Byte.MIN_VALUE, Short.MIN_VALUE).addRow(Byte.MIN_VALUE + 1, Short.MIN_VALUE + 1).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 19 with SingleRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.

the class TestOperatorRecordBatch method testBatchAccessor.

/**
 * The record batch abstraction has a bunch of methods to work with a vector container.
 * Rather than simply exposing the container itself, the batch instead exposes various
 * container operations. Probably an artifact of its history. In any event, make
 * sure those methods are passed through to the container accessor.
 */
@Test
public void testBatchAccessor() {
    SchemaBuilder schemaBuilder = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR);
    BatchSchema schema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10, "fred").addRow(20, "wilma").build();
    MockOperatorExec opExec = new MockOperatorExec(rs.container());
    opExec.nextCalls = 1;
    try (OperatorRecordBatch opBatch = makeOpBatch(opExec)) {
        assertEquals(IterOutcome.OK_NEW_SCHEMA, opBatch.next());
        assertEquals(schema, opBatch.getSchema());
        assertEquals(2, opBatch.getRecordCount());
        assertSame(rs.container(), opBatch.getOutgoingContainer());
        Iterator<VectorWrapper<?>> iter = opBatch.iterator();
        assertEquals("a", iter.next().getValueVector().getField().getName());
        assertEquals("b", iter.next().getValueVector().getField().getName());
        // Not a full test of the schema path; just make sure that the
        // pass-through to the Vector Container works.
        SchemaPath path = SchemaPath.create(NamePart.newBuilder().setName("a").build());
        TypedFieldId id = opBatch.getValueVectorId(path);
        assertEquals(MinorType.INT, id.getFinalType().getMinorType());
        assertEquals(1, id.getFieldIds().length);
        assertEquals(0, id.getFieldIds()[0]);
        path = SchemaPath.create(NamePart.newBuilder().setName("b").build());
        id = opBatch.getValueVectorId(path);
        assertEquals(MinorType.VARCHAR, id.getFinalType().getMinorType());
        assertEquals(1, id.getFieldIds().length);
        assertEquals(1, id.getFieldIds()[0]);
        // Sanity check of getValueAccessorById()
        VectorWrapper<?> w = opBatch.getValueAccessorById(IntVector.class, 0);
        assertNotNull(w);
        assertEquals("a", w.getValueVector().getField().getName());
        w = opBatch.getValueAccessorById(VarCharVector.class, 1);
        assertNotNull(w);
        assertEquals("b", w.getValueVector().getField().getName());
        try {
            opBatch.getSelectionVector2();
            fail();
        } catch (UnsupportedOperationException e) {
        // Expected
        }
        try {
            opBatch.getSelectionVector4();
            fail();
        } catch (UnsupportedOperationException e) {
        // Expected
        }
    } catch (Exception e) {
        fail(e.getMessage());
    }
    assertTrue(opExec.closeCalled);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UserException(org.apache.drill.common.exceptions.UserException) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaPath(org.apache.drill.common.expression.SchemaPath) TypedFieldId(org.apache.drill.exec.record.TypedFieldId) 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 20 with SingleRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.

the class TestOperatorRecordBatch method testSchemaChange.

@Test
public void testSchemaChange() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10, "fred").addRow(20, "wilma").build();
    VectorContainer container = rs.container();
    MockOperatorExec opExec = new MockOperatorExec(container);
    int schemaVersion = opExec.batchAccessor().schemaVersion();
    // Be tidy: start at 1.
    assertEquals(1, schemaVersion);
    // Changing data does not trigger schema change
    container.zeroVectors();
    opExec.batchAccessor.addBatch(container);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Different container, same vectors, does not trigger a change
    VectorContainer c2 = new VectorContainer(fixture.allocator());
    for (VectorWrapper<?> vw : container) {
        c2.add(vw.getValueVector());
    }
    c2.buildSchema(SelectionVectorMode.NONE);
    opExec.batchAccessor.addBatch(c2);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    opExec.batchAccessor.addBatch(container);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Replacing a vector with another of the same type does trigger
    // a change.
    VectorContainer c3 = new VectorContainer(fixture.allocator());
    c3.add(container.getValueVector(0).getValueVector());
    c3.add(TypeHelper.getNewVector(container.getValueVector(1).getValueVector().getField(), fixture.allocator(), null));
    c3.buildSchema(SelectionVectorMode.NONE);
    opExec.batchAccessor.addBatch(c3);
    assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
    schemaVersion = opExec.batchAccessor().schemaVersion();
    // No change if same schema again
    opExec.batchAccessor.addBatch(c3);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Adding a vector triggers a change
    MaterializedField c = SchemaBuilder.columnSchema("c", MinorType.INT, DataMode.OPTIONAL);
    c3.add(TypeHelper.getNewVector(c, fixture.allocator(), null));
    c3.buildSchema(SelectionVectorMode.NONE);
    opExec.batchAccessor.addBatch(c3);
    assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
    schemaVersion = opExec.batchAccessor().schemaVersion();
    // No change if same schema again
    opExec.batchAccessor.addBatch(c3);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Removing a vector triggers a change
    c3.remove(c3.getValueVector(2).getValueVector());
    c3.buildSchema(SelectionVectorMode.NONE);
    assertEquals(2, c3.getNumberOfColumns());
    opExec.batchAccessor.addBatch(c3);
    assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
    schemaVersion = opExec.batchAccessor().schemaVersion();
    // Clean up
    opExec.close();
    c2.clear();
    c3.clear();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) MaterializedField(org.apache.drill.exec.record.MaterializedField) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)257 Test (org.junit.Test)241 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)237 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)234 SubOperatorTest (org.apache.drill.test.SubOperatorTest)207 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)69 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)62 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)61 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)54 ValueVector (org.apache.drill.exec.vector.ValueVector)32 EvfTest (org.apache.drill.categories.EvfTest)30 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)29 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)27 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)27 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)27 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)25 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)24 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)23 VectorContainer (org.apache.drill.exec.record.VectorContainer)22 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)22