Classcast error while using CosmosDB query with COUNT and VALUE
See original GitHub issueHi!
I use Java to write a function that reads data from a CosmosDB instance. I encounter a problem when I use a query like SELECT VALUE COUNT(1) FROM Messages m
.
I get a class cast exception: System.Private.CoreLib: Exception while executing function: Functions.ReadDevicesLastSeenHistogram. Anonymously Hosted DynamicMethods Assembly: Unable to cast object of type ‘Newtonsoft.Json.Linq.JValue’ to type ‘Newtonsoft.Json.Linq.JObject’.
I am using version 3.0.3 of the CosmosDB extension.
Repro steps
@FunctionName("ReadDevicesLastSeenHistogram")
public HttpResponseMessage readDevicesLastSeenHistogram(@HttpTrigger(name = "req",
methods = {HttpMethod.GET},
route = "statistics/lastSeenHistogram",
authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<Void>> request,
@CosmosDBInput(name="databaseAll",
databaseName = "IoTMessagesDatabase",
collectionName = "DevicesLastDocumentCollection",
connectionStringSetting = "siriusiotdb_DOCUMENTDB",
partitionKey = "/deviceId",
sqlQuery = "SELECT VALUE COUNT(1) FROM Messages m") String allCount,
@CosmosDBInput(name="databaseMinus1",
databaseName = "IoTMessagesDatabase",
collectionName = "DevicesLastDocumentCollection",
connectionStringSetting = "siriusiotdb_DOCUMENTDB",
partitionKey = "/deviceId",
sqlQuery = "SELECT VALUE COUNT(1) FROM Messages m WHERE m._ts>udf.timestampMinusDays(1)") String dayCount){
Map<String,Long> result=new HashMap<>();
result.put("all",Long.valueOf(allCount));
result.put("1day",Long.valueOf(dayCount));
return request.createResponseBuilder(HttpStatus.OK).body(result).build();
}
Expected behavior
No class cast error.
Actual behavior
System.Private.CoreLib: Exception while executing function: Functions.ReadDevicesLastSeenHistogram. Anonymously Hosted DynamicMethods Assembly: Unable to cast object of type ‘Newtonsoft.Json.Linq.JValue’ to type ‘Newtonsoft.Json.Linq.JObject’
Known workarounds
None
Related information
- Java Function App
- CosmosDB extension version 3.0.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
The fix will be available in extension 3.0.10 coming in the next week.
I can try to send a PR this week with this requested change.