Search in sources :

Example 1 with SchemaSerDe

use of com.amazonaws.athena.connector.lambda.data.SchemaSerDe in project aws-athena-query-federation by awslabs.

the class SchemaSerializationTest method serializationTest.

@Test
public void serializationTest() throws IOException {
    logger.info("serializationTest - enter");
    SchemaBuilder schemaBuilder = new SchemaBuilder();
    schemaBuilder.addMetadata("meta1", "meta-value-1");
    schemaBuilder.addMetadata("meta2", "meta-value-2");
    schemaBuilder.addField("intfield1", new ArrowType.Int(32, true));
    schemaBuilder.addField("doublefield2", new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE));
    schemaBuilder.addField("varcharfield3", new ArrowType.Utf8());
    Schema expectedSchema = schemaBuilder.build();
    SchemaSerDe serDe = new SchemaSerDe();
    ByteArrayOutputStream schemaOut = new ByteArrayOutputStream();
    serDe.serialize(expectedSchema, schemaOut);
    TestPojo expected = new TestPojo(expectedSchema);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    objectMapper.writeValue(out, expected);
    TestPojo actual = objectMapper.readValue(new ByteArrayInputStream(out.toByteArray()), TestPojo.class);
    Schema actualSchema = actual.getSchema();
    logger.info("serializationTest - fields[{}]", actualSchema.getFields());
    logger.info("serializationTest - meta[{}]", actualSchema.getCustomMetadata());
    assertEquals(expectedSchema.getFields(), actualSchema.getFields());
    assertEquals(expectedSchema.getCustomMetadata(), actualSchema.getCustomMetadata());
    logger.info("serializationTest - exit");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Schema(org.apache.arrow.vector.types.pojo.Schema) SchemaBuilder(com.amazonaws.athena.connector.lambda.data.SchemaBuilder) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SchemaSerDe(com.amazonaws.athena.connector.lambda.data.SchemaSerDe) Test(org.junit.Test)

Aggregations

SchemaBuilder (com.amazonaws.athena.connector.lambda.data.SchemaBuilder)1 SchemaSerDe (com.amazonaws.athena.connector.lambda.data.SchemaSerDe)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrowType (org.apache.arrow.vector.types.pojo.ArrowType)1 Schema (org.apache.arrow.vector.types.pojo.Schema)1 Test (org.junit.Test)1