You could use ChainMapper and ChainReducer API in hadoop.