Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-9321

StreamsBuilder table method overwrites the materialized parameter

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 2.3.0, 2.4.0
    • None
    • streams
    • None

    Description

      One of the methods on the StreamsBuilder to create a KTable takes 3 arguments:

      // code placeholder
      
      public synchronized <K, V> KTable<K, V> table(final String topic,
                                                    final Consumed<K, V> consumed,
                                                    final Materialized<K, V, KeyValueStore<Bytes, byte[]>> materialized)
      

      The method code, however, overwrites the materialized Key & Value serde with the ones coming from consumed. There is already  .table(String, Consumed)  which constructs the table this way. 

       

      // code placeholder
      ...
      final ConsumedInternal<K, V> consumedInternal = new ConsumedInternal<>(consumed);
      materialized.withKeySerde(consumedInternal.keySerde()).withValueSerde(consumedInternal.valueSerde());

      This stops use cases where a table should consume let's say Json but materialize it as Avro. 

       

      Suggestion

      Drop the line overwriting the Key&Value serdes and ideally remove the `withKeySerde` and `withValueSerde` from Materialized - it could help avoid scenarios like this where state is changed unexpectedly and incorrectly.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              stefanbocutiu Stefan Bocutiu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: