Sha256: 28de1bce6614789ac2c978b96082645ea69033a9326ede147f633d58baaf32d2

Contents?: true

Size: 1.45 KB

Versions: 12

Compression:

Stored size: 1.45 KB

Contents

package org.embulk.input.jdbc.getter;

import java.math.RoundingMode;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.embulk.spi.Column;
import org.embulk.spi.PageBuilder;
import org.embulk.spi.type.Type;
import org.embulk.spi.type.Types;
import com.google.common.math.DoubleMath;

public class FloatColumnGetter
        extends AbstractColumnGetter
{
    protected float value;

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

    @Override
    protected void fetch(ResultSet from, int fromIndex) throws SQLException
    {
        value = from.getFloat(fromIndex);
    }

    @Override
    protected Type getDefaultToType()
    {
        return Types.DOUBLE;
    }

    @Override
    public void booleanColumn(Column column)
    {
        to.setBoolean(column, value > 0.0);
    }

    @Override
    public void longColumn(Column column)
    {
        long l;
        try {
            // TODO configurable rounding mode
            l = DoubleMath.roundToLong(value, RoundingMode.HALF_UP);
        } catch (ArithmeticException e) {
            // NaN / Infinite / -Infinite
            super.longColumn(column);
            return;
        }
        to.setLong(column, l);
    }

    @Override
    public void doubleColumn(Column column)
    {
        to.setDouble(column, value);
    }

    @Override
    public void stringColumn(Column column)
    {
        to.setString(column, Float.toString(value));
    }
}

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
embulk-input-jdbc-0.10.0 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.9.3 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.9.2 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-athena-0.1.0 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.9.1 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.9.0 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.8.6 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.8.5 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.8.4 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.8.3 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.8.2 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.8.1 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java