Search in sources :

Example 11 with PersistenceSchema

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));
}
Also used : PersistenceSchema(io.confluent.ksql.schema.ksql.PersistenceSchema) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 12 with PersistenceSchema

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'"));
}
Also used : PersistenceSchema(io.confluent.ksql.schema.ksql.PersistenceSchema) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 13 with PersistenceSchema

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()));
}
Also used : PersistenceSchema(io.confluent.ksql.schema.ksql.PersistenceSchema) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 14 with PersistenceSchema

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`"));
}
Also used : PersistenceSchema(io.confluent.ksql.schema.ksql.PersistenceSchema) SerializationException(org.apache.kafka.common.errors.SerializationException) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 15 with PersistenceSchema

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")));
}
Also used : PersistenceSchema(io.confluent.ksql.schema.ksql.PersistenceSchema) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

PersistenceSchema (io.confluent.ksql.schema.ksql.PersistenceSchema)23 Test (org.junit.Test)20 KsqlException (io.confluent.ksql.util.KsqlException)10 ImmutableList (com.google.common.collect.ImmutableList)5 BigDecimal (java.math.BigDecimal)5 List (java.util.List)5 SerializationException (org.apache.kafka.common.errors.SerializationException)3 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)2 SerdeFeature (io.confluent.ksql.serde.SerdeFeature)1 SerdeFeatures (io.confluent.ksql.serde.SerdeFeatures)1