Sha256: ece209e80a9bca56aae63b92f94d31e32bdb01f385b1521c80faf986c8b2a8f5

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 DoubleColumnGetter
        extends AbstractColumnGetter
{
    private double value;

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

    @Override
    protected void fetch(ResultSet from, int fromIndex) throws SQLException
    {
        value = from.getDouble(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, Double.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/DoubleColumnGetter.java
embulk-input-jdbc-0.7.4 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.7.3 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.7.2 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.7.1 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.7.0 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.6.4 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.6.3 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.6.2 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.6.1 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.6.0 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java
embulk-input-jdbc-0.5.0 src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java