我有三种数据类型。。。
1) 基本数据2)数据目录1 3)数据目录2
基本数据是格式非常好的json。。例如:
{"id1":"foo", "id2":"bar" ,type:"type1"}
{"id1":"foo", "id2":"bar" ,type:"type2"}
数据目录1
1 foo
2 bar
3 foobar
....
数据目录2
-1 foo
-2 bar
-3 foobar
... and so on
现在,我想要的是。。如果数据类型为1
然后从数据目录1中读取id1,从数据目录2中读取id2,并分配该整数id。。如果数据类型为2。。然后从数据目录2中读取id1。。id2来自数据\u dict1。。并分配相应的ID。。例如:
{"id1":1, "id2":2 ,type:"type1"}
{"id1":-1, "id2":-2 ,type:"type2"}
以此类推。。我在Pig里怎么做?
1条答案
按热度按时间niknxzdl1#
注意:上面的示例中的内容不是有效的json
type
密钥未被引用。假设pig0.10及更高版本,有内置的jsonloader,您可以将一个模式传递给它并用它加载
然后把听写器装进去
然后根据
type
价值type1_joined = JOIN type1 BY id1, dict_1 BY key;
type1_joined = FOREACH type1_joined GENERATE type1::id1 AS id1, type1::id2 AS id2, type1::type AS type, dict_1::id AS id;
type2_joined = JOIN type2 BY id2, dict_2 BY key;
type2_joined = FOREACH type2_joined GENERATE type2::id1 AS id1, type2::id2 AS id2, type2::type AS type, dict_2::id AS id;
final_data = UNION type1_joined, type2_joined;
DUMP final_data;
(foo,bar,type2,-2)
(foo,bar,type1,1)