我不熟悉颠簸转换。我想知道是否有一种方法可以对数据类型进行验证然后继续。
我正在处理一个json,以将记录插入到hbase中。从源头开始,我要为要用于行键的相同资源ID重复时间戳。 因此,我只获取第一个时间戳并与资源ID串联以创建行键。但是当记录中只有一个时间戳时,即没有列表时,我遇到了一个问题。感谢有人可以帮助我如何处理这种情况。
输入数据
{ "resource": {
"id": "200629068",
"name": "resource_name_1)",
"parent": {
"id": 200053744,
"name": "parent_name"
},
"properties": {
"AP_ifSpeed": "0",
"DisplaySpeed": "0 (NotApplicable)",
"description": "description"
}
},
"data": [
{
"metric": {
"id": "2215",
"name": "metric_name 1"
},
"timestamp": 1535064595000,
"value": 0
},
{
"metric": {
"id": "2216",
"name": "metric_name_2"
},
"timestamp": 1535064595000,
"value": 1
}
]
}
震动转换
[{
"operation": "shift",
"spec": {
"resource": {
// "id": "resource_&",
"name": "resource_&",
"id": "resource_&",
"parent": {
"id": "parent_&",
"name": "parent_&"
},
"properties": {
"*": "&"
}
},
"data": {
"*": {
"metric": {
"id": {
"*": {
"@(3,value)": "&1"
}
},
"name": {
"*": {
"@(3,value)": "&1"
}
}
},
"timestamp": "timestamp"
}
}
}
}, {
"operation": "shift",
"spec": {
"timestamp": {
// get first element from list
"0": "&1"
},
"*": "&"
}
},
{
"operation": "modify-default-beta",
"spec": {
"rowkey": "=concat(@(1,resource_id),'_',@(1,timestamp))"
}
}
]
我得到的输出
{ "resource_name" : "resource_name_1)",
"resource_id" : "200629068",
"parent_id" : 200053744,
"parent_name" : "parent_name",
"AP_ifSpeed" : "0",
"DisplaySpeed" : "0 (NotApplicable)",
"description" : "description",
"2215" : 0,
"metric_name 1" : 0,
"timestamp" : 1535064595000,
"2216" : 1,
"metric_name_2" : 1,
"rowkey" : "200629068_1535064595000"
}
当只有一个时间戳时,我得到 “ rowkey”:“ 200629068 _”
答案 0 :(得分:0)
在轮班中,即使输入数据数组中只有一个元素,也要使输出“时间戳”始终是一个数组。
"timestamp": "timestamp[]"