Commit 032eff9
Fix column mapping in GroupBy and aggregation queries to ensure corre… (#3750)
## Why make this change?
There is a bug when running aggregation queries, wherein if a mapping
backed column is present, the aggregation fails since it references the
surfaced column and not the backed column.
This pull request improves how group-by queries with mapped (aliased)
columns are handled in SQL generation and adds a regression test to
ensure correct behavior. The main focus is to ensure that SQL queries
reference the backing (database) column names in the SELECT and GROUP BY
clauses, while projecting the correct exposed (mapped) names in the
results.
## What is this change?
* Updated `ProcessGroupByField` and `ProcessGroupByFieldSelections` in
`SqlQueryStructure.cs` to ensure that the backing (database) column name
is used in the SQL query, while the exposed (mapped) field name is used
as the label in the results. This resolves previous issues where the
SELECT clause referenced the exposed name instead of the actual database
column.
[[1]](diffhunk://#diff-4b3df270873038f36ec2f627091120b7aafa271c0e2a2d257380f90602f5a298L907-R908)
[[2]](diffhunk://#diff-4b3df270873038f36ec2f627091120b7aafa271c0e2a2d257380f90602f5a298L956-R956)
## How was this tested?
- [x] Integration Tests
- [X] Unit Tests
* Added a new test method
`TestSupportForGroupByAggregationWithMappedColumns` in
`MsSqlGraphQLQueryTests.cs` to verify that group-by fields and
aggregations both resolve to the correct backing columns, and that
results are projected under the mapped names. This prevents regressions
on mapped column handling in group-by queries.
* Added missing import for
`Azure.DataApiBuilder.Service.GraphQLBuilder.Queries` in
`MsSqlGraphQLQueryTests.cs` to support the new test.
---------
Co-authored-by: ARPIT GUPTA <guptaar@microsoft.com>1 parent 7341bc2 commit 032eff9
3 files changed
Lines changed: 339 additions & 11 deletions
File tree
- src
- Core/Resolvers
- Sql Query Structures
- Service.Tests/SqlTests/GraphQLQueryTests
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
908 | | - | |
| 908 | + | |
909 | 909 | | |
910 | 910 | | |
911 | 911 | | |
| |||
953 | 953 | | |
954 | 954 | | |
955 | 955 | | |
956 | | - | |
| 956 | + | |
957 | 957 | | |
958 | 958 | | |
959 | 959 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| |||
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
65 | | - | |
| 69 | + | |
66 | 70 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 71 | + | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
0 commit comments