pig tutorial - apache pig tutorial - Apache Pig - Bin Storage - pig latin - apache pig - pig hadoop

What is BinStorage() in Apache Pig ?

  • The BinStorage() function is used to load and store the data into Pig using machine readable format.
  • BinStorge() in Pig is generally used to store temporary data generated between the MapReduce jobs.
  • It supports multiple locations as input.
  • Pig uses BinStorage to load and store the temporary data that is generated between multiple MapReduce.
  • BinStorage works with data that is represented on disk in machine-readable format. BinStorage does NOT support compression.
  • BinStorage supports multiple locations (files, directories, globs) as input.


grunt> BinStorage();


  • Ensure that we have a file named wikitechy_employee_data.txt in the HDFS directory /pig_data/ as shown below.


  • Now let us load this data into Pig into a relation as given below
grunt> employee_details = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_employee_data.txt' USING PigStorage(',')
   as (id:int, firstname:chararray, age:int, city:chararray);
  • You can store this relation into the HDFS directory named /pig_data/ using the BinStorage() function.
grunt> STORE employee_details INTO 'hdfs://localhost:9000/pig_Output/mydata' USING BinStorage();
  • After executing the above statement, the relation is stored in the given HDFS directory.
  • You can see it using the HDFS ls command as given below.
$ hdfs dfs -ls hdfs://localhost:9000/pig_Output/mydata/
Found 2 items 
-rw-r--r--   1 Hadoop supergroup       0 2017-10-26 16:58

-rw-r--r--   1 Hadoop supergroup        372 2017-10-26 16:58
  • Currently, load the data from the file part-m-00000.
grunt> result = LOAD 'hdfs://localhost:9000/pig_Output/b/part-m-00000' USING BinStorage();
  • Now verify the contents of the relation as given below,
grunt> Dump result; 

Related Searches to Apache Pig - BinStorage

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.