Fixing bug with handling output columns - MySql#1647
Merged
Conversation
Aniruddh25
reviewed
Aug 24, 2023
Aniruddh25
approved these changes
Aug 24, 2023
Collaborator
Aniruddh25
left a comment
There was a problem hiding this comment.
LGTM, Thanks for fixing this!
abhishekkumams
approved these changes
Aug 24, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Link to file:
data-api-builder/src/Core/Resolvers/MySqlQueryBuilder.cs
Line 293 in 5e3874e
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 finalselectionsand 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.InsertColumnsis same asstructure.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 referencestructure.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 atstructure.Values[index](structure.Values essentially stores parameter names for each of the insert columns).What is this change?
insertColumnsToParamNamewhich 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 ofstructure.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.