Also, one more small thing: an array cannot be used in a group by, so no need to call wrapGroupByExpression(arrayExpression), but instead you can just return arrayExpression