Search in sources :

Example 1 with TimestampType

use of org.embulk.spi.type.TimestampType in project embulk by embulk.

the class Timestamps method newTimestampColumnFormatters.

public static TimestampFormatter[] newTimestampColumnFormatters(TimestampFormatter.Task formatterTask, Schema schema, Map<String, ? extends TimestampFormatter.TimestampColumnOption> columnOptions) {
    TimestampFormatter[] formatters = new TimestampFormatter[schema.getColumnCount()];
    int i = 0;
    for (Column column : schema.getColumns()) {
        if (column.getType() instanceof TimestampType) {
            Optional<TimestampFormatter.TimestampColumnOption> option = Optional.fromNullable(columnOptions.get(column.getName()));
            formatters[i] = TimestampFormatter.of(formatterTask, option);
        }
        i++;
    }
    return formatters;
}
Also used : TimestampFormatter(org.embulk.spi.time.TimestampFormatter) Column(org.embulk.spi.Column) TimestampType(org.embulk.spi.type.TimestampType)

Example 2 with TimestampType

use of org.embulk.spi.type.TimestampType in project embulk by embulk.

the class DynamicColumnSetterFactory method newColumnSetter.

public DynamicColumnSetter newColumnSetter(PageBuilder pageBuilder, Column column) {
    Type type = column.getType();
    if (type instanceof BooleanType) {
        return new BooleanColumnSetter(pageBuilder, column, defaultValue);
    } else if (type instanceof LongType) {
        return new LongColumnSetter(pageBuilder, column, defaultValue);
    } else if (type instanceof DoubleType) {
        return new DoubleColumnSetter(pageBuilder, column, defaultValue);
    } else if (type instanceof StringType) {
        TimestampFormatter formatter = TimestampFormatter.of(getTimestampFormatForFormatter(column), getTimeZoneId(column));
        return new StringColumnSetter(pageBuilder, column, defaultValue, formatter);
    } else if (type instanceof TimestampType) {
        // TODO use flexible time format like Ruby's Time.parse
        final TimestampParser parser;
        if (this.useColumnForTimestampMetadata) {
            final TimestampType timestampType = (TimestampType) type;
            // https://github.com/embulk/embulk/issues/935
            parser = TimestampParser.of(getFormatFromTimestampTypeWithDepracationSuppressed(timestampType), getTimeZoneId(column));
        } else {
            parser = TimestampParser.of(getTimestampFormatForParser(column), getTimeZoneId(column));
        }
        return new TimestampColumnSetter(pageBuilder, column, defaultValue, parser);
    } else if (type instanceof JsonType) {
        TimestampFormatter formatter = TimestampFormatter.of(getTimestampFormatForFormatter(column), getTimeZoneId(column));
        return new JsonColumnSetter(pageBuilder, column, defaultValue, formatter);
    }
    throw new ConfigException("Unknown column type: " + type);
}
Also used : TimestampFormatter(org.embulk.spi.time.TimestampFormatter) JsonType(org.embulk.spi.type.JsonType) LongType(org.embulk.spi.type.LongType) LongColumnSetter(org.embulk.spi.util.dynamic.LongColumnSetter) StringType(org.embulk.spi.type.StringType) TimestampParser(org.embulk.spi.time.TimestampParser) BooleanType(org.embulk.spi.type.BooleanType) ConfigException(org.embulk.config.ConfigException) JsonColumnSetter(org.embulk.spi.util.dynamic.JsonColumnSetter) JsonType(org.embulk.spi.type.JsonType) LongType(org.embulk.spi.type.LongType) TimestampType(org.embulk.spi.type.TimestampType) DoubleType(org.embulk.spi.type.DoubleType) Type(org.embulk.spi.type.Type) BooleanType(org.embulk.spi.type.BooleanType) StringType(org.embulk.spi.type.StringType) DoubleColumnSetter(org.embulk.spi.util.dynamic.DoubleColumnSetter) DoubleType(org.embulk.spi.type.DoubleType) TimestampType(org.embulk.spi.type.TimestampType) StringColumnSetter(org.embulk.spi.util.dynamic.StringColumnSetter) BooleanColumnSetter(org.embulk.spi.util.dynamic.BooleanColumnSetter) TimestampColumnSetter(org.embulk.spi.util.dynamic.TimestampColumnSetter)

Example 3 with TimestampType

use of org.embulk.spi.type.TimestampType in project embulk by embulk.

the class Timestamps method newTimestampColumnParsers.

public static TimestampParser[] newTimestampColumnParsers(TimestampParser.Task parserTask, SchemaConfig schema) {
    TimestampParser[] parsers = new TimestampParser[schema.getColumnCount()];
    int i = 0;
    for (ColumnConfig column : schema.getColumns()) {
        if (column.getType() instanceof TimestampType) {
            TimestampColumnOption option = column.getOption().loadConfig(TimestampColumnOption.class);
            parsers[i] = TimestampParser.of(parserTask, option);
        }
        i++;
    }
    return parsers;
}
Also used : ColumnConfig(org.embulk.spi.ColumnConfig) TimestampParser(org.embulk.spi.time.TimestampParser) TimestampType(org.embulk.spi.type.TimestampType)

Aggregations

TimestampType (org.embulk.spi.type.TimestampType)3 TimestampFormatter (org.embulk.spi.time.TimestampFormatter)2 TimestampParser (org.embulk.spi.time.TimestampParser)2 ConfigException (org.embulk.config.ConfigException)1 Column (org.embulk.spi.Column)1 ColumnConfig (org.embulk.spi.ColumnConfig)1 BooleanType (org.embulk.spi.type.BooleanType)1 DoubleType (org.embulk.spi.type.DoubleType)1 JsonType (org.embulk.spi.type.JsonType)1 LongType (org.embulk.spi.type.LongType)1 StringType (org.embulk.spi.type.StringType)1 Type (org.embulk.spi.type.Type)1 BooleanColumnSetter (org.embulk.spi.util.dynamic.BooleanColumnSetter)1 DoubleColumnSetter (org.embulk.spi.util.dynamic.DoubleColumnSetter)1 JsonColumnSetter (org.embulk.spi.util.dynamic.JsonColumnSetter)1 LongColumnSetter (org.embulk.spi.util.dynamic.LongColumnSetter)1 StringColumnSetter (org.embulk.spi.util.dynamic.StringColumnSetter)1 TimestampColumnSetter (org.embulk.spi.util.dynamic.TimestampColumnSetter)1