Search code examples
apache-pig

I have 50 fields, Is there any option in pig to print first 40 field in Apache Pig? I require something like range $0-$39


I have 50 fields, Is there any option in pig to print first 40 fields? I require something like range $0-$39. I don’t want to specify each and every field like $0, $1,$2 etc

Giving every column when the number of columns is less is acceptable but when there are a huge number of columns what is the case?


Solution

  • You can use the .. notation.

    First 40 fields

    B = FOREACH A GENERATE $0..$39;
    

    All fields

    B = FOREACH A GENERATE $0..;
    

    Multiple ranges,for example first 10,15-20,25-50

    B = FOREACH A GENERATE $0..$9,$14..$19,$24..;
    

    Random fields 22,33-44,46

    B = FOREACH A GENERATE $21,$32..$43,$45;