I am trying following code to get details but it is not return what i want .
my query :
var query = $"SELECT catalog.id as vendorguid,catalog.VendorName,industry.Id as industryguid,industry.IdustryId,industry.IdustryName,category.id as categoryguid,category.Name as categoryname,category.Description as categorydescription,Subcategory.Id as subcategoryguid,Subcategory.Name as subcategoryname,Subcategory.Description as subcategorydescription,product.Id as productguid,product.Name as productname,product.CurrentQuantity as productCurrentQuantity,product.Tag as productTag,product.ImageUrl as productImageUrl,product.Unit as productUnit,product.Price as productPrice,product.hasMethodOfPreparation as producthasMethodOfPreparation,product.MethodOfPreparation as productMethodOfPreparation,product.Addons as productAddons FROM catalogjoin industry in catalog.Industy join category in industry.Category join Subcategory in category.Subcategoryjoin product in Subcategory.Product where product.Id = '"+productId+"'";
my service class :
output:
{
"id": "d91af3e6-6aae-4d10-9ba6-6b97ca4cd881",
"vendorName": "string",
"industy": []
}
expected output:
{
"vendorguid": "97392a23-c8c4-4a7f-bffb-7c3807cc40de",
"VendorName": "string",
"industryguid": "f8265ee6-a351-4036-a0ee-10ec4f51ecf4",
"IdustryId": 0,
"IdustryName": "string",
"categoryguid": "ce7edfdf-1608-4a8c-ae38-7ca60c43bc30",
"categoryname": "string",
"categorydescription": "string",
"subcategoryguid": "709f4e6f-1bba-421f-8dc0-7cf067cbc032",
"subcategoryname": "string",
"subcategorydescription": "string",
"productguid": "d24dd340-d7a2-42e5-b84a-1ee72d9840c6",
"productname": "string",
"productCurrentQuantity": 0,
"productTag": "string",
"productImageUrl": [
"string"
],
"productUnit": 0,
"productPrice": 0,
"producthasMethodOfPreparation": true,
"productMethodOfPreparation": [
],
"productAddons": [
]
}
how can i get it anyone help me?
I think the issue is in your joins (Category, SubCategory). Are your sure its always finding a match? If it doesn't find a match or don't have that properties, CosmosDb will not include it in the results set.
Its not like the left join of MSSQL where nulls are included. CosmosDb is more of a full outer join (cross join).
Related
Suppose we have a structure:
{
"nested_items": [
{
"nested_sample0": "1",
"nested_sample1": "test",
"nested_sample2": "test",
"nested_sample3": {
"type": "type"
},
"nested_sample": null
},
{
"nested_sample0": "1",
"nested_sample1": "test",
"nested_sample2": "test",
"nested_sample3": {
"type": "type"
},
"nested_sample1": null
},
...
],
"sample1": 1233,
"id": "ed68ca34-6b59-4687-a557-bdefc9ec2f4b",
"sample2": "",
"sample3": "test",
"sample4": "test",
"_ts": 1656503348
}
I want to retrieve documents by id by with limit of "nested_items" field .As I know limit and offset not supported in sub queries. Any way to do this except of divide into two queries? Maybe some udf or else?
You can use the function ARRAY_SLICE assuming the array is ordered.
Example data:
{
"name": "John",
"details": [
{
"id": 1
},
{
"id": 2
},
{
"id": 3
}
]
}
Example queries
-- First 2 items from nested array
SELECT c.name, ARRAY_SLICE(c.details, 0, 2) as details
FROM c
-- Last 2 items from nested array
SELECT c.name, ARRAY_SLICE(c.details, ARRAY_LENGTH(c.details) - 2, 2) as details
FROM c
I'm using WooCommerce Rest APIs in wordpress to make an android application and i'm trying to get product variation from the product detail's response.I am getting product variations with its attributes and names in a list but i don't know how to check which variation has which Variation ID.
"attributes": [
{
"id": 3,
"name": "Ships From",
"position": 0,
"visible": false,
"variation": true,
"options": [
"China"
]
},
{
"id": 20,
"name": "Type",
"position": 1,
"visible": false,
"variation": true,
"options": [
"1",
"2",
"3"
]
},
{
"id": 21,
"name": "Length (m/ft)",
"position": 2,
"visible": false,
"variation": true,
"options": [
"0.25 / 0.82",
"0.5 / 1.64",
"1 / 3.28",
"1.5 / 4.92",
"2 / 6.56"
]
}
],
"default_attributes": [],
"variations": [
158435,
158436,
158437,
158438,
158439,
158440,
158441,
158442,
158443,
158444,
158445,
158446
],
here i have names and ID of attributes with everything and in below i have all ID of product variations but i don't know how to know that if i mix China+1+"0.25 / 0.82 then which will be variation ID.
thanks in advance.
You have to make another api call to wp-json/wc/v3/products/< product_id >/variations or make individual calls to wp-json/wc/v3/products/< product_id >/variations/< variation_id > using those variations id's on the "variations" array and check which variation has which combination of attributes, there is no direct relation between the variation ID and the attributes it uses.
What will be the LINQ equivalent of this cosmos SQL API query:
SELECT c as Person, ST_DISTANCE(c.location, {'type': 'Point', 'coordinates':[-122.3382419, 47.6074856]}) as Distance
FROM c
WHERE c.DocType = 0 AND
ST_DISTANCE(c.location, {'type': 'Point', 'coordinates':[-123.3382419, 47.6074856]}) < 1 AND NOT c.Blocked
which gets back
[
{
"Person": {
"DocType": 0,
"location": {
"type": "Point",
"coordinates": [
-123.3382419,
47.6074856
]
},
"MDS": "Chwal",
"Description": "Bduwhs",
"Contents": null,
"GFree": false,
"Veg": false,
"AllergicContents": null,
"Calorie": 0,
"LinkToRecipe": null,
"Cost": 36,
"DASD": "Mexican",
"ExpirationTime": "2019-12-17T11:30:52Z",
"Images": [
"test/25254932-2898-5fd7-949b-b2feb25a4964"
],
"ProducerUserId": "1b36c0f1-425c-483a-bb01-69b06e69f203",
"ExchangeDateTimeStartInUtc": "2019-12-17T20:30:52Z",
"ExchangeDateTimeEndInUtc": "2019-12-17T19:30:52Z",
"Blocked": false,
"id": "asd,
"_rid": "asd=="
},
"Distance": 0.1
}
]
The problem with ST_DISTANCE is that it can only be calculated on Cosmos db, and can't be post evaluated.
Found a way to do it other than writing SQL query string
DocumentDBRepository.RunQueryAsync(
from c in DocumentDBRepository.DocumentQuery<Person>()
where c.DocType == 0
&& c.Location.Distance(point) < 1
&& !c.Blocked
select new { Person = c, Distance = c.Location.Distance(point) });
Also realized that LINQ lambda is different from a LINQ query. The above is a LINQ query, A LINQ lambda looks like this
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:
I have below structure
{
"SubscriberId": "a4db02c1-f41b-4ab1-9f3e-83f9a7ccde83",
"Subscription": {
"Type": "Member",
"MaxUsers": "200",
"StartDate": "2018-07-01T00:00:00.0000000Z",
"EndDate": "2019-07-31T00:00:00.0000000Z",
"Families": [
{
"Id": "4042e5dc-ff0e-5cca-d5ee-d96c4522f1db",
"Products": [
{
"Id": "e9313211-ca18-4776-8fea-1d552b6f40d6",
"Price": null
},
{
"Id": "bf3cdaa4-8cbe-42e6-8f6f-20c1210dc4ac",
"Price": null
}
]
}
],
"IsActive": "true"
}
}
so I want to get data in the below structure, how can I use sql to do this?
SubscriberID , Type,Families.Id,Families.Products.Id, Families.Products.Price
Please use sql:
select distinct c.SubscriberId,c.Subscription.Type as Type,
f.Id as FamiliesId,p.Id as ProductsId,p.Price as ProductsPrice
from c
join f in c.Subscription.Families
join p in f.Products
Result: