use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestFileScanFramework method testMetadataColumns.
/**
* Basic sanity test of a couple of implicit columns, along
* with all table columns in table order. Full testing of implicit
* columns is done on lower-level components.
*/
@Test
public void testMetadataColumns() {
MockEarlySchemaReader reader = new MockEarlySchemaReader();
reader.batchLimit = 1;
// Select table and implicit columns.
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.setProjection("a", "b", "filename", "suffix");
builder.addReader(reader);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Expect data and implicit columns
SchemaBuilder schemaBuilder = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR, 10).add("filename", MinorType.VARCHAR).add("suffix", MinorType.VARCHAR);
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "fred", MOCK_FILE_NAME, MOCK_SUFFIX).addRow(20, "wilma", MOCK_FILE_NAME, MOCK_SUFFIX).build();
// Schema should include implicit columns.
assertTrue(scan.buildSchema());
assertEquals(expectedSchema, scan.batchAccessor().schema());
scan.batchAccessor().release();
// Read one batch, should contain implicit columns
assertTrue(scan.next());
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
// EOF
assertFalse(scan.next());
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestFileScanFramework method testLateSchemaFileWildcards.
@Test
public void testLateSchemaFileWildcards() {
// Create a mock reader, return two batches: one schema-only, another with data.
MockLateSchemaReader reader = new MockLateSchemaReader();
reader.batchLimit = 2;
reader.returnDataOnFirst = false;
// Create the scan operator
FileScanFixtureBuilder builder = new FileScanFixtureBuilder();
builder.projectAllWithAllImplicit(2);
builder.addReader(reader);
ScanFixture scanFixture = builder.build();
ScanOperatorExec scan = scanFixture.scanOp;
// Standard startup
assertFalse(reader.openCalled);
// First batch: build schema. The reader helps: it returns an
// empty first batch.
assertTrue(scan.buildSchema());
assertTrue(reader.openCalled);
assertEquals(1, reader.batchCount);
assertEquals(0, scan.batchAccessor().rowCount());
// Create the expected result.
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR, 10).add(ScanTestUtils.FULLY_QUALIFIED_NAME_COL, MinorType.VARCHAR).add(ScanTestUtils.FILE_PATH_COL, MinorType.VARCHAR).add(ScanTestUtils.FILE_NAME_COL, MinorType.VARCHAR).add(ScanTestUtils.SUFFIX_COL, MinorType.VARCHAR).add(ScanTestUtils.LAST_MODIFIED_TIME_COL, MinorType.VARCHAR).addNullable(ScanTestUtils.PROJECT_METADATA_COL, MinorType.VARCHAR).addNullable(ScanTestUtils.partitionColName(0), MinorType.VARCHAR).addNullable(ScanTestUtils.partitionColName(1), MinorType.VARCHAR).addNullable(ScanTestUtils.partitionColName(2), MinorType.VARCHAR).buildSchema();
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(30, "fred", fqn, pathToFile, MOCK_FILE_NAME, MOCK_SUFFIX, lastModifiedTime, null, MOCK_DIR0, MOCK_DIR1, null).addRow(40, "wilma", fqn, pathToFile, MOCK_FILE_NAME, MOCK_SUFFIX, lastModifiedTime, null, MOCK_DIR0, MOCK_DIR1, null).build();
assertEquals(expected.batchSchema(), scan.batchAccessor().schema());
// Next call, return with data.
assertTrue(scan.next());
RowSetUtilities.verify(expected, fixture.wrap(scan.batchAccessor().container()));
// EOF
assertFalse(scan.next());
assertTrue(reader.closeCalled);
assertEquals(0, scan.batchAccessor().rowCount());
scanFixture.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestDirectConverter method testImplicitConversion.
/**
* Tests the implicit conversions provided by the column writer itself.
* No conversion mechanism is needed in this case.
*/
@Test
public void testImplicitConversion() {
TupleMetadata schema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("fl", MinorType.FLOAT4).add("db", MinorType.FLOAT8).add("dec", MinorType.VARDECIMAL, 10, 0).buildSchema();
// Test allowed implicit conversions.
RowSet actual = new RowSetBuilder(fixture.allocator(), schema).addRow(11, 12, 13, 14, 15, 16, // int
17).addRow(21L, 22L, 23L, 24L, 25L, 26L, // long
27L).addRow(31F, 32F, 33F, 34F, 35F, 36F, // float
37F).addRow(41D, 42D, 43D, 44D, 45D, 46D, // double
47D).addRow(dec(51), dec(52), dec(53), dec(54), dec(55), dec(56), // decimal
dec(57)).build();
final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(11, 12, 13, 14L, 15F, 16D, dec(17)).addRow(21, 22, 23, 24L, 25F, 26D, dec(27)).addRow(31, 32, 33, 34L, 35F, 36D, dec(37)).addRow(41, 42, 43, 44L, 45F, 46D, dec(47)).addRow(51, 52, 53, 54L, 55L, 56D, dec(57)).build();
RowSetUtilities.verify(expected, actual);
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestDirectConverter method testStringToInterval.
/**
* Implicit conversion from String to period using default ISO
* format.
*/
@Test
public void testStringToInterval() {
TupleMetadata outputSchema = new SchemaBuilder().add("id", MinorType.INTERVALDAY).add("iy", MinorType.INTERVALYEAR).add("int", MinorType.INTERVAL).buildSchema();
TupleMetadata inputSchema = new SchemaBuilder().add("id", MinorType.VARCHAR).add("iy", MinorType.VARCHAR).add("int", MinorType.VARCHAR).buildSchema();
ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
testFixture.createConvertersFor(inputSchema);
RowSet actual = testFixture.addRow("P2DT3H4M5S", "P9Y8M", "P9Y8M2DT3H4M5S").build();
Period p1 = Period.days(2).plusHours(3).plusMinutes(4).plusSeconds(5);
Period p2 = Period.years(9).plusMonths(8);
Period p3 = p1.plus(p2);
final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(p1, p2, p3).build();
RowSetUtilities.verify(expected, actual);
}
use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet in project drill by apache.
the class TestDirectConverter method doTestBlanks.
private void doTestBlanks(DataMode mode, String frameworkOption, String colOption, Integer value) {
TupleMetadata outputSchema = new SchemaBuilder().add("col", MinorType.INT, mode).buildSchema();
ColumnMetadata colSchema = outputSchema.metadata("col");
colSchema.setProperty(ColumnMetadata.DEFAULT_VALUE_PROP, "20");
TupleMetadata inputSchema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).buildSchema();
if (colOption != null) {
colSchema = inputSchema.metadata("col");
colSchema.setProperty(ColumnMetadata.BLANK_AS_PROP, colOption);
}
Map<String, String> props = null;
if (frameworkOption != null) {
props = new HashMap<>();
props.put(ColumnMetadata.BLANK_AS_PROP, frameworkOption);
}
ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
testFixture.withProperties(props);
testFixture.createConvertersFor(inputSchema);
try {
testFixture.addSingleCol("").addSingleCol(" ").addSingleCol("10").addSingleCol(" 11 ");
} catch (Exception e) {
testFixture.build().clear();
throw e;
}
RowSet actual = testFixture.build();
final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addSingleCol(value).addSingleCol(value).addSingleCol(10).addSingleCol(11).build();
RowSetUtilities.verify(expected, actual);
}
Aggregations