2

Let's say I have 2 kafka streams (kafka-streams-scala library, version 2.2.0):

val builder: StreamsBuilder = new StreamsBuilder
val stream1: KStream[String, GenericRecord] = builder.stream[String, GenericRecord]("topic1")
val stream2: KStream[String, GenericRecord] = builder.stream[String, GenericRecord]("topic2")

and their join:

val stream3: KStream[String, MyClass] = flights.join(schedules)((r1, r2) =>  MyClass(r1.get("f1"), r2.get("f2")), JoinWindows.of(Duration.ofSeconds(30))

What is the equivalent of WHERE clause available in KSQL? (see late_orders stream) for streams API? Is it a good idea to just use stream3.filter? Will this approach have the same efficiency as stream created by KSQL?

Matthias J. Sax
  • 59,682
  • 7
  • 117
  • 137
Andrii Black
  • 185
  • 2
  • 14
  • 1
    [`.filter`](https://docs.confluent.io/current/streams/developer-guide/dsl-api.html#streams-developer-guide-dsl-transformations-stateless) is the same as a `WHERE`, yes. – OneCricketeer May 03 '19 at 18:45

1 Answers1

3

What is the equivalent of WHERE clause available in KSQL? (see late_orders stream) for streams API?

It is:

  • KStream#filter(), which returns a filtered KStream
  • KTable#filter(), which returns a filtered KTable

https://kafka.apache.org/documentation/streams/developer-guide/dsl-api.html#stateless-transformations

Is it a good idea to just use stream3.filter?

Yes.

Will this approach have the same efficiency as stream created by KSQL?

Yes.

miguno
  • 14,498
  • 3
  • 47
  • 63