Apache Pig脚本注释和运行是什么
Admin 2022-09-30 群英技术资讯 1109 次浏览
Pig脚本中的注释
在将脚本写入文件时,我们可以在其中包含注释,如下所示。
我们将用'/*'开始多行注释,以'*/'结束。
/* These are the multi-line comments In the pig script */
我们将用“--"开始单行注释。
--we can write single line comments like this.
在以批处理方式执行Apache Pig语句时,请按照以下步骤操作。
将所有需要的Pig Latin语句写在单个文件中。我们可以将所有Pig Latin语句和命令写入单个文件,并将其另存为 .pig 文件。
执行Apache Pig脚本。你可以从shell(Linux)执行Pig脚本,如下所示。
Local模式 | MapReduce模式 |
---|---|
$ pig -x local Sample_script.pig |
$ pig -x mapreduce Sample_script.pig |
你可以使用exec命令从Grunt shell执行它,如下所示。
grunt> exec /sample_script.pig
我们还可以执行驻留在HDFS中的Pig脚本。假设在名为 /pig_data/ 的HDFS目录中有名为 Sample_script.pig 的Pig脚本。我们可以执行它如下所示。
$ pig -x mapreduce hdfs://localhost:9000/pig_data/Sample_script.pig
假设在HDFS中有一个具有以下内容的文件 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
我们还在同一个HDFS目录中有一个名为 sample_script.pig 的示例脚本。此文件包含对student关系执行操作和转换的语句,如下所示。
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;
脚本的第一个语句会将名为 student_details.txt 的文件中的数据加载为名为student的关系。
脚本的第二个语句将根据年龄以降序排列关系的元组,并将其存储为 student_order 。
脚本的第三个语句会将 student_order 的前4个元组存储为 student_limit 。
最后,第四个语句将转储关系 student_limit 的内容。
现在,执行 sample_script.pig ,如下所示。
$./pig -x mapreduce hdfs://localhost:9000/pig_data/sample_script.pig
Apache Pig被执行,并提供具有以下内容的输出。
(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)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
COGROUP 运算符的运作方式与 GROUP 运算符相同。两个运算符之间的唯一区别是 group 运算符通常用于一个关系,而 cogroup 运算符用于涉及两个或多个关系的语句。
Load 语句会简单地将数据加载到Apache Pig中的指定关系中。要验证Load语句的执行,必须使用Diagnostic运算符。Pig Latin提供四种不同类型的诊断运算符: Dump运算符、Describe运算符、Explanation运算符、Illustration运算符
SPLIT 运算符用于将关系拆分为两个或多个关系。语法下面给出了 SPLIT 运算符的语法。grunt> SPLIT Relation1_name INTO Relation2_name IF (condition1), Relation2_name (condition2)
explain 运算符用于显示关系的逻辑,物理和MapReduce执行计划。语法下面给出了 explain 运算符的语法。grunt> explain Relation_name;例假设在HDFS中有一个包含以下内容的文件 student_data.txt 。
Hadoop写文件的实现及要点有哪些?1.客户端将文件写入本地磁盘的 HDFS Client 文件中;2.当临时文件大小达到一个 block 大小时,HDFS client 通知 NameNode,申请写入文件;3.NameNode 在 HDFS 的文件系统中创建一_来自Hadoop 教程,w3cschool编程狮。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008