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.
id,year,total
1,1999,190
2,1998,20
a = LOAD '/path/to/file.csv' USING PigStorage() AS --use first row as field names
> describe a;
> id:bytearray,year:bytearray,total:bytearray
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With