gpt4 book ai didi

apache-pig - Pig Latin 在每一行中使用文件中的第一个值

转载 作者:行者123 更新时间:2023-12-01 12:45:13 27 4
gpt4 key购买 nike

我有很多文件,所有文件都采用相同的结构。每个文件的第一行是一个key(在这个例子中是电影的key),后面是user-id、rating和date的记录。

示例文件 1:

1:  
1488844,3,2005-09-06
822109,5,2005-05-13
885013,4,2005-10-19

示例文件 2:

2:  
2059652,4,2005-09-05
1666394,3,2005-04-19
1759415,4,2005-04-22
1959936,5,2005-11-21

为了处理 pig 中的数据并获得每部电影或每年的最高收视率和平均收视率,我需要这样的东西:

1,1488844,3,2005-09-06  
1,822109,5,2005-05-13
1,885013,4,2005-10-19
2,2059652,4,2005-09-05
2,1666394,3,2005-04-19
2,1759415,4,2005-04-22
2,1959936,5,2005-11-21

我该如何管理它?谢谢!!!

最佳答案

尝试这样的事情:

inputs = LOAD 'input_path/*' using PigStorage('-tagsource');
grouped = GROUP inputs by $0;
processed = FOREACH grouped {
key_row = FILTER inputs BY [regexp expression for the key row, or some simple string expression];
without_key_row = FILTER input BY [the opposite expression];
GENERATE
(chararray)key_row,
FLATTEN(without_key_row);
}

关于apache-pig - Pig Latin 在每一行中使用文件中的第一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20799579/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com