Closed bdcoder2 closed 3 years ago
@bdcoder2 Thanks for your feedback! We will investigate and update as appropriate.
@timsander1 I am seeing the same behavior in my locals. Can you please provide your inputs if this is supported.
26-Oct-2021 - Additional information:
Tried the following experiment using the CosmosDB Emulator:
Execute the following query in ComosDB Emulator:
SELECT ST_ISVALID({'type':'Polygon','coordinates':[[[-113.247049,53.657421],[-113.733431,53.657421],
[-113.733431,53.393183],[-113.247049,53.393183],[-113.247049,53.657421]]]}) AS b
The emulator gives the following result, which shows the polygon (geo-JSON string) is valid:
[
{
"b": true
}
]
Next, the following code (C# console application) was executed using a polygon (same JSON string as above) as a parameter:
bounds_str = "{'type':'Polygon','coordinates':[[[-113.247049,53.657421],[-113.733431,53.657421],[-113.733431,53.393183],[-113.247049,53.393183],[-113.247049,53.657421]]]}";
QueryDefinition param_sql_query_1 = new QueryDefinition( "SELECT ST_ISVALID(@polygon), ST_ISVALIDDETAILED(@polygon)" )
.WithParameter( "@polygon", bounds_str );
FeedResponse<dynamic> result_1 = await m_rentals_container.GetItemQueryIterator<dynamic>( param_sql_query_1 ).ReadNextAsync();
Console.WriteLine( $"Result: {result_1.First()}" );
The output is:
Result: {
"$1": false,
"$2": {
"valid": false,
"reason": "Unable to process the geometry."
}
}
It appears that using a geo-JSON string in a parameterized query will fail because the runtime is evaluating the polygon as "invalid" and is "unable to process the geometry".
However, if a polygon OBJECT is passed as a parameter, the query will evaluate the polygon as valid.
Lesson learned: Use geospatial OBJECTS as parameters rather than geo-JSON strings as it appears that geo-JSON string parameters are not supported?- verification from Microsoft would be appreciated.
There are no restrictions about GeoJSON when it comes to parameters. If you're hitting an issue with spatial, this is a bug in the product not the documentation.
Can you file a support ticket and we will try to repro? If you don't have a support plan, you could also open an SDK issue in the Cosmos DB SDK that you were using. Here's the .NET SDK repo - https://github.com/Azure/azure-cosmos-dotnet-v3
Consider the following:
Given the following document structure:
Build a query without parameters ...
When the above query is executed, the query works as expected:
Now build the SAME query using a parameter ...
When the above query is executed, we get a different (incorrect) result ...
Parameterized queries do not seem to work with GeoJson values / objects ?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.