Search in sources :

Example 1 with ValueSerdeFactory

use of io.confluent.ksql.serde.ValueSerdeFactory in project ksql by confluentinc.

the class KafkaConsumerFactory method create.

public static KafkaConsumer<Object, GenericRow> create(final KsqlTopic ksqlTopic, final LogicalSchema logicalSchema, final ServiceContext serviceContext, final Map<String, Object> consumerProperties, final KsqlConfig ksqlConfig, final String consumerGroupId) {
    final PhysicalSchema physicalSchema = PhysicalSchema.from(logicalSchema, ksqlTopic.getKeyFormat().getFeatures(), ksqlTopic.getValueFormat().getFeatures());
    final KeySerdeFactory keySerdeFactory = new GenericKeySerDe();
    final Deserializer<Object> keyDeserializer;
    if (ksqlTopic.getKeyFormat().getWindowInfo().isPresent()) {
        final Serde<Windowed<GenericKey>> keySerde = keySerdeFactory.create(ksqlTopic.getKeyFormat().getFormatInfo(), ksqlTopic.getKeyFormat().getWindowInfo().get(), physicalSchema.keySchema(), ksqlConfig, serviceContext.getSchemaRegistryClientFactory(), "", NoopProcessingLogContext.INSTANCE, Optional.empty());
        keyDeserializer = getDeserializer(keySerde.deserializer());
    } else {
        final Serde<GenericKey> keySerde = keySerdeFactory.create(ksqlTopic.getKeyFormat().getFormatInfo(), physicalSchema.keySchema(), ksqlConfig, serviceContext.getSchemaRegistryClientFactory(), "", NoopProcessingLogContext.INSTANCE, Optional.empty());
        keyDeserializer = getDeserializer(keySerde.deserializer());
    }
    final ValueSerdeFactory valueSerdeFactory = new GenericRowSerDe();
    final Serde<GenericRow> valueSerde = valueSerdeFactory.create(ksqlTopic.getValueFormat().getFormatInfo(), physicalSchema.valueSchema(), ksqlConfig, serviceContext.getSchemaRegistryClientFactory(), "", NoopProcessingLogContext.INSTANCE, Optional.empty());
    return new KafkaConsumer<>(consumerConfig(consumerProperties, ksqlConfig, consumerGroupId), keyDeserializer, valueSerde.deserializer());
}
Also used : ValueSerdeFactory(io.confluent.ksql.serde.ValueSerdeFactory) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) GenericKeySerDe(io.confluent.ksql.serde.GenericKeySerDe) GenericRowSerDe(io.confluent.ksql.serde.GenericRowSerDe) Windowed(org.apache.kafka.streams.kstream.Windowed) GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) GenericKey(io.confluent.ksql.GenericKey) KeySerdeFactory(io.confluent.ksql.serde.KeySerdeFactory)

Example 2 with ValueSerdeFactory

use of io.confluent.ksql.serde.ValueSerdeFactory in project ksql by confluentinc.

the class InsertsSubscriber method createInsertsSubscriber.

public static InsertsSubscriber createInsertsSubscriber(final ServiceContext serviceContext, final JsonObject properties, final DataSource dataSource, final KsqlConfig ksqlConfig, final Context context, final Subscriber<InsertResult> acksSubscriber, final WorkerExecutor workerExecutor) {
    final KsqlConfig configCopy = ksqlConfig.cloneWithPropertyOverwrite(properties.getMap());
    final Producer<byte[], byte[]> producer = serviceContext.getKafkaClientSupplier().getProducer(configCopy.originals());
    final PhysicalSchema physicalSchema = PhysicalSchema.from(dataSource.getSchema(), dataSource.getKsqlTopic().getKeyFormat().getFeatures(), dataSource.getKsqlTopic().getValueFormat().getFeatures());
    final KeySerdeFactory keySerdeFactory = new GenericKeySerDe();
    final Serde<GenericKey> keySerde = keySerdeFactory.create(dataSource.getKsqlTopic().getKeyFormat().getFormatInfo(), physicalSchema.keySchema(), ksqlConfig, serviceContext.getSchemaRegistryClientFactory(), "", NoopProcessingLogContext.INSTANCE, Optional.empty());
    final ValueSerdeFactory valueSerdeFactory = new GenericRowSerDe();
    final Serde<GenericRow> valueSerde = valueSerdeFactory.create(dataSource.getKsqlTopic().getValueFormat().getFormatInfo(), physicalSchema.valueSchema(), ksqlConfig, serviceContext.getSchemaRegistryClientFactory(), "", NoopProcessingLogContext.INSTANCE, Optional.empty());
    final BufferedPublisher<InsertResult> acksPublisher = new BufferedPublisher<>(context);
    acksPublisher.subscribe(acksSubscriber);
    return new InsertsSubscriber(context, producer, dataSource, keySerde.serializer(), valueSerde.serializer(), acksPublisher, workerExecutor);
}
Also used : InsertResult(io.confluent.ksql.api.server.InsertResult) ValueSerdeFactory(io.confluent.ksql.serde.ValueSerdeFactory) KsqlConfig(io.confluent.ksql.util.KsqlConfig) GenericKeySerDe(io.confluent.ksql.serde.GenericKeySerDe) GenericRowSerDe(io.confluent.ksql.serde.GenericRowSerDe) GenericRow(io.confluent.ksql.GenericRow) BufferedPublisher(io.confluent.ksql.reactive.BufferedPublisher) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) GenericKey(io.confluent.ksql.GenericKey) KeySerdeFactory(io.confluent.ksql.serde.KeySerdeFactory)

Aggregations

GenericKey (io.confluent.ksql.GenericKey)2 GenericRow (io.confluent.ksql.GenericRow)2 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)2 GenericKeySerDe (io.confluent.ksql.serde.GenericKeySerDe)2 GenericRowSerDe (io.confluent.ksql.serde.GenericRowSerDe)2 KeySerdeFactory (io.confluent.ksql.serde.KeySerdeFactory)2 ValueSerdeFactory (io.confluent.ksql.serde.ValueSerdeFactory)2 InsertResult (io.confluent.ksql.api.server.InsertResult)1 BufferedPublisher (io.confluent.ksql.reactive.BufferedPublisher)1 KsqlConfig (io.confluent.ksql.util.KsqlConfig)1 KafkaConsumer (org.apache.kafka.clients.consumer.KafkaConsumer)1 Windowed (org.apache.kafka.streams.kstream.Windowed)1