在Pig中将多个地图组合在一起

编程入门 行业动态 更新时间:2024-10-28 19:22:16
本文介绍了在Pig中将多个地图组合在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是第一次使用猪.我已经找到了想要的答案,但嵌套格式很奇怪:

I am using pig for the first time. I've gotten to the point where I have exactly the answer I want, but in a weirdly nested format:

{(price,49),(manages,"1d74426f-2b0a-4777-ac1b-042268cab09c")}

我希望输出为单个地图,没有任何包装:

I'd like the output to be a single map, without any wrapping:

[price#49, manages#"1d74426f-2b0a-4777-ac1b-042268cab09c"]

我已经设法使用TOMAP来解决这个问题,但是我不知道如何合并和展平它.

I've managed to use TOMAP to get this far, but I can't figure out how to merge and flatten it away.

{([price_specification#{"amount":49,"currency":"USD"}]),([manages#"newest-nodes/1d74426f-2b0a-4777-ac1b-042268cab09c"])}

我应该怎么做?

推荐答案

不幸的是,没有内置函数可以为您执行此操作.您必须编写自己的UDF.幸运的是,这很简单.

Unfortunately, there are no built-in functions to do this for you. You'll have to write your own UDF. Fortunately, this is a simple one.

exec方法将类似于:

public Map<String, Object> exec(Tuple input) { Map<String, Object> m = new HashMap<String, Object>(); for (int i = 0; i < input.size(); i++) m.putAll((Map<String, Object>) input.get(i)); return m; }

UDF可以使用任意数量的映射作为参数.

The UDF could take any number of maps as arguments.

请注意,如果两个或两个以上的地图共享一个密钥,那么最后遇到的一个将被保留,另一个将被覆盖.

Note that if two or more maps share a key, then the final one encountered will be the one that is kept and the others get overwritten.

更多推荐

在Pig中将多个地图组合在一起

本文发布于:2023-06-09 04:15:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/595042.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   多个   中将   地图   Pig

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!