1
次の豚のコードからわかるように、私はAttr1とAttr2の一連のステートメントを繰り返しています。関数でそれを抽出する方法はありますか?コードサンプルが本当に役に立ちます。豚のスクリプト関数の質問
Attr1ValidRecs = FILTER BaseRecs BY Attr1 IS NOT NULL;
Attr1ValidRecs_all = GROUP Attr1ValidRecs ALL;
Attr1Count = FOREACH Attr1ValidRecs_all GENERATE COUNT(Attr1ValidRecs);
Attr1CountStr = FOREACH Attr1Count GENERATE CONCAT('Recs with Attr1 not null : ',(chararray)$0);
Attr1BaseCross = CROSS BaseRecsCount,Attr1Count;
Attr1BaseRatio = FOREACH Attr1BaseCross GENERATE CONCAT('Ratio of Not Null Attr1 to Total Base Recs: ',(chararray)((double)$1/(double)$0));
Attr2ValidRecs = FILTER BaseRecs BY Attr2 IS NOT NULL;
Attr2ValidRecs_all = GROUP Attr2ValidRecs ALL;
Attr2Count = FOREACH Attr2ValidRecs_all GENERATE COUNT(Attr2ValidRecs);
Attr2CountStr = FOREACH Attr2Count GENERATE CONCAT('Recs with Attr2 not null : ',(chararray)$0);
Attr2BaseCross = CROSS BaseRecsCount,Attr2Count;
Attr2BaseRatio = FOREACH Attr2BaseCross GENERATE CONCAT('Ratio of Not Null Attr2 to Total Base Recs:
',(chararray)((double)$1/(double)$0));