Sha256: c58ac4027617a9db13453377fd0b47ed8f60ae2c5259ad7c377dbbb3fb6e13c7
Contents?: true
Size: 1.6 KB
Versions: 6
Compression:
Stored size: 1.6 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.AbstractColumnGetter; import org.embulk.spi.Column; import org.embulk.spi.PageBuilder; import org.embulk.spi.json.JsonParseException; import org.embulk.spi.json.JsonParser; import org.embulk.spi.type.Type; import org.embulk.spi.type.Types; import org.msgpack.value.Value; import org.postgresql.util.HStoreConverter; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; public class HstoreColumnGetter extends AbstractColumnGetter { private final JsonParser parser = new JsonParser(); private final ObjectMapper mapper = new ObjectMapper(); private String value; public HstoreColumnGetter(PageBuilder to, Type toType) { super(to, toType); } @Override protected void fetch(ResultSet from, int fromIndex) throws SQLException { value = from.getString(fromIndex); } @Override protected Type getDefaultToType() { return Types.STRING; } @Override public void jsonColumn(Column column) { Value v; try { Map map = HStoreConverter.fromString(value); v = parser.parse(mapper.writeValueAsString(map)); } catch (JsonProcessingException | JsonParseException e) { super.jsonColumn(column); return; } to.setJson(column, v); } @Override public void stringColumn(Column column) { to.setString(column, value); } }
Version data entries
6 entries across 6 versions & 1 rubygems