使用 JOLT 在两个 "tables" 之间进行内部连接
inner join between two "tables" using JOLT
我正在尝试使用两个对象数组和“连接”将 json 文件转换为 json 文件,这是输入文件:
{
"Employee": [
{
"id": "emp_1",
"firstName": "Jose",
"lastName": "Perez",
"ssn": "ssn1",
"depId": "dep_1"
},
{
"id": "emp_2",
"firstName": "Antonio",
"lastName": "Ramirez",
"ssn": "ssn2",
"depId": "dep_2"
}
],
"Department": [
{
"id": "dep_1",
"description": "Instituto nacional de investigaciones nucleares (ININ)",
"division": "Research"
},
{
"id": "dep_2",
"description": "Instituto Mexicano de Seguro Social (IMSS)",
"division": "Healthcare"
},
{
"id": "dep_3",
"description": "Comision Nacional Bancaria y de Valores (CNBV)",
"division": "Financial"
}
]
}
这是预期的输出:
{
"Employee": [
{
"id": "emp_1",
"firstName": "Jose",
"lasttName": "Perez",
"ssn": "ssn1",
"department": "Instituto nacional de investigaciones nucleares (ININ)",
"division": "Research"
},
{
"id": "emp_2",
"firstName": "Antonio",
"lasttName": "Ramirez",
"ssn": "ssn2",
"department": "Instituto Mexicano de Seguro Social (IMSS)",
"division": "Healthcare"
}
]
}
我一直在尝试这样做,但没有得到映射,我做错了什么?
这是我的规格:
[
{
"operation": "shift",
"spec": {
"Department": {
"*": {
"@" : "Department.@id"
}
},
"Employee" : "Employee"
}
},
{
"operation": "shift",
"spec": {
"Employee": {
"*": {
"depId" : {
"*" : {
"@2" : {
"Department" : {
"&4" : "test"
}
}
}
}
}
}
}
}
]
拜托,我已经花了很多时间试图解决它,有没有人知道如何使用 Jolt 解决它:https://github.com/bazaarvoice/jolt?
检查此规范,使部门中的 id 更易于访问,然后比较值,
[
{
"operation": "shift",
"spec": {
"Employee": "Employee",
//make the dep id easier to compare
"Department": {
"*": {
"@": "Department.@(0,id)"
}
}
}
}, {
"operation": "shift",
"spec": {
"Employee": {
"*": {
"depId": {
"*": {
"@(4,Department)": {
// Compare values and move everything into the employee object
"@3": "Employee.&",
"@(&)": "Employee.&.department"
}
}
}
}
}
}
}, {
"operation": "shift",
"spec": {
"Employee": {
"*": {
"@": "Employee[]"
}
}
}
}, {
// Object cleansing
"operation": "shift",
"spec": {
"Employee": {
"*": {
"id": "Employee[].id",
"firstName": "Employee[&1].firstName",
"lastName": "Employee[&1].lastName",
"ssn": "Employee[&1].ssn",
"department": {
"description": "Employee[&2].department",
"division": "Employee[&2].division"
}
}
}
}
}
]
非常感谢@Jagadesh 的回答
我或多或少地遵循了与您相同的方法,但稍作修改:
[
{
"operation": "shift",
"spec": {
"Employee": "Employee",
"Department": {
"*": {
"@": "Department.@id"
}
}
}
},
{
"operation": "shift",
"spec": {
"Employee": {
"*": {
"depId": {
"*": {
"@(4,Department)": {
"@(&)": {
"@(0,description)": "Employee[&5].department",
"@(0,division)": "Employee[&5].division"
}
}
}
},
"@": "Employee[&]"
}
}
}
},
// just to remove depId from Employee
{
"operation": "remove",
"spec": {
"Employee": {
"*": {
"depId": ""
}
}
}
}
]
我正在尝试使用两个对象数组和“连接”将 json 文件转换为 json 文件,这是输入文件:
{
"Employee": [
{
"id": "emp_1",
"firstName": "Jose",
"lastName": "Perez",
"ssn": "ssn1",
"depId": "dep_1"
},
{
"id": "emp_2",
"firstName": "Antonio",
"lastName": "Ramirez",
"ssn": "ssn2",
"depId": "dep_2"
}
],
"Department": [
{
"id": "dep_1",
"description": "Instituto nacional de investigaciones nucleares (ININ)",
"division": "Research"
},
{
"id": "dep_2",
"description": "Instituto Mexicano de Seguro Social (IMSS)",
"division": "Healthcare"
},
{
"id": "dep_3",
"description": "Comision Nacional Bancaria y de Valores (CNBV)",
"division": "Financial"
}
]
}
这是预期的输出:
{
"Employee": [
{
"id": "emp_1",
"firstName": "Jose",
"lasttName": "Perez",
"ssn": "ssn1",
"department": "Instituto nacional de investigaciones nucleares (ININ)",
"division": "Research"
},
{
"id": "emp_2",
"firstName": "Antonio",
"lasttName": "Ramirez",
"ssn": "ssn2",
"department": "Instituto Mexicano de Seguro Social (IMSS)",
"division": "Healthcare"
}
]
}
我一直在尝试这样做,但没有得到映射,我做错了什么? 这是我的规格:
[
{
"operation": "shift",
"spec": {
"Department": {
"*": {
"@" : "Department.@id"
}
},
"Employee" : "Employee"
}
},
{
"operation": "shift",
"spec": {
"Employee": {
"*": {
"depId" : {
"*" : {
"@2" : {
"Department" : {
"&4" : "test"
}
}
}
}
}
}
}
}
]
拜托,我已经花了很多时间试图解决它,有没有人知道如何使用 Jolt 解决它:https://github.com/bazaarvoice/jolt?
检查此规范,使部门中的 id 更易于访问,然后比较值,
[
{
"operation": "shift",
"spec": {
"Employee": "Employee",
//make the dep id easier to compare
"Department": {
"*": {
"@": "Department.@(0,id)"
}
}
}
}, {
"operation": "shift",
"spec": {
"Employee": {
"*": {
"depId": {
"*": {
"@(4,Department)": {
// Compare values and move everything into the employee object
"@3": "Employee.&",
"@(&)": "Employee.&.department"
}
}
}
}
}
}
}, {
"operation": "shift",
"spec": {
"Employee": {
"*": {
"@": "Employee[]"
}
}
}
}, {
// Object cleansing
"operation": "shift",
"spec": {
"Employee": {
"*": {
"id": "Employee[].id",
"firstName": "Employee[&1].firstName",
"lastName": "Employee[&1].lastName",
"ssn": "Employee[&1].ssn",
"department": {
"description": "Employee[&2].department",
"division": "Employee[&2].division"
}
}
}
}
}
]
非常感谢@Jagadesh 的回答 我或多或少地遵循了与您相同的方法,但稍作修改:
[
{
"operation": "shift",
"spec": {
"Employee": "Employee",
"Department": {
"*": {
"@": "Department.@id"
}
}
}
},
{
"operation": "shift",
"spec": {
"Employee": {
"*": {
"depId": {
"*": {
"@(4,Department)": {
"@(&)": {
"@(0,description)": "Employee[&5].department",
"@(0,division)": "Employee[&5].division"
}
}
}
},
"@": "Employee[&]"
}
}
}
},
// just to remove depId from Employee
{
"operation": "remove",
"spec": {
"Employee": {
"*": {
"depId": ""
}
}
}
}
]