use of org.apache.drill.exec.record.metadata.TupleMetadata in project drill by axbaretto.
the class RowSetPrinter method printSchema.
private void printSchema(PrintStream out, SelectionVectorMode selectionMode, RowSetReader reader) {
out.print("#");
switch(selectionMode) {
case FOUR_BYTE:
out.print(" (batch #, row #)");
break;
case TWO_BYTE:
out.print(" (row #)");
break;
default:
break;
}
out.print(": ");
TupleMetadata schema = reader.schema();
printTupleSchema(out, schema);
out.println();
}
use of org.apache.drill.exec.record.metadata.TupleMetadata in project drill by apache.
the class ReaderLifecycle method applyEarlySchema.
/**
* If schema is complete, update the output schema. The reader schema provided
* by the negotiator contains all the columns the reader could provide and is
* not adjusted for projection. The schema tracker will apply the same projection
* filter as used when loading data. As usual, the reader may not provided all
* projected columns, so we apply missing columns early to produce a fully-resolved
* scan schema.
*/
private void applyEarlySchema() {
if (schemaNegotiator.isSchemaComplete()) {
schemaTracker().applyEarlyReaderSchema(schemaNegotiator.readerSchema);
TupleMetadata missingCols = missingColumnsBuilder(schemaNegotiator.readerSchema).buildSchema();
if (missingCols != null) {
schemaTracker().resolveMissingCols(missingCols);
}
}
}
use of org.apache.drill.exec.record.metadata.TupleMetadata in project drill by apache.
the class TestScanOrchestratorImplicitColumns method testSelectNone.
/**
* Test SELECT c FROM table(a, b)
* The result set will be one null column for each record, but
* no file data.
*/
@Test
public void testSelectNone() {
ScanOrchestratorBuilder builder = new MockScanBuilder();
File file = dirTestWatcher.copyResourceToRoot(Paths.get("multilevel", "csv", "1994", "Q1", "orders_94_q1.csv"), Paths.get("x", "y", "z.csv"));
Path filePath = new Path(file.toURI().getPath());
ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
builder.withImplicitColumns(metadataManager);
// SELECT c ...
builder.projection(RowSetTestUtils.projectList("c"));
ScanSchemaOrchestrator scanner = new ScanSchemaOrchestrator(fixture.allocator(), builder);
// ... FROM file
metadataManager.startFile(filePath);
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().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).addSingleCol(null).addSingleCol(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 TestScanOrchestratorImplicitColumns method testEarlySchemaSelectAllAndMetadata.
/**
* Test SELECT a, b, dir0, suffix FROM table(a, b)
* dir0, suffix are file metadata columns
*/
@Test
public void testEarlySchemaSelectAllAndMetadata() {
// Null columns of type VARCHAR
MajorType nullType = MajorType.newBuilder().setMinorType(MinorType.VARCHAR).setMode(DataMode.OPTIONAL).build();
ScanOrchestratorBuilder builder = new MockScanBuilder();
builder.nullType(nullType);
File file = dirTestWatcher.copyResourceToRoot(Paths.get("multilevel", "csv", "1994", "Q1", "orders_94_q1.csv"), Paths.get("x", "y", "z.csv"));
Path filePath = new Path(file.toURI().getPath());
ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath));
builder.withImplicitColumns(metadataManager);
// SELECT a, b, dir0, suffix ...
builder.projection(RowSetTestUtils.projectList("a", "b", "dir0", "suffix"));
ScanSchemaOrchestrator scanner = new ScanSchemaOrchestrator(fixture.allocator(), builder);
// ... FROM file
metadataManager.startFile(filePath);
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 empty batch.
reader.defineSchema();
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).addNullable("dir0", MinorType.VARCHAR).add("suffix", MinorType.VARCHAR).buildSchema();
{
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).build();
assertNotNull(scanner.output());
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
}
// 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", "x", "csv").addRow(2, "wilma", "x", "csv").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 TestScanOrchestratorImplicitColumns method testWildcardWithMetadata.
/**
* Resolve a selection list using SELECT *.
*/
@Test
public void testWildcardWithMetadata() throws IOException {
File file = dirTestWatcher.copyResourceToRoot(Paths.get("multilevel", "csv", "1994", "Q1", "orders_94_q1.csv"), Paths.get("x", "y", "z.csv"));
Path filePath = new Path(file.toURI().getPath());
DrillFileSystem fileSystem = new DrillFileSystem(new Configuration());
ImplicitColumnManager metadataManager = new ImplicitColumnManager(fixture.getOptionManager(), standardOptions(filePath), fileSystem);
ScanOrchestratorBuilder builder = new MockScanBuilder();
builder.withImplicitColumns(metadataManager);
// SELECT *, filename, suffix ...
builder.projection(RowSetTestUtils.projectList(SchemaPath.DYNAMIC_STAR, ScanTestUtils.FULLY_QUALIFIED_NAME_COL, ScanTestUtils.FILE_PATH_COL, ScanTestUtils.FILE_NAME_COL, ScanTestUtils.SUFFIX_COL, ScanTestUtils.LAST_MODIFIED_TIME_COL, ScanTestUtils.PROJECT_METADATA_COL, ScanTestUtils.partitionColName(0), ScanTestUtils.partitionColName(1)));
ScanSchemaOrchestrator scanner = new ScanSchemaOrchestrator(fixture.allocator(), builder);
// ... FROM file
metadataManager.startFile(filePath);
ReaderSchemaOrchestrator reader = scanner.startReader();
// file schema (a, b)
TupleMetadata tableSchema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).buildSchema();
ResultSetLoader loader = reader.makeTableLoader(tableSchema);
// Create a batch of data.
reader.startBatch();
loader.writer().addRow(1, "fred").addRow(2, "wilma");
reader.endBatch();
// Verify
TupleMetadata expectedSchema = ScanTestUtils.expandImplicit(tableSchema, metadataManager, 2);
String fqn = ImplicitFileColumns.FQN.getValue(filePath);
String filePathValue = ImplicitFileColumns.FILEPATH.getValue(filePath);
String fileName = ImplicitFileColumns.FILENAME.getValue(filePath);
String suffix = ImplicitFileColumns.SUFFIX.getValue(filePath);
String lastModifiedTime = ColumnExplorer.getImplicitColumnValue(ImplicitInternalFileColumns.LAST_MODIFIED_TIME, filePath, fileSystem);
String projectMetadata = ColumnExplorer.getImplicitColumnValue(ImplicitInternalFileColumns.USE_METADATA, filePath, fileSystem);
SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(1, "fred", fqn, filePathValue, fileName, suffix, lastModifiedTime, projectMetadata, "x", "y").addRow(2, "wilma", fqn, filePathValue, fileName, suffix, lastModifiedTime, projectMetadata, "x", "y").build();
RowSetUtilities.verify(expected, fixture.wrap(scanner.output()));
scanner.close();
}
Aggregations