-
Notifications
You must be signed in to change notification settings - Fork 21
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
Apurva Shukla- Module 5 #89
Open
apurvaone
wants to merge
45
commits into
hotwax:main
Choose a base branch
from
apurvaone:ApurvaShukla-Module5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
863e134
Solved all questions of Module 5
apurvaone bae17c7
added the solution of Problem 14
apurvaone d17576a
Corrected Problem 1: concatination of firstName and lastName
apurvaone d8058b2
Corrected the output in Problem 16
apurvaone 2e3b42b
Added the missing 'department' field in Problem 8
apurvaone b9f7c62
Added the missing 'salary' field in Problem 8
apurvaone 1ed18f6
Added explanation.md file in problems 1-4
apurvaone c7e3cbc
Optimized the transformation of Problem 5
apurvaone f6863d9
Added explanation.md file for Problem 5-6
apurvaone 661c422
Optimized the transformation of problem 7 and added explanation.md file
apurvaone 570afe6
Corrected the mention of used operation in Problem 7
apurvaone 90d02c5
Added another solution for Problem 8 Transformation
apurvaone 587c4c5
Added the explanation.md file for Problems 8-10
apurvaone 17ecbc3
Added optimized solution for problem 11
apurvaone 8a9f4aa
Added the explanation.md file for problem 11
apurvaone e1e9b35
Optimized the transformation spec of Problem 12
apurvaone 3847138
Added the explanation.md file for problem 12-13
apurvaone 641c989
Corrected the spec of problem 14 to add the missing 'department' field
apurvaone 3dcdb70
Added the explanation.md file for problems 14-25
apurvaone 26484cd
Optimized the transformation spec of Problem 26
apurvaone 69ddb4c
Added the explanation.md file for problems 26-34
apurvaone 4af606c
Added the missing 'totalPrice' field in problem 15
apurvaone eab9b22
Resolved problem 8 issue: removed the usage of field 'tempBonus'
apurvaone cf48fb1
Added alternate solution in problem 8,assuming the bonus is given dep…
apurvaone 0b8aa2a
Optimized Problem 5 spec:used '&' to access the keys of map
apurvaone 0b82846
Corrected the level in problem 10
apurvaone 276f9c3
Optimized problem 1: removed the usage of duplicate field 'itemsTemp'
apurvaone 5a76e63
Problem 12: Corrected the key of list 'phone' to 'phoneNumbers'
apurvaone 8e5e059
Optimized Problem 14 :used wildcard '&' to access the keys of map
apurvaone 731df98
Problem 15: Removed the operation 'sort'
apurvaone dc110c5
Optimized Problem 29: Reduced no. of operation
apurvaone 615ad7c
Corrected Problem 30: Taken name field from 'person' insted of 'emplo…
apurvaone b5b38b8
Optimized Problem 33: Reduced no. of operation
apurvaone 87113cc
Optimized Problem 27: Made the spec more dynamic,reduced operations
apurvaone c3540bb
Used '&' to naviagte on levels instead of '#' in Problem 6
apurvaone 009ceb1
Updated the explanation.md file for problem 1
apurvaone 23015c1
Updated the explanation file for problem 5
apurvaone 44c0cc1
Updated the explanation file for problem 8
apurvaone 51cd391
Updated the explanation file for problem 10
apurvaone b01f32b
Updated the explanation file for problem 12
apurvaone 72efc66
Updated the explanation file for problem 15
apurvaone 4c9e232
Updated the explanation file for problem 29
apurvaone fec0f1d
Updated the explanation file for problem 30
apurvaone 5cb15fe
Updated the explanation file for problem 33
apurvaone 6351102
Updated the explanation file for problem 27
apurvaone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Explanation | ||
|
||
Opeartions: modify-overwrite-beta, shift , remove | ||
|
||
The transformation involves following operation: | ||
|
||
* **`modify-overwrite-beta`** : Adds "customer.address" and "customer.fullname" fields to each order by concatenating address fields and customer names, also created a copy of items in each order and naming it itemTemp. | ||
|
||
* **`modify-overwrite-beta`** : Adds "inverseValue" and "temp" fields to each item by dividing 1 by the price effictively resulting in multipication of price and quantity and storing it in variable named temp, inside itemTemp lsit. | ||
|
||
* **`shift`**: Restructures the JSON by moving the temp value (total amount of each order) into a list named total containing the price of each order, and placing it on each order object. | ||
|
||
* **`modify-overwrite-beta`**" : Computes the sum of "total" values within "orders" and assigns it to each order's "total" field. | ||
|
||
* `"remove"`: Removes "firstName", and "lastName" fields from each order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
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 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
|
||
|
||
Transformation: | ||
|
||
[ | ||
{ | ||
"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": { | ||
"*": { | ||
"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, | ||
"firstName" : "John", | ||
"lastName" : "Doe", | ||
"email" : "[email protected]", | ||
"address" : "123 Main St Anytown CA 12345" | ||
}, | ||
"items" : [ { | ||
"itemId" : 1, | ||
"name" : "Product A", | ||
"quantity" : 2, | ||
"price" : 10 | ||
}, { | ||
"itemId" : 2, | ||
"name" : "Product B", | ||
"quantity" : 1, | ||
"price" : 20 | ||
} ], | ||
"total" : 40.0 | ||
}, { | ||
"orderId" : 2, | ||
"orderDate" : "2022-02-21T09:12:34Z", | ||
"customer" : { | ||
"customerId" : 2, | ||
"firstName" : "Jane", | ||
"lastName" : "Smith", | ||
"email" : "[email protected]", | ||
"address" : "456 Oak St Somewhere NY 67890" | ||
}, | ||
"items" : [ { | ||
"itemId" : 3, | ||
"name" : "Product C", | ||
"quantity" : 3, | ||
"price" : 15 | ||
} ], | ||
"total" : 45.0 | ||
} ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### Explanation: | ||
|
||
|
||
The transformation involves following operations: | ||
|
||
* `modify-overwrite-beta:` The field 'fullname' is splitted with space and the the values of generated lists are assigned to 'first_name' and 'last_name' using firstElement and lastElement methods, also the size of list 'phone_numbers' is calculated using size function and is mapped to key 'phone_number_count'. | ||
|
||
* `remove`: Removes the "fullname" and "name" fields from the output JSON. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Input: | ||
|
||
{ | ||
"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" | ||
} | ||
] | ||
} | ||
|
||
Transformation: | ||
|
||
[ | ||
{ | ||
"operation": "modify-overwrite-beta", | ||
"spec": { | ||
"fullname": "=split(' ',@(2,name))", | ||
"first_name": "=firstElement(@(2,fullname))", | ||
"last_name": "=lastElement(@(2,fullname))", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is giving the desired output but 2 is not the correct level here. Please check. |
||
"phone_number_count": "=size(1,phone_numbers)" | ||
} | ||
}, | ||
{ | ||
"operation": "remove", | ||
"spec": { | ||
"fullname": "", | ||
"name": "" | ||
} | ||
} | ||
] | ||
|
||
|
||
Ouput: | ||
|
||
{ | ||
"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" | ||
} ], | ||
"first_name" : "John", | ||
"last_name" : "Smith", | ||
"phone_number_count" : 2 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### Explanation: | ||
|
||
=> problem_11b | ||
|
||
The transformation involves following operations: | ||
|
||
* `shift:` ': navigate to each object to items list, access the value of name and value fields and map them to items list 2 level up with keys itemName and itemValue respectively. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Input: | ||
|
||
{ | ||
"items": [ | ||
{ | ||
"name": "item1", | ||
"value": 10 | ||
}, | ||
{ | ||
"name": "item2", | ||
"value": 20 | ||
} | ||
] | ||
} | ||
|
||
|
||
Transformation: | ||
|
||
[ | ||
{ | ||
"operation": "modify-overwrite-beta", | ||
"spec": { | ||
"items": { | ||
"*": { | ||
"itemName": "@(1,name)", | ||
"itemValue": "@(1,value)" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"operation": "remove", | ||
"spec": { | ||
"items": { | ||
"*": { | ||
"name": "", | ||
"value": "" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
|
||
|
||
Output: | ||
|
||
{ | ||
"items" : [ { | ||
"itemName" : "item1", | ||
"itemValue" : 10 | ||
}, { | ||
"itemName" : "item2", | ||
"itemValue" : 20 | ||
} ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Input: | ||
|
||
{ | ||
"items": [ | ||
{ | ||
"name": "item1", | ||
"value": 10 | ||
}, | ||
{ | ||
"name": "item2", | ||
"value": 20 | ||
} | ||
] | ||
} | ||
|
||
|
||
Transformation: | ||
[ | ||
{ | ||
"operation": "shift", | ||
"spec": { | ||
"items": { | ||
"*": { | ||
"name": "items[#2].itemName", | ||
"value": "items[#2].itemValue" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
|
||
|
||
Output: | ||
|
||
{ | ||
"items" : [ { | ||
"itemName" : "item1", | ||
"itemValue" : 10 | ||
}, { | ||
"itemName" : "item2", | ||
"itemValue" : 20 | ||
} ] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be easily done without creating a duplicate of the 'items' list. Please optimize this.