Commit ecc0778
authored
Fixing bug with handling output columns - MySql (#1647)
## Why make this change?
Fix #1648
Currently Output columns are incorrectly handled while generating SELECT
query for MySql after update via UPSERT operation.
Relevant code snippet:
<img width="635" alt="image"
src="https://github.com/Azure/data-api-builder/assets/34566234/b835c486-0028-4e84-941c-a7eae9cc6916">
Link to file:
https://github.com/Azure/data-api-builder/blob/5e3874e6a77179523d270a0358efdcbbea9762fa/src/Core/Resolvers/MySqlQueryBuilder.cs#L293
**Where is the bug?**
As we can observe that in the attached code snippet, we are processing
the output columns one by one. The IF block for line 293 is hit when we
find a column which is present in the `structure.InsertColumns`. We add
such a column to the final `selections` and increment the index:
`selections.Add($"{structure.Values[index]} AS {quotedColName}");`
`index++;`
**What have we assumed here?**
We have assumed that the order of columns in `structure.InsertColumns`
is same as `structure.OutputColumns`. Well that is certainly not true as
output columns can have columns other that insertColumns and even if the
columns are same, the order can differ. **So, we cannot just reference
`structure.Values[index]` on line 293 and increment the index on line
294.**. We need to be sure that this output column, which is also an
insert column, corresponds to this parameter name at
`structure.Values[index]` (structure.Values essentially stores parameter
names for each of the insert columns).
## What is this change?
- Instead of incrementing index, we need a dictionary
`insertColumnsToParamName` which certainly tells us as to what paramName
does each of the insertColumns map to. **This also prevents an O(n)
lookup** that we were doing to check if the output column is present in
the list of `structure.InsertColumns`.
## How was this tested?
Will be adding tests in:
#1596, if required at all.
The existing tests are still passing which confirms the change is good.1 parent 854154e commit ecc0778
1 file changed
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| 283 | + | |
| 284 | + | |
283 | 285 | | |
284 | 286 | | |
285 | 287 | | |
286 | | - | |
287 | 288 | | |
288 | 289 | | |
289 | 290 | | |
290 | | - | |
291 | | - | |
| 291 | + | |
| 292 | + | |
292 | 293 | | |
293 | | - | |
294 | | - | |
| 294 | + | |
295 | 295 | | |
296 | | - | |
| 296 | + | |
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| |||
0 commit comments