# Ktable flatMap+groupBy

**URL:** <https://forum.confluent.io/t/ktable-flatmap-groupby/6020>\
**Category:** Kafka Streams\
**Created:** [11 September 2022 18:05 UTC](https://forum.confluent.io/t/ktable-flatmap-groupby/6020 "2022-09-11T18:05:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![koertkuipers](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/koertkuipers/32/2395_2.png) [@koertkuipers](https://forum.confluent.io/u/koertkuipers)\
**Post date:** [11 September 2022 18:05 UTC](https://forum.confluent.io/t/ktable-flatmap-groupby/6020/1 "2022-09-11T18:05:48Z")

</div>

i would like to transform a KTable to another KTable:

from:  
[a1, b1]  
[a2, b2]  
[a3, b1]

to:  
[b1, [a1, a3]]  
[b2, [a2]]

it seems clear to me how to do this by switching to a KStream and then back to a KTable, but then i dont know how to process deletes (tombstones). KGroupedTable would be the obvious route but strangely the selector in groupBy limits me mapping key-values instead of flatMapping (although looking at the code this restriction could be relaxed pretty easily?).

any ideas?  
thanks! best, koert
