use of io.confluent.ksql.GenericRow in project ksql by confluentinc.
the class KsqlGenericRowAvroDeserializerTest method shouldDeserializeIfThereAreRedundantFields.
@Test
public void shouldDeserializeIfThereAreRedundantFields() {
org.apache.kafka.connect.data.Schema newSchema = SchemaBuilder.struct().field("ordertime".toUpperCase(), org.apache.kafka.connect.data.Schema.INT64_SCHEMA).field("orderid".toUpperCase(), org.apache.kafka.connect.data.Schema.INT64_SCHEMA).field("itemid".toUpperCase(), org.apache.kafka.connect.data.Schema.STRING_SCHEMA).field("orderunits".toUpperCase(), org.apache.kafka.connect.data.Schema.FLOAT64_SCHEMA).build();
SchemaRegistryClient schemaRegistryClient = new MockSchemaRegistryClient();
List columns = Arrays.asList(1511897796092L, 1L, "item_1", 10.0, new Double[] { 100.0 }, Collections.singletonMap("key1", 100.0));
GenericRow genericRow = new GenericRow(columns);
KsqlGenericRowAvroDeserializer ksqlGenericRowAvroDeserializer = new KsqlGenericRowAvroDeserializer(newSchema, schemaRegistryClient, false);
byte[] serializedRow = getSerializedRow("t1", schemaRegistryClient, avroSchema, genericRow);
GenericRow row = ksqlGenericRowAvroDeserializer.deserialize("t1", serializedRow);
Assert.assertNotNull(row);
assertThat("Incorrect deserializarion", row.getColumns().size(), equalTo(4));
assertThat("Incorrect deserializarion", (Long) row.getColumns().get(0), equalTo(1511897796092L));
assertThat("Incorrect deserializarion", (Long) row.getColumns().get(1), equalTo(1L));
assertThat("Incorrect deserializarion", (String) row.getColumns().get(2), equalTo("item_1"));
}
use of io.confluent.ksql.GenericRow in project ksql by confluentinc.
the class KsqlGenericRowAvroSerializerTest method shouldSerializeRowWithNullValues.
@Test
@SuppressWarnings("unchecked")
public void shouldSerializeRowWithNullValues() {
SchemaRegistryClient schemaRegistryClient = new MockSchemaRegistryClient();
KsqlGenericRowAvroSerializer ksqlGenericRowAvroSerializer = new KsqlGenericRowAvroSerializer(schema, schemaRegistryClient, new KsqlConfig(new HashMap<>()));
List columns = Arrays.asList(1511897796092L, 1L, "item_1", 10.0, null, null);
GenericRow genericRow = new GenericRow(columns);
ksqlGenericRowAvroSerializer.serialize("t1", genericRow);
}
use of io.confluent.ksql.GenericRow in project ksql by confluentinc.
the class KsqlGenericRowAvroSerializerTest method shouldFailForIncompatibleType.
@Test
public void shouldFailForIncompatibleType() {
SchemaRegistryClient schemaRegistryClient = new MockSchemaRegistryClient();
KsqlGenericRowAvroSerializer ksqlGenericRowAvroSerializer = new KsqlGenericRowAvroSerializer(schema, schemaRegistryClient, new KsqlConfig(new HashMap<>()));
List columns = Arrays.asList(1511897796092L, 1L, "item_1", "10.0", new Double[] { 100.0 }, Collections.singletonMap("key1", 100.0));
GenericRow genericRow = new GenericRow(columns);
try {
byte[] serilizedRow = ksqlGenericRowAvroSerializer.serialize("t1", genericRow);
Assert.fail("Did not fail for incompatible types.");
} catch (Exception e) {
assertThat(e.getMessage(), equalTo("org.apache.kafka.common.errors.SerializationException: Error serializing Avro message"));
}
}
use of io.confluent.ksql.GenericRow in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldDeserializeJsonCorrectlyWithRedundantFields.
@Test
public void shouldDeserializeJsonCorrectlyWithRedundantFields() throws JsonProcessingException {
String rowString = "1511897796092,1,item_1,\r\n";
KsqlDelimitedDeserializer ksqlJsonDeserializer = new KsqlDelimitedDeserializer(orderSchema);
GenericRow genericRow = ksqlJsonDeserializer.deserialize("", rowString.getBytes());
assertThat(genericRow.getColumns().size(), equalTo(4));
assertThat((Long) genericRow.getColumns().get(0), equalTo(1511897796092L));
assertThat((Long) genericRow.getColumns().get(1), equalTo(1L));
assertThat((String) genericRow.getColumns().get(2), equalTo("item_1"));
Assert.assertNull(genericRow.getColumns().get(3));
}
use of io.confluent.ksql.GenericRow in project ksql by confluentinc.
the class KsqlDelimitedSerializerTest method shouldSerializeRowCorrectly.
@Test
public void shouldSerializeRowCorrectly() {
List columns = Arrays.asList(1511897796092L, 1L, "item_1", 10.0);
GenericRow genericRow = new GenericRow(columns);
KsqlDelimitedSerializer ksqlDelimitedSerializer = new KsqlDelimitedSerializer(orderSchema);
byte[] bytes = ksqlDelimitedSerializer.serialize("t1", genericRow);
String delimitedString = new String(bytes);
assertThat("Incorrect serialization.", delimitedString, equalTo("1511897796092,1,item_1,10.0"));
}
Aggregations