Search in sources :

Example 1 with TextParsingSettings

use of org.apache.drill.exec.store.easy.text.reader.TextParsingSettings 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)

Aggregations

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