use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KafkaSerdeFactoryTest method shouldHandle.
private static void shouldHandle(final SqlType fieldSchema, final Object value) {
// Given:
final PersistenceSchema schema = schemaWithFieldOfType(fieldSchema);
final Serde<List<?>> serde = KafkaSerdeFactory.createSerde(schema);
final List<Object> values = Collections.singletonList(value);
// When:
final byte[] bytes = serde.serializer().serialize("topic", values);
final Object result = serde.deserializer().deserialize("topic", bytes);
// Then:
assertThat(result, is(values));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KafkaSerdeFactoryTest method shouldThrowIfArray.
@Test
public void shouldThrowIfArray() {
// Given:
final PersistenceSchema schema = schemaWithFieldOfType(SqlTypes.array(SqlTypes.STRING));
// When:
final Exception e = assertThrows(KsqlException.class, () -> KafkaSerdeFactory.createSerde(schema));
// Then:
assertThat(e.getMessage(), containsString("The 'KAFKA' format does not support type 'ARRAY'"));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KafkaSerdeFactoryTest method shouldDeserializeNullAsNull.
@Test
public void shouldDeserializeNullAsNull() {
// Given:
final PersistenceSchema schema = schemaWithFieldOfType(SqlTypes.INTEGER);
final Serde<List<?>> serde = KafkaSerdeFactory.createSerde(schema);
// When:
final Object result = serde.deserializer().deserialize("topic", null);
// Then:
assertThat(result, is(nullValue()));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldThrowOnArrayTypes.
@Test
public void shouldThrowOnArrayTypes() {
// Given:
final PersistenceSchema schema = persistenceSchema(column("ids", SqlTypes.array(SqlTypes.INTEGER)));
// When:
final Exception e = assertThrows(KsqlException.class, () -> createDeserializer(schema));
// Then:
assertThat(e.getMessage(), containsString("The 'DELIMITED' format does not support type 'ARRAY', column: `ids`"));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldDeserializeDecimalWithoutLeadingZeros.
@Test
public void shouldDeserializeDecimalWithoutLeadingZeros() {
// Given:
final PersistenceSchema schema = persistenceSchema(column("cost", SqlTypes.decimal(4, 2)));
final KsqlDelimitedDeserializer deserializer = createDeserializer(schema);
final byte[] bytes = "1.12".getBytes(StandardCharsets.UTF_8);
// When:
final List<?> result = deserializer.deserialize("", bytes);
// Then:
assertThat(result, contains(new BigDecimal("1.12")));
}
Aggregations