Search in sources :

Example 6 with SimpleBean

use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean in project beam by apache.

the class SchemaRegistryTest method testGetSchemaCoder.

@Test
public void testGetSchemaCoder() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    registry.registerJavaBean(SimpleBean.class);
    Schema schema = registry.getSchema(SimpleBean.class);
    SerializableFunction<SimpleBean, Row> toRowFunction = registry.getToRowFunction(SimpleBean.class);
    SerializableFunction<Row, SimpleBean> fromRowFunction = registry.getFromRowFunction(SimpleBean.class);
    SchemaCoder schemaCoder = registry.getSchemaCoder(SimpleBean.class);
    assertTrue(schema.equivalent(schemaCoder.getSchema()));
    assertTrue(toRowFunction.equals(schemaCoder.getToRowFunction()));
    assertTrue(fromRowFunction.equals(schemaCoder.getFromRowFunction()));
    thrown.expect(NoSuchSchemaException.class);
    registry.getSchemaCoder(Double.class);
}
Also used : DefaultSchema(org.apache.beam.sdk.schemas.annotations.DefaultSchema) SimpleBean(org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 7 with SimpleBean

use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean in project beam by apache.

the class JavaBeanSchemaTest method testFromRow.

@Test
public void testFromRow() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    Row row = createSimpleRow("string");
    SimpleBean bean = registry.getFromRowFunction(SimpleBean.class).apply(row);
    assertEquals("string", bean.getStr());
    assertEquals((byte) 1, bean.getaByte());
    assertEquals((short) 2, bean.getaShort());
    assertEquals((int) 3, bean.getAnInt());
    assertEquals((long) 4, bean.getaLong());
    assertTrue(bean.isaBoolean());
    assertEquals(DATE, bean.getDateTime());
    assertEquals(DATE.toInstant(), bean.getInstant());
    assertArrayEquals("not equal", BYTE_ARRAY, bean.getBytes());
    assertArrayEquals("not equal", BYTE_ARRAY, bean.getByteBuffer().array());
    assertEquals(BigDecimal.ONE, bean.getBigDecimal());
    assertEquals("stringbuilder", bean.getStringBuilder().toString());
}
Also used : SimpleBean(org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 8 with SimpleBean

use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean in project beam by apache.

the class JavaBeanSchemaTest method testFromRowWithGetters.

@Test
public void testFromRowWithGetters() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    SimpleBean bean = createSimple("string");
    Row row = registry.getToRowFunction(SimpleBean.class).apply(bean);
    // Test that the fromRowFunction simply returns the original object back.
    SimpleBean extracted = registry.getFromRowFunction(SimpleBean.class).apply(row);
    assertSame(bean, extracted);
}
Also used : SimpleBean(org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Aggregations

SimpleBean (org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean)8 Test (org.junit.Test)8 Row (org.apache.beam.sdk.values.Row)6 BigDecimal (java.math.BigDecimal)2 DefaultTypeConversionsFactory (org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.DefaultTypeConversionsFactory)2 List (java.util.List)1 FieldValueGetter (org.apache.beam.sdk.schemas.FieldValueGetter)1 FieldValueSetter (org.apache.beam.sdk.schemas.FieldValueSetter)1 JavaBeanSchema (org.apache.beam.sdk.schemas.JavaBeanSchema)1 GetterTypeSupplier (org.apache.beam.sdk.schemas.JavaBeanSchema.GetterTypeSupplier)1 SetterTypeSupplier (org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier)1 DefaultSchema (org.apache.beam.sdk.schemas.annotations.DefaultSchema)1 NestedArrayBean (org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedArrayBean)1 NestedMapBean (org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedMapBean)1 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1