Search in sources :

Example 1 with ColumnFormat

use of com.epam.parso.ColumnFormat in project drill by apache.

the class SasBatchReader method buildSchema.

private TupleMetadata buildSchema() {
    SchemaBuilder builder = new SchemaBuilder();
    List<Column> columns = sasFileReader.getColumns();
    for (Column column : columns) {
        String columnName = column.getName();
        String columnType = column.getType().getSimpleName();
        ColumnFormat columnFormat = column.getFormat();
        try {
            MinorType type = null;
            if (DateTimeConstants.TIME_FORMAT_STRINGS.contains(columnFormat.getName())) {
                type = MinorType.TIME;
            } else if (DateTimeConstants.DATE_FORMAT_STRINGS.containsKey(columnFormat.getName())) {
                type = MinorType.DATE;
            } else if (DateTimeConstants.DATETIME_FORMAT_STRINGS.containsKey(columnFormat.getName())) {
                type = MinorType.TIMESTAMP;
            } else {
                type = getType(columnType);
            }
            builder.addNullable(columnName, type);
        } catch (Exception e) {
            throw UserException.dataReadError().message("Error with type of column " + columnName + "; Type: " + columnType).addContext(errorContext).build(logger);
        }
    }
    return builder.buildSchema();
}
Also used : ColumnFormat(com.epam.parso.ColumnFormat) Column(com.epam.parso.Column) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) UserException(org.apache.drill.common.exceptions.UserException) IOException(java.io.IOException)

Aggregations

Column (com.epam.parso.Column)1 ColumnFormat (com.epam.parso.ColumnFormat)1 IOException (java.io.IOException)1 UserException (org.apache.drill.common.exceptions.UserException)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)1