use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.
the class TestFileScanLifecycle method testPartitionColumnTwoDigits.
/**
* Test the obscure case that the partition column contains two digits:
* dir11. Also tests the obscure case that the output only has partition
* columns.
*/
@Test
public void testPartitionColumnTwoDigits() {
Path filePath = new Path("file:/w/0/1/2/3/4/5/6/7/8/9/10/d11/z.csv");
FileScanLifecycleBuilder builder = new FileScanLifecycleBuilder();
builder.rootDir(MOCK_ROOT_PATH);
builder.maxPartitionDepth(11);
builder.projection(RowSetTestUtils.projectList("a", "b", FileScanUtils.partitionColName(11)));
builder.fileSplits(Collections.singletonList(new DummyFileWork(filePath)));
builder.useLegacyWildcardExpansion(true);
builder.readerFactory(new FileReaderFactory() {
@Override
public ManagedReader newReader(FileSchemaNegotiator negotiator) {
return new MockEarlySchemaReader(negotiator, 1);
}
});
ScanLifecycle scan = buildScan(builder);
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
assertTrue(reader.next());
TupleMetadata expectedSchema = new SchemaBuilder().addAll(SCHEMA).add(FileScanUtils.partitionColName(11), PARTITION_COL_TYPE).build();
RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "fred", "d11").addRow(20, "wilma", "d11").build();
RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
assertFalse(reader.next());
reader.close();
scan.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.
the class TestFileScanLifecycle method testAllColumns.
@Test
public void testAllColumns() {
FileScanLifecycleBuilder builder = new FileScanLifecycleBuilder();
builder.rootDir(MOCK_ROOT_PATH);
builder.maxPartitionDepth(3);
builder.projection(FileScanUtils.projectAllWithMetadata(3));
builder.fileSplits(Collections.singletonList(new DummyFileWork(MOCK_FILE_PATH)));
builder.useLegacyWildcardExpansion(true);
builder.readerFactory(new FileReaderFactory() {
@Override
public ManagedReader newReader(FileSchemaNegotiator negotiator) {
return new MockEarlySchemaReader(negotiator, 1);
}
});
ScanLifecycle scan = buildScan(builder);
assertSame(ProjectionType.ALL, scan.schemaTracker().projectionType());
RowBatchReader reader = scan.nextReader();
assertTrue(reader.open());
assertTrue(reader.next());
TupleMetadata expectedSchema = new SchemaBuilder().addAll(SCHEMA).add(FileScanUtils.FULLY_QUALIFIED_NAME_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.FILE_PATH_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.FILE_NAME_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.SUFFIX_COL, IMPLICIT_COL_TYPE).add(FileScanUtils.partitionColName(0), PARTITION_COL_TYPE).add(FileScanUtils.partitionColName(1), PARTITION_COL_TYPE).add(FileScanUtils.partitionColName(2), PARTITION_COL_TYPE).build();
RowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(10, "fred", MOCK_FILE_FQN, MOCK_FILE_DIR_PATH, MOCK_FILE_NAME, MOCK_SUFFIX, MOCK_DIR0, MOCK_DIR1, null).addRow(20, "wilma", MOCK_FILE_FQN, MOCK_FILE_DIR_PATH, MOCK_FILE_NAME, MOCK_SUFFIX, MOCK_DIR0, MOCK_DIR1, null).build();
RowSetUtilities.verify(expected, fixture.wrap(reader.output()));
assertFalse(reader.next());
reader.close();
scan.close();
}
use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.
the class TestCsvWithSchema method testRequiredColDefault.
/**
* Use a user-provided default value for a missing required column.
*/
@Test
public void testRequiredColDefault() throws Exception {
String tableName = "missingReq";
String tablePath = buildTable(tableName, multi3Contents);
try {
enableSchemaSupport();
String schemaSql = SCHEMA_SQL.replace("id int not null", "id int not null default '-1'");
run(schemaSql, tablePath);
String sql = "SELECT id, `name`, `date` FROM " + tablePath;
RowSet actual = client.queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("name", MinorType.VARCHAR).addNullable("date", MinorType.DATE).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(-1, "dino", LocalDate.of(2018, 9, 1)).build();
RowSetUtilities.verify(expected, actual);
} finally {
resetSchemaSupport();
}
}
use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.
the class TestCsvWithSchema method testMissingRequiredCol.
/**
* Show that the projection framework generates a reasonable default value
* if told to create a required column that does not exist. In this case,
* the default default [sic] value for an INT column is 0. There is no
* "default" value set in the schema, so we use a "default default" instead.)
*/
@Test
public void testMissingRequiredCol() throws Exception {
String tableName = "missingReq";
String tablePath = buildTable(tableName, multi3Contents);
try {
enableSchemaSupport();
run(SCHEMA_SQL, tablePath);
String sql = "SELECT id, `name` FROM " + tablePath;
RowSet actual = client.queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("name", MinorType.VARCHAR).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(0, "dino").build();
RowSetUtilities.verify(expected, actual);
} finally {
resetSchemaSupport();
}
}
use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.
the class TestCsvWithSchema method testWildcardStrictSchema.
/**
* Test wildcard projection with a strict schema: only schema columns are
* projected.
*/
@Test
public void testWildcardStrictSchema() throws Exception {
String tableName = "wildcardStrict";
String tablePath = buildTable(tableName, multi1Contents, reordered2Contents, nameOnlyContents);
try {
enableSchemaSupport();
String sql = SCHEMA_SQL + " PROPERTIES ('" + TupleMetadata.IS_STRICT_SCHEMA_PROP + "'='true')";
run(sql, tablePath);
sql = "SELECT * FROM " + tablePath + "ORDER BY id";
RowSet actual = client.queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).addNullable("date", MinorType.DATE).add("gender", MinorType.VARCHAR).add("comment", MinorType.VARCHAR).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(0, null, "NA", "ABC").addRow(1, LocalDate.of(2019, 1, 18), "female", "ABC").addRow(2, LocalDate.of(2019, 1, 19), "male", "ABC").addRow(3, LocalDate.of(2001, 1, 16), "NA", "ABC").addRow(4, LocalDate.of(2019, 5, 4), "NA", "ABC").build();
RowSetUtilities.verify(expected, actual);
} finally {
resetSchemaSupport();
}
}
Aggregations