use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldDeserializeNegativeDecimalSerializedAsNumber.
@Test
public void shouldDeserializeNegativeDecimalSerializedAsNumber() {
// 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")));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldThrowOnMapTypes.
@Test
public void shouldThrowOnMapTypes() {
// Given:
final PersistenceSchema schema = persistenceSchema(column("ids", SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT)));
// When:
final Exception e = assertThrows(KsqlException.class, () -> createDeserializer(schema));
// Then:
assertThat(e.getMessage(), containsString("The 'DELIMITED' format does not support type 'MAP', column: `ids`"));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldDeserializedTopLevelPrimitiveTypeIfSchemaHasOnlySingleField.
@Test
public void shouldDeserializedTopLevelPrimitiveTypeIfSchemaHasOnlySingleField() {
// Given:
final PersistenceSchema schema = persistenceSchema(column("id", SqlTypes.INTEGER));
final KsqlDelimitedDeserializer deserializer = createDeserializer(schema);
final byte[] bytes = "10".getBytes(StandardCharsets.UTF_8);
// When:
final List<?> result = deserializer.deserialize("", bytes);
// Then:
assertThat(result, contains(10));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldDeserializeDecimal.
@Test
public void shouldDeserializeDecimal() {
// Given:
final PersistenceSchema schema = persistenceSchema(column("cost", SqlTypes.decimal(4, 2)));
final KsqlDelimitedDeserializer deserializer = createDeserializer(schema);
final byte[] bytes = "01.12".getBytes(StandardCharsets.UTF_8);
// When:
final List<?> result = deserializer.deserialize("", bytes);
// Then:
assertThat(result, contains(new BigDecimal("1.12")));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KafkaSerdeFactoryTest method shouldSerializeNullAsNull.
@Test
public void shouldSerializeNullAsNull() {
// Given:
final PersistenceSchema schema = schemaWithFieldOfType(SqlTypes.INTEGER);
final Serde<List<?>> serde = KafkaSerdeFactory.createSerde(schema);
// When:
final byte[] result = serde.serializer().serialize("topic", null);
// Then:
assertThat(result, is(nullValue()));
}
Aggregations