Search in sources :

Example 1 with PersistenceSchema

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

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

Example 3 with PersistenceSchema

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

Example 4 with PersistenceSchema

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

Example 5 with PersistenceSchema

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