1

Is any difference between the the two following approaches of obtaining a KTable?

Option 1:

var kstream = streamsBuilder.stream(topicName, Consumed.with(...));
var mappedKTable = kstream.toTable(...);

Option 2:

var nativeKTable = streamsBuilder.toTable(topicName, Consumed.with(...));
nanachimi
  • 406
  • 6
  • 23
jayachsi
  • 85
  • 1
  • 1
  • 11
  • It's a little unclear what your question is to me. -- It's seems to be kinda semantic question. What does you data represent? Maybe this 4-part blog series helps: https://www.confluent.io/blog/kafka-streams-tables-part-1-event-streaming – Matthias J. Sax Sep 02 '20 at 05:32

1 Answers1

0

When you read from a topic you read it in as a stream. If you need it as a table because you only want the most recent value for each key you can use .toTable(). This is equivalent to reading a table.

If you read a stream then you might preform an aggregation which inherently converts into a KTable.

say you have a topic with the following contents

K1: 1
K1: 2
K2: 1

Reading this as a KTable will give you:

K1: 2
K2: 1

If you were to read as a KStream and preforming a sum aggregation will result in the following Ktable

K1:3
K2:1
wcarlson
  • 216
  • 1
  • 9