implemented pig equivalent in java