我有一个包含具有以下结构的文档的集合:
{
"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.Core
nuget 包库调用 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 尝试过这个,但是它在数据浏览器中工作的事实让我认为这不是模拟器的能力问题。