Given a csv file with first row which can be taken as the header, how can one load the field names dynamically in Pig using these headers? i.e.
a = LOAD '/path/to/file.csv' USING PigStorage() AS --use first row as field names
> describe a;
As this is a CSV file and you want to use first row as a header, you should use
CSVLoader() for it.It will treat first row as header. Your script will be like this.
--Register the piggybank jar REGISTER piggybank.jar define CSVLoader org.apache.pig.piggybank.storage.CSVLoader(); A = LOAD '/path/to/file.csv' using CSVLoader AS(id:int,year:chararray,total:int);