use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestScanOrchestratorEarlySchema method testEarlySchemaSelectAll.
/**
* Test SELECT a, b FROM table(a, b)
*/
@Test
public void testEarlySchemaSelectAll() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
// SELECT a, b ...
builder.projection(RowSetTestUtils.projectList("a", "b"));
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);
// Don't bother with an empty batch here or in other tests.
// Simulates the second reader in a scan.
// Create a batch of data.
reader.startBatch();
loader.writer().addRow(1, "fred").addRow(2, "wilma");
reader.endBatch();
// Verify
SingleRowSet expected = fixture.rowSetBuilder(tableSchema).addRow(1, "fred").addRow(2, "wilma").build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
scanner.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestScanOrchestratorEarlySchema method testEarlySchemaSelectNone.
/**
* Test SELECT - FROM table(a, b)
*/
@Test
public void testEarlySchemaSelectNone() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
// SELECT ...
// (Like SELECT COUNT(*) ...
builder.projection(RowSetTestUtils.projectList());
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.
assertTrue(loader.isProjectionEmpty());
assertFalse(loader.writer().column("a").isProjected());
assertFalse(loader.writer().column("b").isProjected());
// Verify empty batch.
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(new SchemaBuilder()).build();
// Create a batch of data.
reader.startBatch();
loader.writer().addRow(1, "fred").addRow(2, "wilma");
reader.endBatch();
// Verify
{
// Two rows, no data.
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow().addRow().build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
}
// Fast path to fill in empty rows
reader.startBatch();
loader.skipRows(10);
reader.endBatch();
// Verify
{
VectorContainer output = scanner.output();
assertEquals(10, output.getRecordCount());
output.zeroVectors();
}
scanner.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestScanOrchestratorEarlySchema method testEarlySchemaSelectExtra.
/**
* Test SELECT a, b, c FROM table(a, b)
* c will be null
*/
@Test
public void testEarlySchemaSelectExtra() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
// 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.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, "fred", null).addRow(2, "wilma", null).build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
scanner.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestScanOrchestratorEarlySchema method testEmptySchema.
/**
* Test SELECT * from an early-schema table of () (that is,
* a schema that consists of zero columns.
*/
@Test
public void testEmptySchema() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
// SELECT * ...
builder.projection(RowSetTestUtils.projectAll());
ScanSchemaOrchestrator scanner = new ScanSchemaOrchestrator(fixture.allocator(), builder);
// ... FROM table
ReaderSchemaOrchestrator reader = scanner.startReader();
// file schema ()
TupleMetadata tableSchema = new SchemaBuilder().buildSchema();
// Create the table loader
reader.makeTableLoader(tableSchema);
// Create a batch of data. Because there are no columns, it does
// not make sense to ready any rows.
reader.startBatch();
reader.endBatch();
// Verify
{
SingleRowSet expected = fixture.rowSetBuilder(tableSchema).build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
}
scanner.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestScanOrchestratorEarlySchema method testColumnReordering.
/**
* Verify that different table column orders are projected into the
* SELECT order, preserving vectors, so no schema change for column
* reordering.
*/
@Test
public void testColumnReordering() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
builder.enableSchemaSmoothing(true);
builder.projection(RowSetTestUtils.projectList("a", "b", "c"));
ScanSchemaOrchestrator scanner = new ScanSchemaOrchestrator(fixture.allocator(), builder);
TupleMetadata schema1 = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR, 10).add("c", MinorType.BIGINT).buildSchema();
TupleMetadata schema2 = new SchemaBuilder().add("c", MinorType.BIGINT).add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR, 10).buildSchema();
TupleMetadata schema3 = new SchemaBuilder().add("a", MinorType.INT).add("c", MinorType.BIGINT).addNullable("b", MinorType.VARCHAR, 10).buildSchema();
SchemaTracker tracker = new SchemaTracker();
int schemaVersion;
{
// ... FROM table 1
ReaderSchemaOrchestrator reader = scanner.startReader();
// Projection of (a, b, c) to (a, b, c)
ResultSetLoader loader = reader.makeTableLoader(schema1);
reader.startBatch();
loader.writer().addRow(10, "fred", 110L).addRow(20, "wilma", 110L);
reader.endBatch();
tracker.trackSchema(scanner.output());
schemaVersion = tracker.schemaVersion();
SingleRowSet expected = fixture.rowSetBuilder(schema1).addRow(10, "fred", 110L).addRow(20, "wilma", 110L).build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
scanner.closeReader();
}
{
// ... FROM table 2
ReaderSchemaOrchestrator reader = scanner.startReader();
// Projection of (c, a, b) to (a, b, c)
ResultSetLoader loader = reader.makeTableLoader(schema2);
reader.startBatch();
loader.writer().addRow(330L, 30, "bambam").addRow(440L, 40, "betty");
reader.endBatch();
tracker.trackSchema(scanner.output());
assertEquals(schemaVersion, tracker.schemaVersion());
SingleRowSet expected = fixture.rowSetBuilder(schema1).addRow(30, "bambam", 330L).addRow(40, "betty", 440L).build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
}
{
// ... FROM table 3
ReaderSchemaOrchestrator reader = scanner.startReader();
// Projection of (a, c, b) to (a, b, c)
ResultSetLoader loader = reader.makeTableLoader(schema3);
reader.startBatch();
loader.writer().addRow(50, 550L, "dino").addRow(60, 660L, "barney");
reader.endBatch();
tracker.trackSchema(scanner.output());
assertEquals(schemaVersion, tracker.schemaVersion());
SingleRowSet expected = fixture.rowSetBuilder(schema1).addRow(50, "dino", 550L).addRow(60, "barney", 660L).build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
}
scanner.close();
}
Aggregations