99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

Apache Pig 運(yùn)行腳本

2018-01-04 16:12 更新

在本章中,我們將了解如何以批處理模式運(yùn)行Apache Pig腳本。

Pig腳本中的注釋

在將腳本寫入文件時(shí),我們可以在其中包含注釋,如下所示。

多行注釋

我們將用'/*'開始多行注釋,以'*/'結(jié)束。

/* These are the multi-line comments 
  In the pig script */ 

單行注釋

我們將用“--"開始單行注釋。

--we can write single line comments like this.

在批處理模式下執(zhí)行Pig腳本

在以批處理方式執(zhí)行Apache Pig語句時(shí),請(qǐng)按照以下步驟操作。

步驟1

將所有需要的Pig Latin語句寫在單個(gè)文件中。我們可以將所有Pig Latin語句和命令寫入單個(gè)文件,并將其另存為 .pig 文件。

步驟2

執(zhí)行Apache Pig腳本。你可以從shell(Linux)執(zhí)行Pig腳本,如下所示。

Local模式MapReduce模式

$ pig -x local Sample_script.pig

$ pig -x mapreduce Sample_script.pig

你可以使用exec命令從Grunt shell執(zhí)行它,如下所示。

grunt> exec /sample_script.pig

從HDFS執(zhí)行Pig腳本

我們還可以執(zhí)行駐留在HDFS中的Pig腳本。假設(shè)在名為 /pig_data/ 的HDFS目錄中有名為 Sample_script.pig 的Pig腳本。我們可以執(zhí)行它如下所示。

$ pig -x mapreduce hdfs://localhost:9000/pig_data/Sample_script.pig 

假設(shè)在HDFS中有一個(gè)具有以下內(nèi)容的文件 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

我們還在同一個(gè)HDFS目錄中有一個(gè)名為 sample_script.pig 的示例腳本。此文件包含對(duì)student關(guān)系執(zhí)行操作和轉(zhuǎn)換的語句,如下所示。

student = LOAD 'hdfs://localhost:9000/pig_data/student_details.txt' USING PigStorage(',')
   as (id:int, firstname:chararray, lastname:chararray, phone:chararray, city:chararray);
	
student_order = ORDER student BY age DESC;
  
student_limit = LIMIT student_order 4;
  
Dump student_limit;
  • 腳本的第一個(gè)語句會(huì)將名為 student_details.txt 的文件中的數(shù)據(jù)加載為名為student的關(guān)系。

  • 腳本的第二個(gè)語句將根據(jù)年齡以降序排列關(guān)系的元組,并將其存儲(chǔ)為 student_order

  • 腳本的第三個(gè)語句會(huì)將 student_order 的前4個(gè)元組存儲(chǔ)為 student_limit 。

  • 最后,第四個(gè)語句將轉(zhuǎn)儲(chǔ)關(guān)系 student_limit 的內(nèi)容。

現(xiàn)在,執(zhí)行 sample_script.pig ,如下所示。

$./pig -x mapreduce hdfs://localhost:9000/pig_data/sample_script.pig

Apache Pig被執(zhí)行,并提供具有以下內(nèi)容的輸出。

(7,Komal,Nayak,24,9848022334,trivendram)
(8,Bharathi,Nambiayar,24,9848022333,Chennai) 
(5,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar) 
(6,Archana,Mishra,23,9848022335,Chennai)
2015-10-19 10:31:27,446 [main] INFO  org.apache.pig.Main - Pig script completed in 12
minutes, 32 seconds and 751 milliseconds (752751 ms)


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)