Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def insideETL(keyname; arrayname; cond; result):
- def etl:
- . as $parent
- | .[arrayname][]
- | { parent: $parent, child: .}
- | select(cond) | result;
- map ( .
- +
- {(keyname): map(etl)}
- )
- ;
- def etl(keyname; arrayname; cond; result):
- def etl:
- . as $parent
- | .[arrayname][]
- | { parent: $parent, child: .}
- | select(cond) | result;
- {(keyname): map(etl)}
- ;
- ## Invocation:
- etl("conflictsInPeriod";
- "events";
- ( (.parent.workorder.startDate | dateDaysAgo(12*7) ) < .child.endDate)
- and
- (.child.vendorId == .parent.workorder.vendorId);
- {
- event: .child.id,
- wo_sd: .parent.workorder.startDate[:10],
- workorder_id: .parent.workorder.id
- }
- )
- [
- {
- "storeId": "s2",
- "storehouseInfo": {
- "id": "025453",
- "name": "00211 NW, OR",
- "maxPallets": 10
- },
- "workorder":{
- "id": "w2s2",
- "startDate": "2019-09-06T10:00:00.000Z",
- "vendorId":"v2"
- },
- "events": [
- {
- "id": "e4",
- "storeId": "s2",
- "vendorId": "v1",
- "startDate": "2019-09-05T10:00:00.000Z",
- "endDate": "2019-09-14T00:00:00.000Z",
- "palletsUsed": 5
- },
- {
- "id": "e5",
- "storeId": "s2",
- "vendorId": "v2",
- "startDate": "2019-09-05T00:00:00.000Z",
- "endDate": "2019-09-14T00:00:00.000Z",
- "palletsUsed": 5
- },
- {
- "id": "e10",
- "storeId": "s2",
- "vendorId": "v1",
- "startDate": "2019-09-06T10:00:00.000Z",
- "endDate": "2019-09-14T00:00:00.000Z",
- "palletsUsed": 5
- },
- {
- "id": "e11",
- "storeId": "s2",
- "vendorId": "v2",
- "startDate": "2019-09-06T00:00:00.000Z",
- "endDate": "2019-09-14T00:00:00.000Z",
- "palletsUsed": 5
- },
- {
- "id": "e12",
- "storeId": "s2",
- "vendorId": "v2",
- "startDate": "2019-09-06T10:00:00.000Z",
- "endDate": "2019-09-14T00:00:00.000Z",
- "palletsUsed": 5
- }
- ]
- },
- ]
- .|
- etl("conflictsInPeriod";
- "events";
- ( (.parent.workorder.startDate | dateDaysAgo(12*7) ) < .child.endDate)
- and
- (.child.vendorId == .parent.workorder.vendorId);
- {
- event: .child.id,
- wo_sd: .parent.workorder.startDate[:10],
- workorder_id: .parent.workorder.id
- }
- )
- [
- {
- "conflictsInPeriod":[
- {
- "event":"e5",
- "workorder_sd":"2019-09-06",
- "workorder_id":"w2s2"
- },
- {
- "event_id":"e11",
- "workorder_sd":"2019-09-06",
- "workorder_id":"w2s2"
- },
- {
- "event_id":"e12",
- "workorder_sd":"2019-09-06",
- "workorder_id":"w2s2"
- }
- ],
- "storeId":"s2",
- "storehouseInfo":{
- "id":"025453",
- "name":"00211 NW, OR",
- "maxPallets":10
- },
- "workorder":{
- "id":"w2s2",
- "startDate":"2019-09-06T10:00:00.000Z",
- "vendorId":"v2"
- },
- "events":[
- {
- "id":"e4",
- "storeId":"s2",
- "vendorId":"v1",
- "startDate":"2019-09-05T10:00:00.000Z",
- "endDate":"2019-09-14T00:00:00.000Z",
- "palletsUsed":5
- },
- ... All the other data
- ]
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement