- 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 運算子
- 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 - 分割運算子
SPLIT 運算子用於將關係拆分為兩個或多個關係。
語法
以下是 SPLIT 運算子的語法。
grunt> SPLIT Relation1_name INTO Relation2_name IF (condition1), Relation2_name (condition2),
示例
假設我們在 HDFS 目錄 /pig_data/ 中有一個名為 student_details.txt 的檔案,如下所示。
student_details.txt
001,Rajiv,Reddy,21,9848022337,Hyderabad 002,siddarth,Battacharya,22,9848022338,Kolkata 003,Rajesh,Khanna,22,9848022339,Delhi 004,Preethi,Agarwal,21,9848022330,Pune 005,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar 006,Archana,Mishra,23,9848022335,Chennai 007,Komal,Nayak,24,9848022334,trivendram 008,Bharathi,Nambiayar,24,9848022333,Chennai
我們已將此檔案使用關係名稱 student_details 載入到 Pig 中,如下所示。
student_details = LOAD 'hdfs://:9000/pig_data/student_details.txt' USING PigStorage(',')
as (id:int, firstname:chararray, lastname:chararray, age:int, phone:chararray, city:chararray);
現在讓我們將關係分成兩個,一個列出年齡小於 23 歲的員工,另一個列出年齡在 22 到 25 歲之間的員工。
SPLIT student_details into student_details1 if age<23, student_details2 if (22<age and age>25);
驗證
使用 DUMP 運算子驗證關係 student_details1 和 student_details2,如下所示。
grunt> Dump student_details1; grunt> Dump student_details2;
輸出
它將生成以下輸出,分別顯示關係 student_details1 和 student_details2 的內容。
grunt> Dump student_details1; (1,Rajiv,Reddy,21,9848022337,Hyderabad) (2,siddarth,Battacharya,22,9848022338,Kolkata) (3,Rajesh,Khanna,22,9848022339,Delhi) (4,Preethi,Agarwal,21,9848022330,Pune) grunt> Dump student_details2; (5,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar) (6,Archana,Mishra,23,9848022335,Chennai) (7,Komal,Nayak,24,9848022334,trivendram) (8,Bharathi,Nambiayar,24,9848022333,Chennai)
廣告