Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Enhancement]: Let aggregate_records (MCP) compute multiple aggregations in one call (single GROUP BY pass)

未关闭
#3,725 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
冷清
技术栈
csharp, sql
领域
api, database

调研方向

从 MCP AggregateRecordsTool 的参数解析开始,然后跟踪 GroupByMetadata.Aggregations 和 BaseTSqlQueryBuilder.BuildAggregationColumns,包括现有的 GraphQL 路径。支持可选的 aggregations 数组,同时保留 function 和 field,并验证分组结果会生成一个带有可供 orderby 和 having 使用的别名的查询。

由索引模型根据 Issue 内容生成。

描述

cri enhancement mcp-server
Is your feature request related to a problem?

The MCP aggregate_records tool accepts only one aggregate per call (function + field). To retrieve several metrics over the same grouping, a client must issue N separate calls, each generating its own query with the same GROUP BY:

SELECT region, SUM(amount) FROM dbo.Sales WHERE ... GROUP BY region
SELECT region, AVG(amount) FROM dbo.Sales WHERE ... GROUP BY region
SELECT region, SUM(cost)   FROM dbo.Sales WHERE ... GROUP BY region

This scans the same rows and recomputes the same GROUP BY N times, plus N× query-planning / result-shaping / round-trip overhead. On large tables/views this is a real, avoidable database cost. Issuing the N calls concurrently on the client side only reduces latency — it does not reduce total DB work and can increase peak load/contention.

Describe the solution you'd like

Allow aggregate_records to accept multiple aggregations in a single call, producing one SELECT with one GROUP BY pass, e.g.:

{
  "entity": "Sales",
  "aggregations": [
    { "function": "sum", "field": "amount", "alias": "sum_amount" },
    { "function": "avg", "field": "amount", "alias": "avg_amount" },
    { "function": "sum", "field": "cost",   "alias": "sum_cost" }
  ],
  "groupby": ["region"],
  "orderby": ["sum_amount desc"]
}

which maps to a single query:

SELECT region, SUM(amount) AS sum_amount, AVG(amount) AS avg_amount, SUM(cost) AS sum_cost
FROM dbo.Sales
WHERE ...
GROUP BY region

orderby/having should be able to reference the aggregate aliases (e.g. sum_amount), consistent with how grouped results are projected.

Why this looks feasible

DAB already builds multi-aggregation queries internally for GraphQL: the shared SqlQueryStructure.GroupByMetadata.Aggregations is a List<AggregationOperation> and BaseTSqlQueryBuilder.BuildAggregationColumns(...) emits all requested aggregate expressions into a single SELECT. The MCP aggregate_records tool (AggregateRecordsTool) currently parses and loads only a single AggregationOperation. Extending its argument parsing to accept an array and pushing multiple AggregationOperations onto the existing structure would reuse the machinery GraphQL already relies on.

Backward compatibility

Keep the current single-metric form (function + field) working as-is; add the new optional aggregations array alongside it. Single-metric callers are unaffected; multi-metric callers opt in.

Additional context
  • Related: #3695 (a separate correctness bug in the aggregate ORDER BY for dwsql). This enhancement is independent of that fix.
  • Benefit is largest for wide analytical tables/views where several measures are aggregated over the same grouping in one logical request.
主要语言
C#
星标
1.5k
派生
371
平均合并
7 天 5 小时
30 天内合并 PR
8

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/data-api-builder 的其他 Issue

查看 Azure/data-api-builder 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。