Package com.asakusafw.runtime.value

Examples of com.asakusafw.runtime.value.DecimalOption$DecimalBuffer


        super(TypeInfoFactory.getDecimalTypeInfo(precision, scale));
    }

    @Override
    protected ValueOption<?> newObject() {
        return new DecimalOption();
    }
View Full Code Here


        return new DecimalOption();
    }

    @Override
    public HiveDecimal getPrimitiveJavaObject(Object o) {
        DecimalOption object = (DecimalOption) o;
        if (object == null || object.isNull()) {
            return null;
        }
        return convert(object.get());
    }
View Full Code Here

    static final class FromDecimalOption extends AbstractWriter {

        @Override
        protected String toString(Object value) {
            DecimalOption option = (DecimalOption) value;
            return option.get().toPlainString();
        }
View Full Code Here

    static class StringDecimalOptionInspector extends AbstractStringInspector {

        @Override
        protected ValueOption<?> newObject() {
            return new DecimalOption();
        }
View Full Code Here

    @Test
    public void getDecimal() {
        ValueSerde serde = ValueSerdeFactory.getDecimal(10, 2);
        HiveDecimalObjectInspector inspector = (HiveDecimalObjectInspector) serde.getInspector();

        DecimalOption option = new DecimalOption(new BigDecimal("123.45"));
        HiveDecimal value = HiveDecimal.create(new BigDecimal("123.45"));

        assertThat(inspector.copyObject(option), is((Object) option));
        assertThat(inspector.copyObject(option), is(not(sameInstance((Object) option))));
        assertThat(inspector.copyObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveJavaObject(option), is(value));
        assertThat(inspector.getPrimitiveJavaObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveWritableObject(option), is(new HiveDecimalWritable(value)));
        assertThat(inspector.getPrimitiveWritableObject(null), is(nullValue()));

        ValueDriver driver = serde.getDriver(inspector);
        DecimalOption copy = new DecimalOption();

        driver.set(copy, option);
        assertThat(copy, is(option));
        driver.set(copy, null);
        assertThat(copy.isNull(), is(true));
    }
View Full Code Here

    @Test
    public void decimal_by_string() {
        ValueSerde serde = StringValueSerdeFactory.DECIMAL;
        StringObjectInspector inspector = (StringObjectInspector) serde.getInspector();

        DecimalOption option = new DecimalOption(new BigDecimal("123.45"));
        String value = "123.45";

        assertThat(inspector.copyObject(option), is((Object) option));
        assertThat(inspector.copyObject(option), is(not(sameInstance((Object) option))));
        assertThat(inspector.copyObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveJavaObject(option), is(value));
        assertThat(inspector.getPrimitiveJavaObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveWritableObject(option), is(new Text(value)));
        assertThat(inspector.getPrimitiveWritableObject(null), is(nullValue()));

        ValueDriver driver = serde.getDriver(inspector);
        DecimalOption copy = new DecimalOption();

        driver.set(copy, option);
        assertThat(copy, is(option));
        driver.set(copy, null);
        assertThat(copy.isNull(), is(true));
    }
View Full Code Here

    @Test
    public void decimal_values() throws Exception {
        CsvParser parser = create(
                "0,1,50,-1,-50,"
                + "0.5,-0.5,3.1415,-3.1415, 0,0 , ,");
        DecimalOption option = new DecimalOption();

        assertThat(parser.next(), is(true));

        parser.fill(option);
        assertThat(option.get(), is(decimal("0")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("1")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("50")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("-1")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("-50")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("0.5")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("-0.5")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("3.1415")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("-3.1415")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("0")));

        parser.fill(option);
        assertThat(option.get(), is(decimal("0")));

        parser.fill(option);
        assertThat(option.isNull(), is(true));

        parser.fill(option);
        assertThat(option.isNull(), is(true));

        parser.endRecord();
        assertThat(parser.next(), is(false));
    }
View Full Code Here

     * decimalの値を解析するテスト。
     * @throws Exception 例外が発生した場合
     */
    @Test
    public void fillDecimal() throws Exception {
        DecimalOption value = new DecimalOption();
        create("decimal");

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.get(), is(decimal("0")));
        parser.fill(value);
        assertThat(value.get(), is(decimal("10")));
        parser.fill(value);
        assertThat(value.get(), is(decimal("-10")));
        parser.endRecord();

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.get(), is(decimal("0.9999999999999999999999999999999999999999999999999")));
        parser.fill(value);
        assertThat(value.get(), is(decimal("9223372036854775809")));
        parser.endRecord();

        assertThat(parser.next(), is(false));
    }
View Full Code Here

     * test for decimal values.
     * @throws Exception if failed
     */
    @Test
    public void decimal_values() throws Exception {
        assertRestorable(new DecimalOption(decimal("0")));
        assertRestorable(new DecimalOption(decimal("-100")));
        assertRestorable(new DecimalOption(decimal("1")));
        assertRestorable(new DecimalOption(decimal("-1")));
        assertRestorable(new DecimalOption(decimal("100")));
        assertRestorable(new DecimalOption(decimal("-100")));
        assertRestorable(new DecimalOption(decimal("3.1415")));
        assertRestorable(new DecimalOption(decimal("-3.1415")));
        assertRestorable(new DecimalOption());
    }
View Full Code Here

    @Test
    public void invalid_decimal() throws Exception {
        CsvParser parser = create(String.valueOf("?"));
        assertThat(parser.next(), is(true));
        try {
            parser.fill(new DecimalOption());
            fail();
        } catch (CsvFormatException e) {
            assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT));
        }
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.runtime.value.DecimalOption$DecimalBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.