Sha256: cf04e4f2823b036a536cc6489e3d97f7f15badbc1c936bc3c3c0fda9e5a1e449

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

package org.embulk.output.s3_per_record.visitor;

import org.embulk.spi.Column;
import org.embulk.spi.PageReader;
import org.embulk.spi.time.Timestamp;
import org.embulk.spi.time.TimestampFormatter;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;

import java.nio.charset.StandardCharsets;

public class JsonSingleColumnVisitor implements S3PerRecordOutputColumnVisitor {
    final PageReader reader;
    final TimestampFormatter[] timestampFormatters;
    final StringBuilder sb;

    public JsonSingleColumnVisitor(PageReader reader, TimestampFormatter[] timestampFormatters) {
        this.reader = reader;
        this.timestampFormatters = timestampFormatters;
        this.sb = new StringBuilder();
    }

    public byte[] getByteArray() {
        return sb.toString().getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public void booleanColumn(Column column) {
        boolean value = reader.getBoolean(column);
        sb.append(value);
    }

    @Override
    public void longColumn(Column column) {
        long value = reader.getLong(column);
        sb.append(value);
    }

    @Override
    public void doubleColumn(Column column) {
        double value = reader.getDouble(column);
        sb.append(value);
    }

    @Override
    public void stringColumn(Column column) {
        String value = reader.getString(column);
        sb.append(ValueFactory.newString(value).toJson());
    }

    @Override
    public void timestampColumn(Column column) {
        Timestamp value = reader.getTimestamp(column);
        TimestampFormatter formatter = timestampFormatters[column.getIndex()];
        sb.append(ValueFactory.newString(formatter.format(value)).toJson());
    }

    @Override
    public void jsonColumn(Column column) {
        Value value = reader.getJson(column);
        sb.append(value.toJson());
    }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
embulk-output-s3_per_record-0.4.0 src/main/java/org/embulk/output/s3_per_record/visitor/JsonSingleColumnVisitor.java