- Apache Pig 教程
- Apache Pig - 首頁
- Apache Pig 簡介
- Apache Pig - 概述
- Apache Pig - 架構
- Apache Pig 環境
- Apache Pig - 安裝
- Apache Pig - 執行
- Apache Pig - Grunt Shell
- Pig Latin
- Pig Latin - 基礎
- LOAD & STORE 運算子
- 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 函式
- LOAD & STORE 函式
- Apache Pig - Bag & Tuple 函式
- Apache Pig - 字串函式
- Apache Pig - 日期時間函式
- Apache Pig - 數學函式
- Apache Pig 有用資源
- Apache Pig - 快速指南
- Apache Pig - 有用資源
- Apache Pig - 討論
Apache Pig - LIMIT 運算子
LIMIT 運算子用於從關係中獲取有限數量的元組。
語法
以下是 LIMIT 運算子的語法。
grunt> Result = LIMIT Relation_name required number of tuples;
示例
假設我們在 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 中,如下所示。
grunt> 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);
現在,讓我們根據學生的年齡按降序對關係進行排序,並使用 ORDER BY 運算子將其儲存到另一個名為 limit_data 的關係中,如下所示。
grunt> limit_data = LIMIT student_details 4;
驗證
使用 DUMP 運算子驗證關係 limit_data,如下所示。
grunt> Dump limit_data;
輸出
它將產生以下輸出,顯示關係 limit_data 的內容,如下所示。
(1,Rajiv,Reddy,21,9848022337,Hyderabad) (2,siddarth,Battacharya,22,9848022338,Kolkata) (3,Rajesh,Khanna,22,9848022339,Delhi) (4,Preethi,Agarwal,21,9848022330,Pune)
廣告