use of org.apache.drill.exec.record.metadata.TupleMetadata in project drill by apache.
the class TestScanOrchestratorEarlySchema method testEarlySchemaSelectExtraCustomType.
/**
* Test SELECT a, b, c FROM table(a, b)
* c will be null of type VARCHAR
*/
@Test
public void testEarlySchemaSelectExtraCustomType() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
// Null columns of type VARCHAR
MajorType nullType = MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.OPTIONAL).build();
builder.nullType(nullType);
// SELECT a, b, c ...
builder.projection(RowSetTestUtils.projectList("a", "b", "c"));
ScanSchemaOrchestrator scanner = new ScanSchemaOrchestrator(fixture.allocator(), builder);
// ... FROM table ...
ReaderSchemaOrchestrator reader = scanner.startReader();
// file schema (a, b)
TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
// Create the table loader
ResultSetLoader loader = reader.makeTableLoader(tableSchema);
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).addNullable("c", MinorType.VARCHAR).buildSchema();
// Create a batch of data.
reader.startBatch();
loader.writer().addRow(1, "fred").addRow(2, "wilma");
reader.endBatch();
// Verify
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(1, "fred", null).addRow(2, "wilma", null).build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
scanner.close();
}
use of org.apache.drill.exec.record.metadata.TupleMetadata in project drill by apache.
the class TestScanOrchestratorEarlySchema method testEarlySchemaSelectSubset.
/**
* Test SELECT a FROM table(a, b)
*/
@Test
public void testEarlySchemaSelectSubset() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
// SELECT a ...
builder.projection(RowSetTestUtils.projectList("a"));
ScanSchemaOrchestrator scanner = new ScanSchemaOrchestrator(fixture.allocator(), builder);
// ... FROM table
ReaderSchemaOrchestrator reader = scanner.startReader();
// file schema (a, b)
TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
// Create the table loader
ResultSetLoader loader = reader.makeTableLoader(tableSchema);
// Verify that unprojected column is unprojected in the
// table loader.
assertFalse(loader.writer().column("b").isProjected());
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
// Create a batch of data.
reader.startBatch();
loader.writer().addRow(1, "fred").addRow(2, "wilma");
reader.endBatch();
// Verify
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(1).addRow(2).build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
scanner.close();
}
use of org.apache.drill.exec.record.metadata.TupleMetadata in project drill by apache.
the class TestScanOrchestratorLateSchema method testLateSchemaSelectDisjoint.
/**
* Test SELECT a, c FROM table(a, b)
*/
@Test
public void testLateSchemaSelectDisjoint() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
// SELECT a, c ...
builder.projection(RowSetTestUtils.projectList("a", "c"));
ScanSchemaOrchestrator orchestrator = new ScanSchemaOrchestrator(fixture.allocator(), builder);
// ... FROM file
ReaderSchemaOrchestrator reader = orchestrator.startReader();
// Create the table loader
ResultSetLoader loader = reader.makeTableLoader(null);
// file 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.
writer.addRow(1, "fred").addRow(2, "wilma");
reader.endBatch();
// Verify
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("c", MinorType.INT).buildSchema();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(1, null).addRow(2, null).build();
new RowSetComparison(expected).verifyAndClearAll(fixture.wrap(orchestrator.output()));
orchestrator.close();
}
use of org.apache.drill.exec.record.metadata.TupleMetadata 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.record.metadata.TupleMetadata 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);
}
Aggregations