Apache Pig - TextLoader()


Advertisements

The Pig Latin function TextLoader() is a Load function which is used to load unstructured data in UTF-8 format.

Syntax

Given below is the syntax of TextLoader() function.

grunt> TextLoader()

Example

Let us assume there is a file with named stu_data.txt in the HDFS directory named /data/ as shown below.

001,Rajiv_Reddy,21,Hyderabad 
002,siddarth_Battacharya,22,Kolkata 
003,Rajesh_Khanna,22,Delhi 
004,Preethi_Agarwal,21,Pune 
005,Trupthi_Mohanthy,23,Bhuwaneshwar 
006,Archana_Mishra,23,Chennai 
007,Komal_Nayak,24,trivendram 
008,Bharathi_Nambiayar,24,Chennai

Now let us load the above file using the TextLoader() function.

grunt> details = LOAD 'hdfs://localhost:9000/pig_data/stu_data.txt' USING TextLoader();

You can verify the loaded data using the Dump operator.

grunt> dump details;
   
(001,Rajiv_Reddy,21,Hyderabad) 
(002,siddarth_Battacharya,22,Kolkata) 
(003,Rajesh_Khanna,22,Delhi) 
(004,Preethi_Agarwal,21,Pune) 
(005,Trupthi_Mohanthy,23,Bhuwaneshwar) 
(006,Archana_Mishra,23,Chennai) 
(007,Komal_Nayak,24,trivendram) 
(008,Bharathi_Nambiayar,24,Chennai)
apache_pig_load_store_functions.htm
Advertisements