Reputation: 319
Is there any way to find the number of Fields or columns available in a relation?
For example:
a = load 'input' using PigStorage(',') as (a1,a2,a3);
b = load 'input2' using PigStorage(',') as (b1,b2,b3);
C = join a by a1, b by b1;
Now there will be six columns in the result 'c'. Is there any way to check the count of columns in the result by code.
Thanks,
Kalai
Upvotes: 1
Views: 740
Reputation: 179
PIG does not provide any intentional way of counting columns but one of the way to use the count of fields in pig is by 1st -storing the file and then counting the no of delimiters in the file.
Example:- (Delimiter used is "|")
%declare COUNT hadoop fs -cat //trihadn01/user/ykale/warranty_recs | head -1| tr '|' '\n'|wc -l
;
and then use this variable - COUNT where ever required in pig.
Note- Please do not miss the '`' symbol at the end of the statement and after the variable name (count)
Upvotes: 2