返回介绍

Pig Cross 运算符

发布于 2024-06-23 16:54:49 字数 5681 浏览 0 评论 0 收藏 0

Cross 运算符

CROSS操作符计算两个或两个以上关系的向量叉积。本章举例说明如何在Pig Latin中使用Cross运算符。
语法
下面给出的是CROSS运算符的语法。

  1. grunt> Relation3_name = CROSS Relation1_name, Relation2_name;

假设我们在HDFS的/pig_data/目录中有两个文件,即customers.txt和orders.txt,如下所示。

  1. 1,Ramesh,32,Ahmedabad,2020.00
  2. 2,Khilan,25,Delhi,1500.00
  3. 3,kaushik,23,Kota,2020.00
  4. 4,Chaitali,25,Mumbai,6500.00
  5. 5,Hardik,27,Bhopal,8500.00
  6. 6,Komal,22,MP,4500.00
  7. 7,Muffy,24,Indore,10000.00
  1. 102,2019-10-08 00:00:00,3,3000
  2. 100,2019-10-08 00:00:00,3,1500
  3. 101,2019-11-20 00:00:00,2,1560
  4. 103,2018-05-20 00:00:00,4,2060

我们已将这两个文件与客户和订单的关系加载到Pig中,如下所示。

  1. grunt> customers = LOAD 'hdfs://localhost:9000/pig_data/customers.txt' USING PigStorage(',')
  2. as (id:int, name:chararray, age:int, address:chararray, salary:int);
  3. grunt> orders = LOAD 'hdfs://localhost:9000/pig_data/orders.txt' USING PigStorage(',')
  4. as (oid:int, date:chararray, customer_id:int, amount:int);

现在让我们使用这两个关系上的cross 运算符获得这两个关系的向量叉积,如下所示。

  1. grunt> cross_data = CROSS customers, orders;

验证
使用DUMP运算符验证关系cross_data,如下所示。

  1. grunt> Dump cross_data;

输出
它将产生以下输出,显示关系cross_data的内容。

  1. (7,Muffy,24,Indore,10000,103,2018-05-20 00:00:00,4,2060)
  2. (7,Muffy,24,Indore,10000,101,2019-11-20 00:00:00,2,1560)
  3. (7,Muffy,24,Indore,10000,100,2019-10-08 00:00:00,3,1500)
  4. (7,Muffy,24,Indore,10000,102,2019-10-08 00:00:00,3,3000)
  5. (6,Komal,22,MP,4500,103,2018-05-20 00:00:00,4,2060)
  6. (6,Komal,22,MP,4500,101,2019-11-20 00:00:00,2,1560)
  7. (6,Komal,22,MP,4500,100,2019-10-08 00:00:00,3,1500)
  8. (6,Komal,22,MP,4500,102,2019-10-08 00:00:00,3,3000)
  9. (5,Hardik,27,Bhopal,8500,103,2018-05-20 00:00:00,4,2060)
  10. (5,Hardik,27,Bhopal,8500,101,2019-11-20 00:00:00,2,1560)
  11. (5,Hardik,27,Bhopal,8500,100,2019-10-08 00:00:00,3,1500)
  12. (5,Hardik,27,Bhopal,8500,102,2019-10-08 00:00:00,3,3000)
  13. (4,Chaitali,25,Mumbai,6500,103,2018-05-20 00:00:00,4,2060)
  14. (4,Chaitali,25,Mumbai,6500,101,2019-20 00:00:00,4,2060)
  15. (2,Khilan,25,Delhi,1500,101,2019-11-20 00:00:00,2,1560)
  16. (2,Khilan,25,Delhi,1500,100,2019-10-08 00:00:00,3,1500)
  17. (2,Khilan,25,Delhi,1500,102,2019-10-08 00:00:00,3,3000)
  18. (1,Ramesh,32,Ahmedabad,2020,103,2018-05-20 00:00:00,4,2060)
  19. (1,Ramesh,32,Ahmedabad,2020,101,2019-11-20 00:00:00,2,1560)
  20. (1,Ramesh,32,Ahmedabad,2020,100,2019-10-08 00:00:00,3,1500)
  21. (1,Ramesh,32,Ahmedabad,2020,102,2019-10-08 00:00:00,3,3000)-11-20 00:00:00,2,1560)
  22. (4,Chaitali,25,Mumbai,6500,100,2019-10-08 00:00:00,3,1500)
  23. (4,Chaitali,25,Mumbai,6500,102,2019-10-08 00:00:00,3,3000)
  24. (3,kaushik,23,Kota,2020,103,2018-05-20 00:00:00,4,2060)
  25. (3,kaushik,23,Kota,2020,101,2019-11-20 00:00:00,2,1560)
  26. (3,kaushik,23,Kota,2020,100,2019-10-08 00:00:00,3,1500)
  27. (3,kaushik,23,Kota,2020,102,2019-10-08 00:00:00,3,3000)
  28. (2,Khilan,25,Delhi,1500,103,2018-05-20 00:00:00,4,2060)
  29. (2,Khilan,25,Delhi,1500,101,2019-11-20 00:00:00,2,1560)
  30. (2,Khilan,25,Delhi,1500,100,2019-10-08 00:00:00,3,1500)
  31. (2,Khilan,25,Delhi,1500,102,2019-10-08 00:00:00,3,3000)
  32. (1,Ramesh,32,Ahmedabad,2020,103,2018-05-20 00:00:00,4,2060)
  33. (1,Ramesh,32,Ahmedabad,2020,101,2019-11-20 00:00:00,2,1560)
  34. (1,Ramesh,32,Ahmedabad,2020,100,2019-10-08 00:00:00,3,1500)
  35. (1,Ramesh,32,Ahmedabad,2020,102,2019-10-08 00:00:00,3,3000)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文