我对jolt转换还不熟悉。我想知道是否有一种方法可以对数据类型进行验证,然后继续。
我正在处理一个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
}
]
}
Jolt变换
[{
"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_”
发布于 2018-08-31 06:23:05
在你的班次中,使输出的“时间戳”始终是一个数组,即使传入的数据数组中只有一个元素。
"timestamp": "timestamp[]"
https://stackoverflow.com/questions/52060629
复制相似问题