1

我有一个包含具有以下结构的文档的集合:

{
    "Identifier": 1,
    "Values": {
        "value1": "33806",
        "value2": "10",
        "value3": "0"
    },
   ...
}

我创建了一个 UDF 来从Values字典中提取键:

function getKeys(dictionary) {
    let result = [];
    for (var key in dictionary) {
        result.push(key);
    }
    return result;
}

我有一个使用 UDF 查找Values字典中所有不同键的查询。以下代码使用Microsoft.Azure.DocumentDB.Corenuget 包库调用 CosmosDB:

var query = $@"
    SELECT DISTINCT
    VALUE i
    FROM
    (
        SELECT
        VALUE
        {{
             'keys': udf.getKeys(c.Values), 
             'id': c.Identifier
        }}
        FROM c
        WHERE c.Identifier = @Identifier
    ) AS dt
    JOIN i in dt.keys";

    var parameters = new SqlParameterCollection(new[]
    {
        new SqlParameter("@Identifier", identifier)
    });

    var documentQuery = store.Query(new SqlQuerySpec(query, parameters));

这是针对 Azure CosmosDB 模拟器运行的。当我通过http://localhost:8081.

通过 .NET 客户端运行查询时,出现以下错误:

Microsoft.Azure.Documents.BadRequestException:消息:{"errors":[{"severity":"Error","location":{"start":25,"end":33},"code":"SC1001" "message":"语法错误,'DISTINCT' 附近的语法不正确。"}]},Windows/10.0.16299 documentdb-netcore-sdk/1.9.1 ---> System.Runtime.InteropServices.COMException: 来自 HRESULT 的异常: 0x800A0B00

我还没有针对真正的CosmosDB 尝试过这个,但是它在数据浏览器中工作的事实让我认为这不是模拟器的能力问题。

4

1 回答 1

1

我还没有针对真正的 CosmosDB 尝试过这个,但是它在数据浏览器中工作的事实让我认为这不是模拟器的能力问题。

distinctcosmos db 模拟器或真实版本在 SQL 中支持。(https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/6719531-provide-support-for-distinct?page=1&per_page=20

我测试了你的代码,documentdb-netcore-sdk v.2.0.0它工作正常。根据此问题文档,该错误似乎在 2.0.0-preview 或更高版本中得到解决。您可以更新软件包的版本。

于 2018-09-13T09:45:04.987 回答