use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldThrowOnStructTypes.
@Test
public void shouldThrowOnStructTypes() {
// Given:
final PersistenceSchema schema = persistenceSchema(column("ids", SqlTypes.struct().field("f0", SqlTypes.INTEGER).build()));
// When:
final Exception e = assertThrows(KsqlException.class, () -> createDeserializer(schema));
// Then:
assertThat(e.getMessage(), containsString("The 'DELIMITED' format does not support type 'STRUCT', column: `ids`"));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KsqlDelimitedDeserializerTest method shouldDeserializeNegativeDecimalSerializedAsString.
@Test
public void shouldDeserializeNegativeDecimalSerializedAsString() {
// 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 KsqlDelimitedDeserializerTest method shouldDeserializeDecimalWithTooSmallScale.
@Test
public void shouldDeserializeDecimalWithTooSmallScale() {
// Given:
final PersistenceSchema schema = persistenceSchema(column("cost", SqlTypes.decimal(4, 2)));
final KsqlDelimitedDeserializer deserializer = createDeserializer(schema);
final byte[] bytes = "2".getBytes(StandardCharsets.UTF_8);
// When:
final List<?> result = deserializer.deserialize("", bytes);
// Then:
assertThat(result, contains(new BigDecimal("2.00")));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KafkaSerdeFactoryTest method shouldHandleNullKeyColumn.
@Test
public void shouldHandleNullKeyColumn() {
// Given:
final LogicalSchema logical = LogicalSchema.builder().valueColumn(ColumnName.of("f0"), SqlTypes.INTEGER).build();
final PersistenceSchema schema = PhysicalSchema.from(logical, SerdeFeatures.of(), SerdeFeatures.of()).keySchema();
final Serde<List<?>> serde = KafkaSerdeFactory.createSerde(schema);
// When:
final byte[] bytes = serde.serializer().serialize("topic", null);
final Object result = serde.deserializer().deserialize("topic", null);
// Then:
assertThat(bytes, is(nullValue()));
assertThat(result, is(nullValue()));
}
use of io.confluent.ksql.schema.ksql.PersistenceSchema in project ksql by confluentinc.
the class KafkaSerdeFactoryTest method shouldHandleEmptyKey.
@Test
public void shouldHandleEmptyKey() {
// Given:
final LogicalSchema logical = LogicalSchema.builder().valueColumn(ColumnName.of("f0"), SqlTypes.INTEGER).build();
final PersistenceSchema schema = PhysicalSchema.from(logical, SerdeFeatures.of(), SerdeFeatures.of()).keySchema();
final Serde<List<?>> serde = KafkaSerdeFactory.createSerde(schema);
// When:
final byte[] bytes = serde.serializer().serialize("topic", ImmutableList.of());
final Object result = serde.deserializer().deserialize("topic", null);
// Then:
assertThat(bytes, is(nullValue()));
assertThat(result, is(nullValue()));
}
Aggregations