Add check whether group is empty in scala reduce operator

This fixes #434