在 x64 平台上执行聚合查询时出现异常
Exception occurs performing aggregate queries on x64 platform
当 运行 使用聚合的查询时,我收到以下异常:
Microsoft.Azure.Documents.BadRequestException:
{"Errors":["Cross partition query only supports 'VALUE <AggreateFunc>' for aggregates."]}
---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A0B00
我的查询码是:
var store = "1234";
var sumResults = client.CreateDocumentQuery(
UriFactory.CreateDocumentCollectionUri("my-data-db", "my-collection"),
$"SELECT SUM(t.totalAmount) FROM t where t.siteData.siteID = '{store}'");
我花了一段时间才弄清楚,当构建平台设置为 x86 时它工作正常,但当设置为 x64 时失败。
我使用的是最新版本的软件包 1.12.2
关于如何使 x64 版本工作的任何想法?
根据您的描述,我使用 Microsoft.Azure.DocumentDB 1.12.2 在 DocomentDB Emulator 和 Azure DocumentDB 上测试了类似的查询。经过一些试验,我发现此问题仅在您对 DocomentDB 模拟器(我当前的版本是 1.11.136.2)和您的项目使用 SQL 聚合函数(例如 COUNT、MIN、MAX、SUM 和 AVG)时出现基于 x64 构建。
正如这位官员 document 提到的有关 Azure DocumentDB 的聚合:
Aggregate support has been rolled out to all DocumentDB production datacenters. You can start running aggregate queries against your existing DocumentDB accounts or provision new DocumentDB accounts via the SDKs, REST API, or the Azure Portal. You must however download the latest version of the SDKs in order to perform cross-partition aggregate queries or use LINQ aggregate operators in .NET.
我假设您可以按如下方式利用 LINQ 的聚合:
var amount=client.CreateDocumentQuery<DocEntity>("/dbs/{your-db-id}/colls/{your-collection-id}",
new FeedOptions { MaxDegreeOfParallelism = -1 })
.Where(r => r.siteID == "1234")
.Sum(r=>r.totalAmount);
我们可以发现上面的查询会生成以下查询:
{"query":"SELECT VALUE Sum(root[\"totalAmount\"]) FROM root WHERE (root[\"siteID\"] =\"1234\") "}
更多细节,你可以参考这个tutorial。
您需要在查询中输入值,如下所示
SELECT 值计数 (1)
来自 C
当 运行 使用聚合的查询时,我收到以下异常:
Microsoft.Azure.Documents.BadRequestException:
{"Errors":["Cross partition query only supports 'VALUE <AggreateFunc>' for aggregates."]}
---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A0B00
我的查询码是:
var store = "1234";
var sumResults = client.CreateDocumentQuery(
UriFactory.CreateDocumentCollectionUri("my-data-db", "my-collection"),
$"SELECT SUM(t.totalAmount) FROM t where t.siteData.siteID = '{store}'");
我花了一段时间才弄清楚,当构建平台设置为 x86 时它工作正常,但当设置为 x64 时失败。
我使用的是最新版本的软件包 1.12.2
关于如何使 x64 版本工作的任何想法?
根据您的描述,我使用 Microsoft.Azure.DocumentDB 1.12.2 在 DocomentDB Emulator 和 Azure DocumentDB 上测试了类似的查询。经过一些试验,我发现此问题仅在您对 DocomentDB 模拟器(我当前的版本是 1.11.136.2)和您的项目使用 SQL 聚合函数(例如 COUNT、MIN、MAX、SUM 和 AVG)时出现基于 x64 构建。
正如这位官员 document 提到的有关 Azure DocumentDB 的聚合:
Aggregate support has been rolled out to all DocumentDB production datacenters. You can start running aggregate queries against your existing DocumentDB accounts or provision new DocumentDB accounts via the SDKs, REST API, or the Azure Portal. You must however download the latest version of the SDKs in order to perform cross-partition aggregate queries or use LINQ aggregate operators in .NET.
我假设您可以按如下方式利用 LINQ 的聚合:
var amount=client.CreateDocumentQuery<DocEntity>("/dbs/{your-db-id}/colls/{your-collection-id}",
new FeedOptions { MaxDegreeOfParallelism = -1 })
.Where(r => r.siteID == "1234")
.Sum(r=>r.totalAmount);
我们可以发现上面的查询会生成以下查询:
{"query":"SELECT VALUE Sum(root[\"totalAmount\"]) FROM root WHERE (root[\"siteID\"] =\"1234\") "}
更多细节,你可以参考这个tutorial。
您需要在查询中输入值,如下所示
SELECT 值计数 (1) 来自 C