Kafka stream, groupby multiple columns result multiple columns

1,711 views
Skip to first unread message

beji dhia

unread,
Nov 14, 2017, 3:07:58 AM11/14/17
to Confluent Platform
Hello,
 

I m a young java developer And i m beginner with kafka stream API. I have some questions about, Il be grateful if you can answer it .
 
Is there a way to create ktable using objet and grouping by a specified attribute of this object  rather than returning just premitive (key,value) types ?
For example KTable<String, Person>
With
Class Person{
Long id ;
String Name ;
Date date ;
Double money_per_day ;
……(other class attributes)
}
Class SumPersonMoney  extends Person {
Double moneySome;
}
 
 
And i want as a result  list<SumPersonMoney>  where I can get (id, Name,Sum of money )
 
 
Thank you.

Damian Guy

unread,
Nov 14, 2017, 5:59:24 AM11/14/17
to confluent...@googlegroups.com
Hi, for your first question you can use `kstream#groupBy()` or `ktable#groupBy()` to group by a specific attribute in your value object. In either case if you wanted to produce another Ktable you could then call reduce() on the returned object to generate the KTable. The reducer would be as simple as: (value1, value2) -> value2
For the KTable you also need a subtractor which would be: (value1, value2) -> value1

As for the second part i'm not entirely sure what you are asking, but it seems that you want to do an aggregation. Assuming this was on the result of the `groupBy` you could then call `aggregate` to aggregate your objects into the appropriate lists.

It might be worth having a look at some of the examples that can be found here: https://github.com/confluentinc/kafka-streams-examples

--
You received this message because you are subscribed to the Google Groups "Confluent Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to confluent-platf...@googlegroups.com.
To post to this group, send email to confluent...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/confluent-platform/59c38fc4-c0bb-40b9-9074-80cb399bdb1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages