课程表

Apache Pig 基础

Apache Pig 诊断运算符

Apache Pig 分组和连接

Apache Pig 合并和拆分

Apache Pig 过滤

Apache Pig 排序

Pig Latin 内置函数

Apache Pig 其他执行模式

工具箱
速查手册

Split运算符

当前位置:免费教程 » 大数据/云 » Apache Pig

SPLIT 运算符用于将关系拆分为两个或多个关系。

语法

下面给出了 SPLIT 运算符的语法。

  1. grunt> SPLIT Relation1_name INTO Relation2_name IF (condition1), Relation2_name (condition2),

假设在HDFS目录 /pig_data/ 中有一个名为 student_details.txt 的文件,如下所示。

student_details.txt

  1. 001,Rajiv,Reddy,21,9848022337,Hyderabad
  2. 002,siddarth,Battacharya,22,9848022338,Kolkata
  3. 003,Rajesh,Khanna,22,9848022339,Delhi
  4. 004,Preethi,Agarwal,21,9848022330,Pune
  5. 005,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar
  6. 006,Archana,Mishra,23,9848022335,Chennai
  7. 007,Komal,Nayak,24,9848022334,trivendram
  8. 008,Bharathi,Nambiayar,24,9848022333,Chennai

通过关系 student_details 将此文件加载到Pig中,如下所示。

  1. student_details = LOAD 'hdfs://localhost:9000/pig_data/student_details.txt' USING PigStorage(',')
  2. as (id:int, firstname:chararray, lastname:chararray, age:int, phone:chararray, city:chararray);

现在,让我们将关系分为两个,一个列出年龄小于23岁的员工,另一个列出年龄在22到25岁之间的员工。

  1. SPLIT student_details into student_details1 if age<23, student_details2 if (22<age and age>25);

验证

使用 DUMP 操作符验证关系 student_details1 student_details2 ,如下所示。

  1. grunt> Dump student_details1;
  2.  
  3. grunt> Dump student_details2;

输出

它将产生以下输出,分别显示关系 student_details1 student_details2 的内容。

  1. grunt> Dump student_details1;
  2. (1,Rajiv,Reddy,21,9848022337,Hyderabad)
  3. (2,siddarth,Battacharya,22,9848022338,Kolkata)
  4. (3,Rajesh,Khanna,22,9848022339,Delhi)
  5. (4,Preethi,Agarwal,21,9848022330,Pune)
  6. grunt> Dump student_details2;
  7. (5,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar)
  8. (6,Archana,Mishra,23,9848022335,Chennai)
  9. (7,Komal,Nayak,24,9848022334,trivendram)
  10. (8,Bharathi,Nambiayar,24,9848022333,Chennai)
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号