Sha256: 670c360190f1a6a3bdab05a1325e95dbf9c4ad561156bbb23791371d322e76ef

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

package org.embulk.input.postgresql.getter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.embulk.input.jdbc.getter.JsonColumnGetter;
import org.embulk.spi.Column;
import org.embulk.spi.PageBuilder;
import org.embulk.spi.json.JsonParseException;
import org.embulk.spi.type.Type;
import org.msgpack.value.Value;
import org.postgresql.util.HStoreConverter;

import java.util.Map;

public class HstoreToJsonColumnGetter
        extends JsonColumnGetter
{
    private final ObjectMapper mapper = new ObjectMapper();

    public HstoreToJsonColumnGetter(PageBuilder to, Type toType)
    {
        super(to, toType);
    }

    @Override
    public void jsonColumn(Column column)
    {
        Value v;
        try {
            Map map = HStoreConverter.fromString(value);
            v = jsonParser.parse(mapper.writeValueAsString(map));
        } catch (JsonProcessingException | JsonParseException e) {
            super.jsonColumn(column);
            return;
        }
        to.setJson(column, v);
    }
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
embulk-input-postgresql-0.10.1 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.10.0 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.9.3 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.9.2 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.9.1 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.9.0 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.8.6 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.8.5 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.8.4 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.8.3 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.8.2 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java
embulk-input-postgresql-0.8.1 src/main/java/org/embulk/input/postgresql/getter/HstoreToJsonColumnGetter.java