Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prakhar Yadav Module 5 #86

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions Module 5/Problem_1/Q1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
Input:
{
"orders": [
{
"orderId": 1,
"orderDate": "2022-02-20T12:34:56Z",
"customer": {
"customerId": 1,
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
},
"items": [
{
"itemId": 1,
"name": "Product A",
"quantity": 2,
"price": 10
},
{
"itemId": 2,
"name": "Product B",
"quantity": 1,
"price": 20
}
]
},
{
"orderId": 2,
"orderDate": "2022-02-21T09:12:34Z",
"customer": {
"customerId": 2,
"firstName": "Jane",
"lastName": "Smith",
"email": "[email protected]",
"address": {
"street": "456 Oak St",
"city": "Somewhere",
"state": "NY",
"zip": "67890"
}
},
"items": [
{
"itemId": 3,
"name": "Product C",
"quantity": 3,
"price": 15
}
]
}
]
}

json Spec:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"customer": {
"address": "=concat(@(1,address.street),' ',@(1,address.city), ' ', @(1,address.state), ' ',@(1,address.zip))",
"fullname": "=concat(@(1,firstName),' ',@(1,lastName))"
},
"itemTemp": "@(1,items)"
}
}
}
},

{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"items": {
"*": {
"price": "=toDouble(@(1,price))"
}
},
"itemTemp": {
"*": {
"inverseValue": "=divide(1,@(1,price))",
"temp": "=divideAndRound(2, @(1,quantity), @(1,inverseValue))"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"orders": {
"*": {
"*": "orders[&1].&",
"itemTemp": {
"*": {
"temp": "orders[#4].total"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"total": "=doubleSum(@(1,total))"
}
}
}
},

{
"operation": "remove",
"spec": {
"orders": {
"*": {
"items": {
"*": {
"inverseValue": "",
"temp": ""
}
},
"customer": {
"firstName": "",
"lastName": ""
}
}
}
}
}
]


Output:
{
"orders" : [ {
"orderId" : 1,
"orderDate" : "2022-02-20T12:34:56Z",
"customer" : {
"customerId" : 1,
"email" : "[email protected]",
"address" : "123 Main St Anytown CA 12345",
"fullname" : "John Doe"
},
"items" : [ {
"itemId" : 1,
"name" : "Product A",
"quantity" : 2,
"price" : 10.0
}, {
"itemId" : 2,
"name" : "Product B",
"quantity" : 1,
"price" : 20.0
} ],
"total" : 40.0
}, {
"orderId" : 2,
"orderDate" : "2022-02-21T09:12:34Z",
"customer" : {
"customerId" : 2,
"email" : "[email protected]",
"address" : "456 Oak St Somewhere NY 67890",
"fullname" : "Jane Smith"
},
"items" : [ {
"itemId" : 3,
"name" : "Product C",
"quantity" : 3,
"price" : 15.0
} ],
"total" : 45.0
} ]
}
8 changes: 8 additions & 0 deletions Module 5/Problem_1/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Number of operations: 5
1. modify-overwrite-beta
2. shift
3. remove
### Approach
1. The modify-overwrite-beta is used in order to concatenate the firstName and the lastName and the complete address into a single string. Also the modify-overwrite-beta operation is used to create a key value pair that gives us the total of orders by using the divide and doubleSum functions.
2. The shift operation is then used in order to get the desired output in that particular order.
3. Finally the remove operation is used to remove all the temp variables that were created during the calculation of the total amount of orders.
70 changes: 70 additions & 0 deletions Module 5/Problem_10/Q10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Input JSON
{
"name": "John Smith",
"age": 35,
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
},
"phone_numbers": [
{
"type": "home",
"number": "555-1234"
},
{
"type": "work",
"number": "555-5678"
}
]
}

Jolt Spec
[
{
"operation": "modify-overwrite-beta",
"spec": {
"fullName": "=split(' ',@(2,name))",
"first_name": "=firstElement(@(1,fullName))",
"last_name": "=lastElement(@(1,fullName))",
"phone_number_count": "=size(@(1,phone_numbers))"
}
},
{
"operation": "shift",
"spec": {
"first_name": "&",
"last_name": "&",
"age": "&",
"address": "&",
"phone_numbers": "&",
"phone_number_count": "&"
}
}

]

Output JSON
{
"first_name": "John",
"last_name": "Smith",
"age": 35,
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
},
"phone_numbers": [
{
"type": "home",
"number": "555-1234"
},
{
"type": "work",
"number": "555-5678"
}
],
"phone_number_count": 2
}
7 changes: 7 additions & 0 deletions Module 5/Problem_10/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Number of operations: 2
1. modify-overwrite-beta
2. shift

### Approach
1. The modify-overwrite-beta is used in order to split the name in the input json and to add the count of the phone_numbers.
2. Finally, in the second operation i.e. shift operartion the json is transformed into the desired struture.
41 changes: 41 additions & 0 deletions Module 5/Problem_11/Q11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Input JSON
{
"items": [
{
"name": "item1",
"value": 10
},
{
"name": "item2",
"value": 20
}
]
}

Jolt Spec
[

{
"operation": "shift",
"spec": {
"items": {
"*": {
"name": "items[#2].itemName",
"value": "items[#2].itemValue"
}
}
}
}

]

Output JSON
{
"items" : [ {
"itemName" : "item1",
"itemValue" : 10
}, {
"itemName" : "item2",
"itemValue" : 20
} ]
}
5 changes: 5 additions & 0 deletions Module 5/Problem_11/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Number of operations: 1
1. Shift

### Approach
1. The shift operation is used in order to change the keys.
63 changes: 63 additions & 0 deletions Module 5/Problem_12/Q_12.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Input JSON
{
"employee": {
"firstName": "John",
"lastName": "Doe",
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
},
"phones": [
{
"type": "home",
"number": "555-555-1234"
},
{
"type": "work",
"number": "555-555-5678"
}
]
}
}

Jolt Spec
[

{
"operation": "modify-overwrite-beta",
"spec": {
"employee": {
"name": "=concat(@(1,firstName),' ', @(1,lastName))",
"address": "=concat(@(1,address.street),' ', @(1,address.city),' ', @(1,address.state),' ', @(1,address.zip))"
}
}
},
{
"operation": "shift",
"spec": {
"employee": {
"name": "name",
"address": "&",
"phones": "phoneNumbers"
}
}
}
]

Output JSON
{
"name": "John Doe",
"address": "123 Main St, Anytown, CA 12345",
"phoneNumbers": [
{
"type": "home",
"number": "555-555-1234"
},
{
"type": "work",
"number": "555-555-5678"
}
]
}
Loading