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();
}
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);
}
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);
}
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);
}
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();
}
Aggregations