Search in sources :

Example 16 with PersistenceSchema

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

Example 17 with PersistenceSchema

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`"));
}
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 18 with PersistenceSchema

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

Example 19 with PersistenceSchema

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

Example 20 with PersistenceSchema

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