question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query with ENDSWITH and ternary operator in where clause returning 500

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sboshracommented, Apr 22, 2020

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') to ENDSWITH(t.TransactionTime, t.foo ?? 'Z')

where foo is a property that does not exist.

Thanks for reporting this issue.

0reactions
bchong95commented, May 16, 2020

There was a deployment that should have fixed this issue. Please reopen if not the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't we have return in the ternary operator?
The ternary operator evaluates to an expression and expressions can't contain a return statement (how would that behave if you were to ...
Read more >
Program to Find the Largest Number using Ternary Operator
The task is to write a program to find the largest number using ternary operator among: Two Numbers; Three Numbers; Four Numbers. Examples:....
Read more >
NRQL reference
A detailed reference list of clauses and functions in NRQL, the New Relic query language.
Read more >
Log Operators Cheat Sheet
The length operator returns the number of characters in a string. You can use it in where clauses or to create new fields....
Read more >
Comparison and Conditional functions
This function takes pairs of <condition> and <value> arguments and returns the first value for which the condition evaluates to TRUE.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found