I have been create a catalog service like blow json pattern.
Json pattern :
{
"id": "b01ee924-78d3-4f3a-9568-5ee80cbad7a7",
"VendorName": "string",
"Industy": [
{
"Id": "0350ac6c-ca15-4a1e-9211-ad078fbf443c",
"IdustryId": 0,
"IdustryName": "string",
"Category": [
{
"id": "a7b71770-9daf-4b67-b471-0a8390843544",
"Name": "string",
"Description": "string",
"Subcategory": [
{
"id": "76a6ead4-9f4d-4d6e-9c30-70938f088ea3",
"Name": "string",
"Description": "string",
"Product": [
{
"Id": "abf95277-ccbc-4f9d-aeda-b6cc9c99953b",
"Name": "string",
"CurrentQuantity": 0,
"Tag": "string",
"Unit": "string",
"Price": 0,
"hasMethodOfPreparation": true,
"MethodOfPreparation": [
{
"id": "a78cb9ea-276f-494b-840a-6eab5e7d8f4b",
"Description": "string",
"Price": 0
}
],
"Addons": [
{
"id": "bdf97be3-5dd1-49e9-bdec-7ac0d3288adb",
"Description": "one",
"Price": 0
},
{
"id": "8f03d2e2-be1f-446d-b943-be9b8fe8ec4c",
"Description": "new add",
"Price": 0
I query the data like blow
query:
SELECT product FROM catalog
join industry in catalog.Industy
join category in industry.Category
join product in category.Subcategory.Product
where catalog.id ='" + itemId + "'
actual result:For a specific vendor ,industry ,category,sub category i need to get and create product.
note: here more than one indutry,category,sub category .
{
"Id": "abf95277-ccbc-4f9d-aeda-b6cc9c99953b",
"Name": "string",
"CurrentQuantity": 0,
"Tag": "string",
"Unit": "string",
"Price": 0,
"hasMethodOfPreparation": true,
"MethodOfPreparation": [
{
"id": "a78cb9ea-276f-494b-840a-6eab5e7d8f4b",
"Description": "string",
"Price": 0
}
but i need to check the industry id ,category id and sub category id.
How to do that,
Please give me suggestion. thanks in advance .
Please use sql:
SELECT product FROM c
join industry in c.Industy
join category in industry.Category
join Subcategory in category.Subcategory
join product in Subcategory.Product
where industry.Id ='<your item id>'
and category.Id = '<your item id>'
and Subcategory.Id = '<your item id>'
Output:
Related
I'm trying to deduplicate all objects inside the array results that share the same key id, and merge their path arrays.
JSON input:
[
{
"type": "apple",
"results": [
{
"id": "apple1",
"name": "appleName1",
"path": "/some/path/a"
},
{
"id": "apple1",
"name": "appleName1",
"path": "/some/path/b"
},
{
"id": "apple2",
"name": "appleName2",
"path": "/some/path/c"
}
]
},
{
"type": "orange",
"results": [
{
"id": "orange1",
"name": "orangeName1",
"path": "/some/path/a"
},
{
"id": "orange1",
"name": "orangeName1",
"path": "/some/path/b"
},
{
"id": "orange2",
"name": "orangeName2",
"path": "/some/path/c"
}
]
}
]
Expected output:
[
{
"type": "apple",
"results": [
{
"id": "apple1",
"name": "appleName1",
"path": [
"/some/path/a",
"/some/path/b"
]
},
{
"id": "apple2",
"name": "appleName2",
"path": [
"/some/path/c"
]
}
]
},
{
"type": "orange",
"results": [
{
"id": "orange1",
"name": "orangeName1",
"path": [
"/some/path/a",
"/some/path/b"
]
},
{
"id": "orange2",
"name": "orangeName2",
"path": [
"/some/path/c"
]
}
]
}
]
I've managed to get an approximate solution using:
jq '[{type: .[].type, results: .[].results | group_by(.id) | map({id: .[0].id, name: .[0].name, path: (map(.path))})}]'
But my solution produces two additional elements that aren't supposed to be there.
I know there are some similar questions already answered but I didn't manage to get them to work with this example. Any help is appreciated!
You could group_by the .id field, then for each group take the first item and replace its .path field with a map on the .path fields of all group members:
jq 'map(.results |= (group_by(.id) | map(first + {path: map(.path)})))'
[
{
"type": "apple",
"results": [
{
"id": "apple1",
"name": "appleName1",
"path": [
"/some/path/a",
"/some/path/b"
]
},
{
"id": "apple2",
"name": "appleName2",
"path": [
"/some/path/c"
]
}
]
},
{
"type": "orange",
"results": [
{
"id": "orange1",
"name": "orangeName1",
"path": [
"/some/path/a",
"/some/path/b"
]
},
{
"id": "orange2",
"name": "orangeName2",
"path": [
"/some/path/c"
]
}
]
}
]
Demo
Is there a way to setup a where clause in Kusto to get specific records with child records
Like if I wanted Kyle from below
Where address has Code = street and that value= grant AND Code = Number and that value= 55555
{
"Firstname": "Bob",
"lastName": "stevens"
"address": [
{
"code": "street",
"value": "Olsen"
},
{
"code": "Number",
"value": "123456"
}
},
{
"Firstname": "Kyle",
"lastName": "richards"
"address": [
{
"code": "street",
"value": "grant"
},
{
"code": "Number",
"value": "55555"
}
}
you could try using mv-apply, and filter for records in which the number of conditions met is as expected:
datatable(i:int, d:dynamic)
[
1, dynamic({"Firstname": "Bob", "lastName": "stevens", "address": [{ "code": "street", "value": "Olsen" }, { "code": "Number", "value": "123456" }]}),
2, dynamic({"Firstname": "Kyle", "lastName": "richards", "address": [{ "code": "street", "value": "grant" }, { "code": "Number", "value": "55555" }]}),
3, dynamic({"Firstname": "Kyle", "lastName": "richards", "address": [{ "code": "street", "value": "grant" }, { "code": "Number", "value": "11111" }]})
]
| mv-apply address = d.address on (
summarize c = countif((address.code == 'street' and address.value == 'grant') or
(address.code == 'Number' and address.value == 55555))
| where c == 2
)
| project-away c
i
d
2
{ "Firstname": "Kyle", "lastName": "richards", "address": [ { "code": "street", "value": "grant" }, { "code": "Number", "value": "55555" } ]}
update: in reply to your comment:
I'm trying to do this with a sproc, Would i need to put this into a datatable then query it like that? If so how do I put a query into a datatable
First, there are no stored procedures in Kusto. there are stored functions.
Second, if you want to invoke a similar logic over an existing table, you can define a stored function that takes a tabular argument as its input. And, optionally, use the invoke operator.
For example:
.create function my_function(T:(d:dynamic)) {
T
| mv-apply address = d.address on (
summarize c = countif((address.code == 'street' and address.value == 'grant') or
(address.code == 'Number' and address.value == 55555))
| where c == 2
)
| project-away c
}
let my_table = datatable(i:int, d:dynamic)
[
1, dynamic({"Firstname": "Bob", "lastName": "stevens", "address": [{ "code": "street", "value": "Olsen" }, { "code": "Number", "value": "123456" }]}),
2, dynamic({"Firstname": "Kyle", "lastName": "richards", "address": [{ "code": "street", "value": "grant" }, { "code": "Number", "value": "55555" }]}),
3, dynamic({"Firstname": "Kyle", "lastName": "richards", "address": [{ "code": "street", "value": "grant" }, { "code": "Number", "value": "11111" }]})
];
my_table
| invoke my_function()
With the usage of this query in CosmosDB Gremlin API:
g.V().has('person', 'name', 'John').as('his')
.out('bought').aggregate('self')
.out('made_by')
I have next output:
[
{
"id": "100",
"label": "brand",
"type": "vertex",
"properties": {
"name": [
{
"id": "233b77e7-7007-4c08-8930-99b25b67e493",
"value": "Apple"
}
]
}
},
{
"id": "100",
"label": "brand",
"type": "vertex",
"properties": {
"name": [
{
"id": "233b77e7-7007-4c08-8930-99b25b67e493",
"value": "Apple"
}
]
}
},
{
"id": "101",
"label": "brand",
"type": "vertex",
"properties": {
"name": [
{
"id": "f3e238e2-f274-489c-a69c-f1333403ee8e",
"value": "Google"
}
]
}
}
]
Is there a way to select only brands, which quantity is > 1 (Apple in this case)?
I think that you just need to groupCount() and then use a filter:
g.V().has('person', 'name', 'John').as('his').
out('bought').aggregate('self').
out('made_by').
groupCount().
unfold().
where(select(values).is(gt(1))).
select(keys)
You could just groupCount() and then unfold() the resulting Map so that you can filter the entries with where().
I have the following JSON:
{
"code": 201,
"data": {
"type": "Agent",
"id": {
"#type": "Client",
"#id": "88",
"title": "Ing.",
"titleAfter": null,
"name": "Ján",
"surname": "Kašperan",
"idNumber": "8706229411",
"dateOfBirth": null,
"idCardNumber": "OP12345",
"idCardExpirationDate": null,
"idCardType": {
"#type": "IdCardType",
"#id": 1,
"name": "id_card_type.id_card",
"shortName": "OP"
},
"type": 1
}
}
}
I would like to write a JSON path expression so that I want to get the value of "#id": "88",.
My JSON path do not work: $.data.id.#id
Since # is not allowed, access it by the string property name. More information about property accessors can be found on MDN
var json = {
"code": 201,
"data": {
"type": "Agent",
"id": {
"#type": "Client",
"#id": "88",
"title": "Ing.",
"titleAfter": null,
"name": "Ján",
"surname": "Kašperan",
"idNumber": "8706229411",
"dateOfBirth": null,
"idCardNumber": "OP12345",
"idCardExpirationDate": null,
"idCardType": {
"#type": "IdCardType",
"#id": 1,
"name": "id_card_type.id_card",
"shortName": "OP"
},
"type": 1
}
}
}
console.log(json.data.id["#id"])
I'm getting list of all users whom I've followed using following query :-
g.v(2304).out('Follow')
Response :
{
"success": true,
"results":
[
{
"Type": "User",
"CreatedTime": "2016-03-16T18:39:48.5000845Z",
"Username": "funoverflow24x7#gmail.com",
"FirstName": "Joany",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/947174ae-3e60-4dd0-877f-cc988fae3888.jpg",
"ImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/f4f6901c-64c4-425b-929b-43936c53eaba.png",
"LastName": "Ashtana",
"Gender": "male",
"_id": 768,
"_type": "vertex"
},
{
"Type": "User",
"CreatedTime": "2016-04-05T16:36:49.3740440Z",
"Username": "urnoticemail#gmail.com",
"FirstName": "Maria",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/images/companyRectangleImageNotAvailable.png",
"ImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/users/female_professional.png",
"LastName": "Sharapova",
"Gender": "female",
"_id": 5120256,
"_type": "vertex"
},
{
"Type": "User",
"CreatedTime": "2016-04-12T07:42:18.8036554Z",
"Username": "abhinavsrivastava189+1#gmail.com",
"FirstName": "Abhi",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/afd0d047-0d1c-4391-8f88-95f7775c615f.jpg",
"ImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/fd0842d4-579b-4896-9525-945f8f718816.JPG",
"LastName": "Sri",
"Gender": "male",
"_id": 12800512,
"_type": "vertex"
},
{
"Type": "User",
"CreatedTime": "2016-04-15T07:51:34.3867249Z",
"Username": "786goopchup#gmail.com",
"FirstName": "Goop",
"CoverImageUrl": "",
"ImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",
"LastName": "Chup",
"Gender": "NA",
"_id": 17928960,
"_type": "vertex"
},
{
"Type": "User",
"CreatedTime": "2016-04-20T03:25:30.0753729Z",
"Username": "sumit#thirdeyeinc.com",
"FirstName": "Kunal",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/ee167d15-52bb-4f4f-99fb-038f27eee1dc.jpeg",
"ImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",
"LastName": "Sharma",
"Gender": "NA",
"_id": 23041024,
"_type": "vertex"
}
],
"version": "2.5.0",
"queryTime": 21.94298
}
And I'm getting particular user post using following query :
g.v(396800).in('WallPost').sort{ a, b -> b.PostedTime <=> a.PostedTime }.()[0..3].transform{ [postInfo : it, commentsInfo: it.in('Comment').sort{ a, b -> b.PostedTime <=> a.PostedTime }.()[0..5].transform{[commentInfo:it, commentedBy: it.in('Created')]},userInfo:it.in('Created')] }
And I'm getting response :
{
"success": true,
"results": [
{
"postInfo": {
"PostImage": "",
"Type": "Post",
"PostedByUser": "sumit#thirdeyeinc.com",
"PostedTime": "2016-04-29T11:48:17.5069984Z",
"PostedTimeLong": 635975272975069984,
"PostMessage": "testing new post. on pooja",
"_id": 30729984,
"_type": "vertex"
},
"commentsInfo": [
],
"userInfo": [
{
"Type": "User",
"CreatedTime": "2016-04-20T03:25:30.0753729Z",
"Username": "sumit#thirdeyeinc.com",
"FirstName": "Kunal",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/ee167d15-52bb-4f4f-99fb-038f27eee1dc.jpeg",
"ImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",
"LastName": "Sharma",
"Gender": "NA",
"_id": 23041024,
"_type": "vertex"
}
]
}
],
"version": "2.5.0",
"queryTime": 383.759295
}
I want to get post of all users whom i've followed and that in descending order according to PostTime of post Vertex.
I've tried a lot but I'm not getting any approach how can I achieve this.
You are doing it right. Just first get all the vertices whom you are following and apply your get wall post logic on that all vertices, it will give you your desired result.
g.v(2304).out('Follow').in('WallPost').sort {
a, b -> b.PostedTime <=> a.PostedTime
}.()[0..3]
.transform {
[
postInfo: it,
commentsInfo: it.in('Comment').sort {
a, b -> b.PostedTime <=> a.PostedTime
}.()[0..5].
transform {
[
commentInfo: it,
commentedBy: it.in('Created')
]
},
userInfo:it.in('Created')
]
}
So it will give you list of all post of your following and in descending order of PostedTime.