Issue with groupBy+flatMap query