pig,把一个数组变成多条记录
pig, turn an array into multiple records
我的记录中有一个数组:
{
"resource":"rest-api-v1",
"accessControlList":[
{
"methods":{
"methodTypes":[
"DELETE"
]
},
"Users":[
"user2"
]
},
{
"methods":{
"methodTypes":[
"CREATE"
]
},
"Users":[
"user1",
"user2"
]
}
]
}
在accessControlList数组中,数组中有2个元素。
我怎样才能把这 1 记录变成 2?
我希望结果看起来像:
resource: rest-api-v1
accessControl:
{
"methods":{
"methodTypes":[
"DELETE"
]
},
"Users":[
"user2"
]
}
和
resource: rest-api-v1
accessControl:
{
"methods":{
"methodTypes":[
"DELETE"
]
},
"Users":[
"user2"
]
}
在 hive 中我可以做一个 LATERAL VIEW EXPLODE(),但是在 pig 中我不知道怎么做。
猪 FLATTEN 运算符可以满足您的需求:https://pig.apache.org/docs/r0.16.0/basic.html#flatten
我的记录中有一个数组:
{
"resource":"rest-api-v1",
"accessControlList":[
{
"methods":{
"methodTypes":[
"DELETE"
]
},
"Users":[
"user2"
]
},
{
"methods":{
"methodTypes":[
"CREATE"
]
},
"Users":[
"user1",
"user2"
]
}
]
}
在accessControlList数组中,数组中有2个元素。 我怎样才能把这 1 记录变成 2? 我希望结果看起来像:
resource: rest-api-v1
accessControl:
{
"methods":{
"methodTypes":[
"DELETE"
]
},
"Users":[
"user2"
]
}
和
resource: rest-api-v1
accessControl:
{
"methods":{
"methodTypes":[
"DELETE"
]
},
"Users":[
"user2"
]
}
在 hive 中我可以做一个 LATERAL VIEW EXPLODE(),但是在 pig 中我不知道怎么做。
猪 FLATTEN 运算符可以满足您的需求:https://pig.apache.org/docs/r0.16.0/basic.html#flatten