Search in sources :

Example 1 with ColumnsScanBuilder

use of org.apache.drill.exec.physical.impl.scan.columns.ColumnsScanFramework.ColumnsScanBuilder in project drill by apache.

the class TextFormatPlugin method frameworkBuilder.

@Override
protected FileScanBuilder frameworkBuilder(OptionManager options, EasySubScan scan) throws ExecutionSetupException {
    ColumnsScanBuilder builder = new ColumnsScanBuilder();
    initScanBuilder(builder, scan);
    TextParsingSettings settings = new TextParsingSettings(getConfig(), scan.getSchema());
    builder.setReaderFactory(new ColumnsReaderFactory(settings, scan.getMaxRecords()));
    // If this format has no headers, or wants to skip them,
    // then we must use the columns column to hold the data.
    builder.requireColumnsArray(!settings.isHeaderExtractionEnabled() && builder.providedSchema() == null);
    // Text files handle nulls in an unusual way. Missing columns
    // are set to required Varchar and filled with blanks. Yes, this
    // means that the SQL statement or code cannot differentiate missing
    // columns from empty columns, but that is how CSV and other text
    // files have been defined within Drill.
    builder.nullType(Types.required(MinorType.VARCHAR));
    // The text readers use required Varchar columns to represent null columns.
    builder.allowRequiredNullColumns(true);
    // Provide custom error context
    builder.errorContext(new ChildErrorContext(builder.errorContext()) {

        @Override
        public void addContext(UserException.Builder builder) {
            super.addContext(builder);
            builder.addContext("Extract headers:", Boolean.toString(getConfig().isHeaderExtractionEnabled()));
            builder.addContext("Skip first line:", Boolean.toString(getConfig().isSkipFirstLine()));
        }
    });
    return builder;
}
Also used : TextParsingSettings(org.apache.drill.exec.store.easy.text.reader.TextParsingSettings) ChildErrorContext(org.apache.drill.common.exceptions.ChildErrorContext) ColumnsScanBuilder(org.apache.drill.exec.physical.impl.scan.columns.ColumnsScanFramework.ColumnsScanBuilder) UserException(org.apache.drill.common.exceptions.UserException)

Example 2 with ColumnsScanBuilder

use of org.apache.drill.exec.physical.impl.scan.columns.ColumnsScanFramework.ColumnsScanBuilder in project drill by apache.

the class TestColumnsArray method buildScan.

private ScanSchemaOrchestrator buildScan(boolean requireColumns, List<SchemaPath> cols) {
    // Set up the columns array manager
    ColumnsArrayManager colsManager = new ColumnsArrayManager(requireColumns);
    // Configure the schema orchestrator
    ScanOrchestratorBuilder builder = new ColumnsScanBuilder();
    builder.addParser(colsManager.projectionParser());
    builder.addResolver(colsManager.resolver());
    builder.projection(cols);
    return new ScanSchemaOrchestrator(fixture.allocator(), builder);
}
Also used : ColumnsArrayManager(org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayManager) ScanOrchestratorBuilder(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator.ScanOrchestratorBuilder) ColumnsScanBuilder(org.apache.drill.exec.physical.impl.scan.columns.ColumnsScanFramework.ColumnsScanBuilder) ScanSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator)

Aggregations

ColumnsScanBuilder (org.apache.drill.exec.physical.impl.scan.columns.ColumnsScanFramework.ColumnsScanBuilder)2 ChildErrorContext (org.apache.drill.common.exceptions.ChildErrorContext)1 UserException (org.apache.drill.common.exceptions.UserException)1 ColumnsArrayManager (org.apache.drill.exec.physical.impl.scan.columns.ColumnsArrayManager)1 ScanSchemaOrchestrator (org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator)1 ScanOrchestratorBuilder (org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator.ScanOrchestratorBuilder)1 TextParsingSettings (org.apache.drill.exec.store.easy.text.reader.TextParsingSettings)1