I was wondering if it is possible to do a jolt transform for below use case
Person {
String id;
}
Property {
Id
name
area
address
}
Feature{
String featureId;
}
Basically we have Person having multiple properties and features. We want to reverse map in such a way using jolt transform that we want per Property list of all Person grouped by feature.
Input is:
[
{
personId: "personId1",
properties: [{id: 1, name: "property1", area: "abc"}, {id: 2, name: "property2", area: "def"}],
features: [{featureId: "feature1"}, {featureId: "feature2"}, {featureId: "feature3"}}]
},
{
personId: "personId2",
properties: [{id: 1, name: "property1", area: "abc"}, {id: 3, name: "property3"}],
features: [{featureId: "feature1"}, {featureId: "feature3"}, {featureId: "feature5"}}]
}
]
Output is expected as:
[
{
id: 1,
name: "property1",
area: "abc",
featureMap: [
{
featureId: "feature1",
persons: [personId1, personId2]
},
{
featureId: "feature2",
persons: [personId1]
},
{
featureId: "feature3",
persons: [personId1, personId2]
},
{
featureId: "feature5",
persons: [personId2]
}]
},
{
id: 2,
name: "property2",
area: "def",
featureMap: [
{
featureId: "feature1",
persons: [personId1]
},
{
featureId: "feature2",
persons: [personId1]
},
{
featureId: "feature3",
persons: [personId1]
}]
},
{
id: 3,
name: "property3",
featureMap: [
{
featureId: "feature1",
persons: [personId2]
},
{
featureId: "feature3",
persons: [personId2]
},
{
featureId: "feature5",
persons: [personId2]
}]
}
]
Above data input will contains hundreds of Person in input with multiple features and properties.
I am not able to understand what should be used as jolt transform here. even this complex transformation is possible. It kind of aggregating all the data per properties, so doing so need some hack in jolt transform to convert the propertyId as key in all the input json and then aggregate using that key to get all the common merged. Might need addition logic to remove duplicates.
First, please make sure when you need help with something like this is to provide valid json data. When I copied your data to work on I noticed double quotes were missing from the keys and in one case there was an extra curly brackets.
Regarding the spec, I think the below should work. Basically you need to create a way to group persons by properties & features (2ed shift transformation). To group easily I have concatenated all possible properties values into a string (1st modify spec). Finally I restructured the grouping output to get the desired result based on possible combinations of the properties concatenation (since some values might not exist which would be easier if not).
@Barbaros Özhan, I wonder if spec can be written in cleaner more concise way.let me know what you think.
Thanks