【问题标题】:Group by in Pig latin and stream for each key在 Pig latin 中分组并为每个键流式传输
【发布时间】:2013-11-05 11:43:34
【问题描述】:

我有这种格式的数据:student_id, course_id,grade,other_information。这适用于大量学生,比如数十亿。我编写了一个 perl 脚本来处理学生的数据。于是想到了使用 hadoop 框架,通过将每个学生的数据流式传输到 perl 脚本来加速这个过程。

这就是我的做法:

student_data = LOAD 'source' using PigStorage('\t') As (stud_id:string,...)
grp_student = group student_data by stud_id;
final_data = foreach grp_student {
    flat_data = flatten(grp_student)
    each_stud_data = generate flat_data;
    result = STREAM each_stud_data THROUGH 'some perl script';
}

store final_data into '/some_location';

问题:我收到此错误Syntax error, unexpected symbol at or near 'flatten'。试图谷歌但徒劳无功。有人可以帮忙吗?

【问题讨论】:

    标签: hadoop mapreduce apache-pig


    【解决方案1】:

    一些提示:嵌套的 foreach 中不允许展平。 generate 必须是最后一条语句。

    关于Stream 命令Pig docs

    About Data Guarantees
    Data guarantees are determined based on the position of the streaming operator in the Pig script.
    
    [...]
    Grouped data – The data for the same grouped key is guaranteed to be provided to the streaming application contiguously
    [...]
    

    因此,如果您调整脚本以使其能够处理连续获取组键的所有数据这一事实,那么它可能会成功。

    student_data = LOAD 'source' using PigStorage('\t') As (stud_id:string,...);
    grp_student = GROUP student_data BY stud_id;
    flat_data = FOREACH grp_student GENERATE FLATTEN(student_data);
    result = STREAM flat_data THROUGH 'some perl script';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多