Search in sources :

Example 1 with JsonRowSerializationSchema

use of org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema in project flink by apache.

the class JsonRowSerializationSchemaTest method serializeAndDeserialize.

private Row serializeAndDeserialize(String[] fieldNames, Class[] fieldTypes, Row row) throws IOException {
    JsonRowSerializationSchema serializationSchema = new JsonRowSerializationSchema(fieldNames);
    JsonRowDeserializationSchema deserializationSchema = new JsonRowDeserializationSchema(fieldNames, fieldTypes);
    byte[] bytes = serializationSchema.serialize(row);
    return deserializationSchema.deserialize(bytes);
}
Also used : JsonRowDeserializationSchema(org.apache.flink.streaming.util.serialization.JsonRowDeserializationSchema) JsonRowSerializationSchema(org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema)

Example 2 with JsonRowSerializationSchema

use of org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema in project flink by apache.

the class JsonRowSerializationSchemaTest method testSerializeRowWithInvalidNumberOfFields.

@Test(expected = IllegalStateException.class)
public void testSerializeRowWithInvalidNumberOfFields() {
    String[] fieldNames = new String[] { "f1", "f2", "f3" };
    Row row = new Row(1);
    row.setField(0, 1);
    JsonRowSerializationSchema serializationSchema = new JsonRowSerializationSchema(fieldNames);
    serializationSchema.serialize(row);
}
Also used : JsonRowSerializationSchema(org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 3 with JsonRowSerializationSchema

use of org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema in project flink by apache.

the class JsonRowSerializationSchemaTest method testSerializationOfTwoRows.

@Test
public void testSerializationOfTwoRows() throws IOException {
    String[] fieldNames = new String[] { "f1", "f2", "f3" };
    Class[] fieldTypes = new Class[] { Integer.class, Boolean.class, String.class };
    Row row1 = new Row(3);
    row1.setField(0, 1);
    row1.setField(1, true);
    row1.setField(2, "str");
    JsonRowSerializationSchema serializationSchema = new JsonRowSerializationSchema(fieldNames);
    JsonRowDeserializationSchema deserializationSchema = new JsonRowDeserializationSchema(fieldNames, fieldTypes);
    byte[] bytes = serializationSchema.serialize(row1);
    assertEqualRows(row1, deserializationSchema.deserialize(bytes));
    Row row2 = new Row(3);
    row2.setField(0, 10);
    row2.setField(1, false);
    row2.setField(2, "newStr");
    bytes = serializationSchema.serialize(row2);
    assertEqualRows(row2, deserializationSchema.deserialize(bytes));
}
Also used : JsonRowDeserializationSchema(org.apache.flink.streaming.util.serialization.JsonRowDeserializationSchema) JsonRowSerializationSchema(org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

JsonRowSerializationSchema (org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema)3 JsonRowDeserializationSchema (org.apache.flink.streaming.util.serialization.JsonRowDeserializationSchema)2 Row (org.apache.flink.types.Row)2 Test (org.junit.Test)2