如何从地图中提取密钥? [英] How to extract keys from map?

查看:25
本文介绍了如何从地图中提取密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 map 字段中提取所有键?
我有一包元组,其中一个字段是包含 HTTP 标头(及其值)的映射.我想为 HTTP 标头创建一组所有可能的键(在我的数据集中),并计算我看到它们的次数.

How do I extract all keys from a map field?
I have a bag of tuples where one of the fields is a map that contains HTTP headers (and their values). I want to create a set of all possible keys (in my dataset) for a HTTP header and count how many times I've seen them.

理想情况下,类似于:

A = LOAD ...
B = FOREACH A GENERATE KEYS(http_headers)
C = GROUP FLATTEN(B) BY $0
D = FOREACH C GENERATE group, COUNT($0)

(没有测试但它说明了这个想法..)

(didn't test it but it illustrates the idea..)

我该怎么做这样的事情?如果我可以从 map 中提取一个 bag 密钥,它实际上可以解决它.我只是在 Piglatin 的文档中找不到任何这样的功能.

How do I do something like this? If I can extract a bag of keys from a map it would actually solve it. I just couldn't find any function like this in piglatin's documentation.

推荐答案

是的,Pig 中有一个命令可以完成此任务.

Yes there is a command in Pig to accomplish this.

示例:

/*  data  */
[a#1,b#2,c#3]
[green#sam,eggs#I,ham#am]

A = load 'data' as (M:[]);
B = foreach A generate KEYSET($0);
dump B

输出:

({(b),(c),(a)})
({(ham),(eggs),(green)})

这篇关于如何从地图中提取密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