[Bug]: aggregate_records (MCP) generates an invalid default ORDER BY SUM(<raw column>) against the grouped derived table on dwsql (Microsoft Fabric Warehouse) → Invalid column name
I maintainer di solito rispondono entro 1 giorno
@souvikghosh04 ci sta già lavorando.
Dal 7/7/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
What happened?
Summary
When calling the MCP aggregate_records tool with a numeric aggregate (sum/avg/min/max) plus groupby against a dwsql data source (Microsoft Fabric Warehouse), DAB emits a query whose outer default ORDER BY re-applies the aggregate over the pre-aggregation raw column (e.g. ORDER BY SUM([alias].[amount]) DESC). The outer query's FROM is the grouped derived table, which only exposes the group-by columns and the aliased aggregate ([sum_amount]), not the raw column [amount]. SQL Server therefore fails name resolution with:
Msg 207, Level 16, State 1: Invalid column name 'amount'.
The inner grouped subquery is correct; only the auto-generated outer ORDER BY is wrong. As a result, sum/avg aggregations via MCP are unusable on Fabric Warehouse.
Environment
- Data API builder: 2.0.9 (
Microsoft.DataApiBuilder 2.0.9) — also reproduced on 2.0.8 - Data source
database-type:dwsql - Backend: Microsoft Fabric Warehouse (SQL analytics endpoint,
*.datawarehouse.fabric.microsoft.com) - Surface: MCP SQL Server (
runtime.mcp), toolaggregate_records - Entity: a
view(dbo.my_view) withkey-fieldsdefined - OS: Windows 11
Configuration (relevant excerpt)
All object names, column names, and connection-string names below are synthetic and minimized for reproduction. The permission setting is also a minimal sample for reproduction only.
{
"data-source": {
"database-type": "dwsql",
"connection-string": "@env('my-connection-string')",
"options": { "set-session-context": false }
},
"runtime": {
"mcp": {
"enabled": true,
"path": "/mcp",
"dml-tools": {
"describe-entities": true,
"read-records": true,
"aggregate-records": true
}
}
},
"entities": {
"my_view": {
"source": { "object": "dbo.my_view", "type": "view", "key-fields": ["id"] },
"permissions": [ { "role": "anonymous", "actions": [ { "action": "read" } ] } ]
}
}
}
Repro steps
- Point DAB (
database-type: dwsql) at a Fabric Warehouse and expose a view with a numeric column (hereamount) and a string column (category). - Start DAB:
dab start --LogLevel Debug. - Call the MCP
aggregate_recordstool:
{
"method": "tools/call",
"params": {
"name": "aggregate_records",
"arguments": {
"entity": "my_view",
"function": "sum",
"field": "amount",
"groupby": ["category"]
}
}
}
- The call fails with
InternalServerError: Invalid column name 'amount'.
Note: passing an explicit
orderby(e.g.["category asc"]) does not change the generated SQL — the broken defaultORDER BY SUM(<raw column>) DESCis still emitted, so there is no client-side workaround.
Actual generated SQL (from --LogLevel Debug)
SELECT COALESCE('['+STRING_AGG('{'+N'"category":' + ISNULL('"'+STRING_ESCAPE([category],'json')+'"','null')+', '+N'"sum_amount":' + ISNULL(STRING_ESCAPE(CONVERT(NVARCHAR(MAX), [sum_amount]),'json'),'null')+'}',', ')+']','[]')
FROM (
SELECT TOP 101
[dbo_my_view].[category] AS [category],
sum([dbo_my_view].[amount]) AS [sum_amount]
FROM [dbo].[my_view] AS [dbo_my_view]
WHERE 1 = 1
GROUP BY [dbo_my_view].[category]
) AS [dbo_my_view]
ORDER BY SUM([dbo_my_view].[amount]) DESC -- <-- invalid: [amount] is not a column of the derived table
The derived table aliased [dbo_my_view] only exposes [category] and [sum_amount]. The outer ORDER BY SUM([dbo_my_view].[amount]) references the raw, pre-aggregation column [amount], which does not exist at that scope → Invalid column name 'amount'.
Expected behavior
The default ordering should reference the projected aggregate alias, not re-aggregate the raw column in the outer scope:
) AS [dbo_my_view]
ORDER BY [sum_amount] DESC
(Equivalently, DAB should either order by the aliased aggregation output or omit the default ORDER BY when the client did not request one.)
Additional context / scoping
read_recordson the same entity and the same column (SELECT amount ...) works correctly — the column and permissions are fine.aggregate_recordswithfunction: "count",field: "*"works (it does not reference a raw measure column).- Only the numeric aggregates (
sum/avg/min/max) withgroupbyfail, and the failure is entirely in the auto-generated outerORDER BY. - Running the intended query by hand against the Warehouse (grouped subquery +
ORDER BY [sum_amount]) succeeds, confirming the issue is the generated SQL, not the data/schema/permissions. - This looks related to the
dwsqlquery builder's default order-by generation for aggregations (cf. previous fix "failing MCP aggregate_records tool caused by groupby default value", #3294).
Error detail
fail: Azure.DataApiBuilder.Core.Resolvers.IQueryExecutor[0]
Query execution error due to:
Invalid column name 'amount'.
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'amount'.
at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.ExecuteQueryAgainstDbAsync[TResult](...) in /_/src/Core/Resolvers/QueryExecutor.cs:line 296
Error Number: 207, State: 1, Class: 16
Version
2.0.9
What database are you using?
Azure SQL (dwsql(Microsoft Fabric Warehouse))
What hosting model are you using?
Local (including CLI)
Which API approach are you accessing DAB through?
MCP
Code of Conduct
- I agree to follow this project's Code of Conduct
- Lingua principale
- C#
- Stelle
- 1.5k
- Fork
- 371
- Merge medio
- 9g 2h
- PR unite (30g)
- 10
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Azure/data-api-builder
-
pgsql
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/data-api-builder#3598 ·
I maintainer di solito rispondono entro 1 giorno
-
2.x cli mcp-server
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/data-api-builder#3576 ·
I maintainer di solito rispondono entro 1 giorno
-
2.x health-endpoint
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/data-api-builder#3570 ·
I maintainer di solito rispondono entro 1 giorno
-
2.x telemetry
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/data-api-builder#3564 ·
I maintainer di solito rispondono entro 1 giorno
-
2.x telemetry
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Azure/data-api-builder#3562 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Azure/data-api-builder
Issue simili
-
.NET bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
RayWangQvQ/BiliBiliToolPro#1144 ·
I maintainer di solito rispondono entro 1 giorno
-
area-System.Numerics.Tensors untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dotnet/runtime#134691 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
microsoft/DataFactory.MCP#121 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
unoplatform/uno.templates#2277 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/fluentui-blazor#5344 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno