properly handle missing columns in groupBy