Sha256: 876a1eedeef12282dd0a253c031c7d3673a2953049606ec8ad466434923fd8d4

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
{
    private 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 & 1 rubygems

Version Path
embulk-input-jdbc-0.8.0 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.7.4 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.7.3 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.7.2 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.7.1 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.7.0 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.6.4 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.6.3 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.6.2 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.6.1 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.6.0 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java
embulk-input-jdbc-0.5.0 src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java