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

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


     * Simple test case.
     */
    @Test
    public void simple() {
        DataModelDescriptor descriptor = FieldPropertyDescriptor.extract(MockSimple.class);
        MockSimple obj = (MockSimple) descriptor.createDataModelObject();
        obj.number.modify(12345);
        obj.string.modify("Hello, world!");

        DataModelInspector inspector = new DataModelInspector(descriptor);
        assertThat(inspector.getTypeName(), is(MockSimple.class.getName()));
        assertThat(inspector.getAllStructFieldRefs(), hasSize(2));
        assertThat(inspector.getStructFieldsDataAsList(obj), is(Arrays.asList(new Object[] {
                obj.number,
                obj.string,
        })));
        assertThat(getJavaField(inspector, obj, "number"), equalTo((Object) 12345));
        assertThat(getJavaField(inspector, obj, "string"), equalTo((Object) "Hello, world!"));

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

        assertThat(copy.number, equalTo(obj.number));
        assertThat(copy.string, equalTo(obj.string));
    }
View Full Code Here


     * test case for column name mangled object.
     */
    @Test
    public void mangled() {
        DataModelDescriptor descriptor = FieldPropertyDescriptor.extract(MockSimple.class);
        MockSimple obj = (MockSimple) descriptor.createDataModelObject();
        obj.number.modify(12345);
        obj.string.modify("Hello, world!");

        List<PropertyDescriptor> properties = new ArrayList<PropertyDescriptor>();
        for (final PropertyDescriptor property : descriptor.getPropertyDescriptors()) {
            properties.add(new PropertyDescriptor(String.format("_col%d", properties.size()), property) {
                @Override
                public ValueOption<?> extract(Object dataModel) {
                    return property.extract(dataModel);
                }
            });
        }
        DataModelDescriptor mangled = new DataModelDescriptor(descriptor.getDataModelClass(), properties);

        DataModelMapping config = new DataModelMapping();
        config.setFieldMappingStrategy(FieldMappingStrategy.NAME);
        config.setOnMissingSource(ExceptionHandlingStrategy.FAIL);
        config.setOnMissingTarget(ExceptionHandlingStrategy.IGNORE);
        config.setOnIncompatibleType(ExceptionHandlingStrategy.IGNORE);
        try {
            DataModelDriver driver = new DataModelDriver(descriptor, new DataModelInspector(mangled), config);
            MockSimple copy = new MockSimple();
            driver.set(copy, obj);
            throw new AssertionError();
        } catch (IllegalArgumentException e) {
            // ok.
        }

        config.setFieldMappingStrategy(FieldMappingStrategy.POSITION);
        DataModelDriver driver = new DataModelDriver(descriptor, new DataModelInspector(mangled), config);
        MockSimple copy = new MockSimple();
        driver.set(copy, obj);

        assertThat(copy.number, equalTo(obj.number));
        assertThat(copy.string, equalTo(obj.string));
    }
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void io_simple() throws Exception {
        OrcFileFormat<MockSimple> format = format(MockSimple.class);
        MockSimple in = new MockSimple(100, "Hello, world!");
        MockSimple out = restore(format, in);
        assertThat(out.number, is(in.number));
        assertThat(out.string, is(in.string));
    }
View Full Code Here

        OrcFileFormat<MockSimple> format2 = format(MockSimple.class, "string");
        format2.getFormatConfiguration()
            .withFieldMappingStrategy(FieldMappingStrategy.NAME)
            .withOnMissingTarget(ExceptionHandlingStrategy.IGNORE);

        MockSimple in = new MockSimple(100, "Hello, world!");
        File file = save(format1, Arrays.asList(in));
        List<MockSimple> restored = load(format2, file);

        assertThat(restored, hasSize(1));
        MockSimple out = restored.get(0);
        assertThat(out.number, is(in.number));
        assertThat(out.string, is(new StringOption())); // null
    }
