我是第一次使用猪.我已经找到了想要的答案,但嵌套格式很奇怪:
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中将多个地图组合在一起
发布评论