【问题标题】:Pig: Accessing inner tuples' fields for filteringPig:访问内部元组的字段以进行过滤
【发布时间】:2014-06-21 00:13:03
【问题描述】:

我有这样的a custom Pig loader

A = LOAD 'myfile' USING myudf_loader()

A 包含:

((key1, val1), (key2, val2), (key3, val3), ...)

A 有一个外部元组,其中包含存储在内部元组中的键值对。

我没有使用地图,因为地图需要 key values within a relation must be unique。我拥有的键不一定是唯一的。

键是chararrays,值可以是chararraysintsfloats

我想访问A 的内部元组,以及这些元组中的(键、值)对。

例如,我想FILTERA 的键,这样剩下的字段就只有key = "city"value = "New York City"

示例输入:

DUMP A;
(("city", "New York City"), ("city", "Boston"),
 ("city", "Washington, D.C."), ("non-city-key", "non-city-value"),
 ("city", "New York City"), ("non-city-key", "non-city-value"))

过滤的示例输出,存储到B

DUMP B;
("city", "New York City")
("city", "New York City")

【问题讨论】:

    标签: hadoop mapreduce apache-pig


    【解决方案1】:

    我没有完整的猪拉丁文脚本。

    但是你可以使用下面的想法来实现

    grouped_records = GROUP records By Key;
    
    filtered_records = FILTER grouped_records By group='CITY'
    
    Dump filtered_records
    

    干杯 唠叨

    【讨论】:

    • 谢谢,但这个答案没有显示如何访问内部元组。就像 ((key1, val1), (key2, val2), ..., (keyn, valn)) 中的 key1。
    猜你喜欢
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多