Query with ENDSWITH and ternary operator in where clause returning 500
See original GitHub issueDescribe the bug We have a SQL query like mentioned below in our code. It contains ENDSWITH and ternary operator in where clause. This query was working fine so far. From 18th April, it started returning 500 status code when called from Cosmos SDK. And it is returning 400 status code when executed in cosmos db explorer.
To Reproduce Below query is failing when executed using Cosmos SDK or explorer.
SELECT t.TransactionTime
FROM transactions t
WHERE
t.AccountId = '1234567'
AND
ENDSWITH(t.TransactionTime, 'Z') ? (t.State.Amount > 100) : (t.State.Amount > 50)
Expected behavior The query should exectute successfully and return results.
Actual behavior
Following error is returned by .NET Cosmos sdk.
Response status code does not indicate success: 500 Substatus: 0 Reason: (Message: {"Errors":["An unknown error occurred while processing this request. If the issue persists, please contact Azure Support: http://aka.ms/azure-support"]}ActivityId: 67e93a37-e7cd-4ea4-9242-05e53a27c537, Request URI: /apps/a678790d-5f32-4849-9590-eb510b1dc384/services/0875fa50-d545-4585-b34f-31f659d73970/partitions/1fcc5c29-be34-4d4a-ac85-8c4e9dbab4c1/replicas/132316600554466458p/, RequestStats: RequestStartTime: 2020-04-21T17:08:02.1367988Z, RequestEndTime: 2020-04-21T17:08:02.1418128Z, Number of regions attempted:1ResponseTime: 2020-04-21T17:08:02.1418128Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-uksouth1-fd4.documents.azure.com:14447/apps/a678790d-5f32-4849-9590-eb510b1dc384/services/0875fa50-d545-4585-b34f-31f659d73970/partitions/1fcc5c29-be34-4d4a-ac85-8c4e9dbab4c1/replicas/132316600554466458p/, LSN: 2166514, GlobalCommittedLsn: 2166514, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 500, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#2166514, UsingLocalLSN: True, TransportException: null, ResourceType: Document, OperationType: Query, SDK: Windows/10.0.14393 cosmos-netstandard-sdk/3.4.1).
Following error is returned when trying to execute query in Cosmos DB explorer:
Failed to query item for container transactions: {"code":400,"body":{"code":"BadRequest","message":"Gateway Failed to Retrieve Query Plan: Message: \r\nActivityId: d2fb7214-e560-492e-ae65-7c39e50e341e, Microsoft.Azure.Documents.Common/2.10.0, Microsoft.Azure.Documents.Common/2.10.0"},"headers":{"access-control-allow-credentials":"true","access-control-allow-origin":"https://cosmos.azure.com","content-type":"application/json","strict-transport-security":"max-age=31536000","x-ms-activity-id":"d2fb7214-e560-492e-ae65-7c39e50e341e","x-ms-gatewayversion":"version=2.10.0","x-ms-throttle-retry-count":0,"x-ms-throttle-retry-wait-time-ms":0},"activityId":"d2fb7214-e560-492e-ae65-7c39e50e341e"}
Environment summary SDK Version: 3.4.1 OS Version : Windows
Additional context I have tried below queries and they work fine:
SELECT t.TransactionTime, ENDSWITH(t.TransactionTime, 'Z') ? (t.State.Amount > 100) : (t.State.Amount > 50) As ValidAmount
FROM transactions t
WHERE t.AccountId = '1234567'
SELECT t.TransactionTime
FROM transactions t
WHERE
t.AccountId = '1234567'
AND
(t.TransactionTime > '2020-01-23T00:00:00.0000000Z') ? (t.Amount > 100) : (t.Amount > 50)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top GitHub Comments
Hi @tushar-kesare,
We have identified an issue on the server side with the query that you reported.
While we’re working on the fix, here’s a workaround that should unblock you:
Update
ENDSWITH(t.TransactionTime, 'Z')
toENDSWITH(t.TransactionTime, t.foo ?? 'Z')
where foo is a property that does not exist.
Thanks for reporting this issue.
There was a deployment that should have fixed this issue. Please reopen if not the case.