View Full Code Here

        ModelOutput<MockSimple> output = format.createOutput(
                MockSimple.class,
                fs, new Path(file.toURI()),
                new Counter());
        try {
            output.write(new MockSimple(100, "Hello, world!"));
        } finally {
            output.close();
        }
        assertThat(file.exists(), is(true));

        FileStatus stat = fs.getFileStatus(new Path(file.toURI()));
        List<DirectInputFragment> fragments = format.computeInputFragments(new StripedDataFormat.InputContext(
                MockSimple.class,
                Arrays.asList(stat), fs,
                -1L, -1L,
                false, false));

        assertThat(fragments, hasSize(1));
        DirectInputFragment first = fragments.get(0);

        ModelInput<MockSimple> input = format.createInput(
                MockSimple.class,
                fs, new Path(first.getPath()),
                first.getOffset(), first.getSize(),
                new Counter());
        try {
            MockSimple buf = new MockSimple();
            assertThat(input.readTo(buf), is(true));
            assertThat(buf.number, is(new IntOption(100)));
            assertThat(buf.string, is(new StringOption("Hello, world!")));

            assertThat(input.readTo(buf), is(false));
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void io_simple() throws Exception {
        ParquetFileFormat<MockSimple> format = format(MockSimple.class);
        MockSimple in = new MockSimple(100, "Hello, world!");
        MockSimple out = restore(format, in);
        assertThat(out.number, is(new IntOption(100)));
        assertThat(out.string, is(new StringOption("Hello, world!")));
    }
View Full Code Here

     */
    @Test
    public void io_v_0_11() throws Exception {
        OrcFileFormat<MockSimple> format = format(MockSimple.class);
        format.getFormatConfiguration().withFormatVersion(OrcFile.Version.V_0_11);
        MockSimple in = new MockSimple(100, "Hello, world!");
        MockSimple out = restore(format, in);
        assertThat(out.number, is(in.number));
        assertThat(out.string, is(in.string));
    }
View Full Code Here

        ModelOutput<MockSimple> output = format.createOutput(
                MockSimple.class,
                fs, new Path(file.toURI()),
                new Counter());
        try {
            output.write(new MockSimple(100, "Hello, world!"));
        } finally {
            output.close();
        }
        assertThat(file.exists(), is(true));

        FileStatus stat = fs.getFileStatus(new Path(file.toURI()));
        List<DirectInputFragment> fragments = format.computeInputFragments(new StripedDataFormat.InputContext(
                MockSimple.class,
                Arrays.asList(stat), fs,
                -1L, -1L,
                false, false));

        assertThat(fragments, hasSize(1));
        DirectInputFragment first = fragments.get(0);

        ModelInput<MockSimple> input = format.createInput(
                MockSimple.class,
                fs, new Path(first.getPath()),
                first.getOffset(), first.getSize(),
                new Counter());
        try {
            MockSimple buf = new MockSimple();
            assertThat(input.readTo(buf), is(true));
            assertThat(buf.number, is(new IntOption(100)));
            assertThat(buf.string, is(new StringOption("Hello, world!")));

            assertThat(input.readTo(buf), is(false));
View Full Code Here

     */
    @Test
    public void io_v_2() throws Exception {
        ParquetFileFormat<MockSimple> format = format(MockSimple.class);
        format.getFormatConfiguration().withWriterVersion(WriterVersion.PARQUET_2_0);
        MockSimple in = new MockSimple(100, "Hello, world!");
        MockSimple out = restore(format, in);
        assertThat(out.number, is(new IntOption(100)));
        assertThat(out.string, is(new StringOption("Hello, world!")));
    }
View Full Code Here

        ParquetFileFormat<MockSimpleWithLong> f2 = format(MockSimpleWithLong.class);
        f2.getFormatConfiguration()
            .withFieldMappingStrategy(FieldMappingStrategy.NAME)
            .withOnIncompatibleType(ExceptionHandlingStrategy.IGNORE);

        MockSimple in = new MockSimple(100, "Hello, world!");
        File file = save(f1, Arrays.asList(in));
        List<MockSimpleWithLong> results = load(f2, file);
        assertThat(results, hasSize(1));
        MockSimpleWithLong out = results.get(0);
        assertThat(out.number, is(new LongOption()));
View Full Code Here

TOP

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

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.