Package com.asakusafw.directio.hive.serde.mock

Examples of com.asakusafw.directio.hive.serde.mock.MockTypes


     * All property types.
     */
    @Test
    public void types() {
        DataModelDescriptor descriptor = FieldPropertyDescriptor.extract(MockTypes.class);
        MockTypes obj = (MockTypes) descriptor.createDataModelObject();
        obj.booleanOption.modify(true);
        obj.byteOption.modify((byte) 1);
        obj.shortOption.modify((short) 2);
        obj.intOption.modify(3);
        obj.longOption.modify(4L);
        obj.floatOption.modify(5f);
        obj.doubleOption.modify(6d);
        obj.dateOption.modify(new Date(2014, 6, 1));
        obj.dateTimeOption.modify(new DateTime(2014, 6, 1, 2, 3, 4));
        obj.stringOption.modify("Hello, world!");
        obj.decimalOption.modify(new BigDecimal("7.8"));

        DataModelInspector inspector = new DataModelInspector(descriptor);
        assertThat(inspector.getTypeName(), is(MockTypes.class.getName()));
        assertThat(inspector.getAllStructFieldRefs(), hasSize(11));
        assertThat(inspector.getStructFieldsDataAsList(obj), is(Arrays.asList(new Object[] {
                obj.booleanOption,
                obj.byteOption,
                obj.shortOption,
                obj.intOption,
                obj.longOption,
                obj.floatOption,
                obj.doubleOption,
                obj.dateOption,
                obj.dateTimeOption,
                obj.stringOption,
                obj.decimalOption,
        })));

        assertThat(getJavaField(inspector, obj, "booleanOption"), equalTo((Object) obj.booleanOption.get()));
        assertThat(getJavaField(inspector, obj, "byteOption"), equalTo((Object) obj.byteOption.get()));
        assertThat(getJavaField(inspector, obj, "shortOption"), equalTo((Object) obj.shortOption.get()));
        assertThat(getJavaField(inspector, obj, "intOption"), equalTo((Object) obj.intOption.get()));
        assertThat(getJavaField(inspector, obj, "longOption"), equalTo((Object) obj.longOption.get()));
        assertThat(getJavaField(inspector, obj, "floatOption"), equalTo((Object) obj.floatOption.get()));
        assertThat(getJavaField(inspector, obj, "doubleOption"), equalTo((Object) obj.doubleOption.get()));

        Calendar calendar = Calendar.getInstance();
        DateUtil.setDayToCalendar(obj.dateOption.get().getElapsedDays(), calendar);
        assertThat(getJavaField(inspector, obj, "dateOption"),
                equalTo((Object) new java.sql.Date(calendar.getTimeInMillis())));
        DateUtil.setSecondToCalendar(obj.dateTimeOption.get().getElapsedSeconds(), calendar);
        assertThat(getJavaField(inspector, obj, "dateTimeOption"),
                equalTo((Object) new java.sql.Timestamp(calendar.getTimeInMillis())));
        assertThat(getJavaField(inspector, obj, "stringOption"),
                equalTo((Object) obj.stringOption.getAsString()));
        assertThat(((HiveDecimal) getJavaField(inspector, obj, "decimalOption")),
                equalTo(HiveDecimal.create(obj.decimalOption.get())));

        DataModelDriver driver = new DataModelDriver(descriptor, inspector);
        MockTypes copy = new MockTypes();
        driver.set(copy, obj);

        assertThat(copy.booleanOption, equalTo(obj.booleanOption));
        assertThat(copy.byteOption, equalTo(obj.byteOption));
        assertThat(copy.shortOption, equalTo(obj.shortOption));
View Full Code Here


     * All property types with null.
     */
    @Test
    public void nulls() {
        DataModelDescriptor descriptor = FieldPropertyDescriptor.extract(MockTypes.class);
        MockTypes obj = (MockTypes) descriptor.createDataModelObject();

        DataModelInspector inspector = new DataModelInspector(descriptor);
        assertThat(inspector.getTypeName(), is(MockTypes.class.getName()));
        assertThat(inspector.getAllStructFieldRefs(), hasSize(11));
        assertThat(inspector.getStructFieldsDataAsList(obj), is(Arrays.asList(new Object[11])));

        assertThat(getJavaField(inspector, obj, "booleanOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "byteOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "shortOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "intOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "longOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "floatOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "doubleOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "decimalOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "stringOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "dateOption"), is(nullValue()));
        assertThat(getJavaField(inspector, obj, "dateTimeOption"), is(nullValue()));

        DataModelDriver driver = new DataModelDriver(descriptor, inspector);
        MockTypes copy = new MockTypes();
        copy.booleanOption.modify(true);
        copy.byteOption.modify((byte) 1);
        copy.shortOption.modify((short) 2);
        copy.intOption.modify(3);
        copy.longOption.modify(4L);
View Full Code Here

        edits.put("decimalOption", StringValueSerdeFactory.DECIMAL);
        edits.put("dateOption", StringValueSerdeFactory.DATE);
        edits.put("dateTimeOption", StringValueSerdeFactory.DATETIME);

        ParquetFileFormat<MockTypes> format = format(MockTypes.class, edits);
        MockTypes in = new MockTypes();
        in.booleanOption.modify(true);
        in.byteOption.modify((byte) 1);
        in.shortOption.modify((short) 2);
        in.intOption.modify(3);
        in.longOption.modify(4L);
        in.floatOption.modify(5f);
        in.doubleOption.modify(6d);
        in.dateOption.modify(new Date(2014, 6, 1));
        in.dateTimeOption.modify(new DateTime(2014, 6, 1, 2, 3, 4));
        in.stringOption.modify("Hello, world!");
        in.decimalOption.modify(new BigDecimal("7.8"));

        MockTypes out = restore(format, in);
        assertThat(out.booleanOption, equalTo(in.booleanOption));
        assertThat(out.byteOption, equalTo(in.byteOption));
        assertThat(out.shortOption, equalTo(in.shortOption));
        assertThat(out.intOption, equalTo(in.intOption));
        assertThat(out.longOption, equalTo(in.longOption));
View Full Code Here

        int count = 1000;
        ParquetFileFormat<MockTypes> format = format(MockTypes.class, edits);
        List<MockTypes> inputs = new ArrayList<MockTypes>();
        for (int i = 0; i < count; i++) {
            MockTypes in = new MockTypes();
            in.booleanOption.modify(true);
            in.byteOption.modify((byte) 1);
            in.shortOption.modify((short) 2);
            in.intOption.modify(3);
            in.longOption.modify(4L);
            in.floatOption.modify(5f);
            in.doubleOption.modify(6d);
            in.dateOption.modify(new Date(2014, 6, 1));
            in.dateTimeOption.modify(new DateTime(2014, 6, 1, 2, 3, 4));
            in.stringOption.modify("Hello, world!");
            in.decimalOption.modify(new BigDecimal("7.8"));
            inputs.add(in);
        }

        List<MockTypes> outputs = restore(format, inputs);
        MockTypes sample = inputs.get(0);
        for (MockTypes out : outputs) {
            assertThat(out.booleanOption, equalTo(sample.booleanOption));
            assertThat(out.byteOption, equalTo(sample.byteOption));
            assertThat(out.shortOption, equalTo(sample.shortOption));
            assertThat(out.intOption, equalTo(sample.intOption));
View Full Code Here

        edits.put("decimalOption", StringValueSerdeFactory.DECIMAL);
        edits.put("dateOption", StringValueSerdeFactory.DATE);
        edits.put("dateTimeOption", StringValueSerdeFactory.DATETIME);

        ParquetFileFormat<MockTypes> format = format(MockTypes.class, edits);
        MockTypes in = new MockTypes();
        MockTypes out = restore(format, in);
        assertThat(out.booleanOption, equalTo(in.booleanOption));
        assertThat(out.byteOption, equalTo(in.byteOption));
        assertThat(out.shortOption, equalTo(in.shortOption));
        assertThat(out.intOption, equalTo(in.intOption));
        assertThat(out.longOption, equalTo(in.longOption));
View Full Code Here

TOP

Related Classes of com.asakusafw.directio.hive.serde.mock.MockTypes

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.