Azure / azure-cosmosdb-java

Java Async SDK for SQL API of Azure Cosmos DB
MIT License
54 stars 61 forks source link

select DISTINCT results in "incorrect syntax near 'DISTINCT'" #311

Open ghost opened 4 years ago

ghost commented 4 years ago

The statement

SELECT DISTINCT c.machine_id FROM c (WHERE clause omitted for brevity)

works perfectly fine in the cosmosdb data explorer

Same statement issued via Java SDK

DocumentClient documentClient = new DocumentClient(endPoint, masterKey, ConnectionPolicy.GetDefault(), ConsistencyLevel.Session);
FeedOptions feedOptions = new FeedOptions();
feedOptions.setEnableCrossPartitionQuery(true);

documentClient.queryDocuments(
            "dbs/data/colls/someCollection",
            "SELECT DISTINCT c.machine_id FROM c", feedOptions)

results in

java.lang.IllegalArgumentException: {"errors":[{"severity":"Error","location":{"start":7,"end":15},"code":"SC1001","message":"Syntax error, incorrect syntax near 'DISTINCT'."}]}
    at com.microsoft.azure.documentdb.internal.ServiceJNIWrapper.throwIfFailed(ServiceJNIWrapper.java:69) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.internal.ServiceJNIWrapper.getSerializedPartitionKeyRangesFromQuery(ServiceJNIWrapper.java:238) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.internal.ServiceJNIWrapper.getPartitionKeyRangesFromQuery(ServiceJNIWrapper.java:255) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.internal.query.QueryPartitionProvider.getPartitionQueryExcecutionInfo(QueryPartitionProvider.java:50) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.internal.query.ProxyQueryExecutionContext.<init>(ProxyQueryExecutionContext.java:52) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.internal.query.QueryExecutionContextFactory.createQueryExecutionContext(QueryExecutionContextFactory.java:23) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.QueryIterable.createQueryExecutionContext(QueryIterable.java:70) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.QueryIterable.reset(QueryIterable.java:115) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.QueryIterable.<init>(QueryIterable.java:57) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.DocumentClient.queryDocuments(DocumentClient.java:1168) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.DocumentClient.queryDocuments(DocumentClient.java:1127) ~[azure-documentdb-2.4.6.jar:na]
    at com.microsoft.azure.documentdb.DocumentClient.queryDocuments(DocumentClient.java:1106) ~[azure-documentdb-2.4.6.jar:na]

Environment summary Windows 10 OpenJDK 11 Spring-Boot 2.2.2 com.microsoft.azure:azure-documentdb:2.4.6