- Apache Pig 教程
- Apache Pig - 首頁
- Apache Pig 簡介
- Apache Pig - 概述
- Apache Pig - 架構
- Apache Pig 環境
- Apache Pig - 安裝
- Apache Pig - 執行
- Apache Pig - Grunt Shell
- Pig Latin
- Pig Latin - 基礎
- 載入 & 儲存運算子
- Apache Pig - 讀取資料
- Apache Pig - 儲存資料
- 診斷運算子
- Apache Pig - 診斷運算子
- Apache Pig - Describe 運算子
- Apache Pig - Explain 運算子
- Apache Pig - Illustrate 運算子
- 分組 & 連線
- Apache Pig - Group 運算子
- Apache Pig - Cogroup 運算子
- Apache Pig - Join 運算子
- Apache Pig - Cross 運算子
- Pig Latin 內建函式
- Apache Pig - Eval 函式
- 載入 & 儲存函式
- Apache Pig - Bag & Tuple 函式
- Apache Pig - 字串函式
- Apache Pig - 日期時間函式
- Apache Pig - 數學函式
- Apache Pig 有用資源
- Apache Pig - 快速指南
- Apache Pig - 有用資源
- Apache Pig - 討論
Apache Pig - BinStorage()
BinStorage() 函式用於使用機器可讀格式載入和儲存資料到 Pig 中。Pig 中的 BinStorge() 通常用於儲存 MapReduce 作業之間生成的臨時資料。它支援多個位置作為輸入。
語法
下面是 BinStorage() 函式的語法。
grunt> BinStorage();
示例
假設我們在 HDFS 目錄 /pig_data/ 中有一個名為 stu_data.txt 的檔案,如下所示。
Stu_data.txt
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
讓我們將此資料載入到 Pig 中的一個關係中,如下所示。
grunt> student_details = LOAD 'hdfs://:9000/pig_data/stu_data.txt' USING PigStorage(',')
as (id:int, firstname:chararray, age:int, city:chararray);
現在,我們可以使用 BinStorage() 函式將此關係儲存到名為 /pig_data/ 的 HDFS 目錄中。
grunt> STORE student_details INTO 'hdfs://:9000/pig_Output/mydata' USING BinStorage();
執行上述語句後,關係將儲存在給定的 HDFS 目錄中。您可以使用 HDFS 的 ls 命令檢視它,如下所示。
$ hdfs dfs -ls hdfs://:9000/pig_Output/mydata/ Found 2 items -rw-r--r-- 1 Hadoop supergroup 0 2015-10-26 16:58 hdfs://:9000/pig_Output/mydata/_SUCCESS -rw-r--r-- 1 Hadoop supergroup 372 2015-10-26 16:58 hdfs://:9000/pig_Output/mydata/part-m-00000
現在,從檔案 part-m-00000 載入資料。
grunt> result = LOAD 'hdfs://:9000/pig_Output/b/part-m-00000' USING BinStorage();
驗證關係的內容,如下所示
grunt> Dump result; (1,Rajiv_Reddy,21,Hyderabad) (2,siddarth_Battacharya,22,Kolkata) (3,Rajesh_Khanna,22,Delhi) (4,Preethi_Agarwal,21,Pune) (5,Trupthi_Mohanthy,23,Bhuwaneshwar) (6,Archana_Mishra,23,Chennai) (7,Komal_Nayak,24,trivendram) (8,Bharathi_Nambiayar,24,Chennai)
apache_pig_load_store_functions.htm
廣告