7051: DataTable Renderer should discard the key of a single value table #17535
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.
Description:
This is a start towards fixing #7051
The return value when requesting a single column has now changed.
old: {"value":3161}
new: {"nb_visits":315}
The way I have done that has had some reasonably significant impacts on both JSON and XML output so I am unsure if I'm on the right track.
The core problem is that Renderer::convertDataTableToArray() contains a check for an array of length one. If an array of length 1 is detected its key is discarded and a single value is returned instead of an array. Instead of this array
you just get this instead
float(315)
meaning that the array key has been discarded. There are then places that check for the single value where there should be an array and wrap that value in an array with key 'value'.It does seem preferable in my mind for Renderer::convertDataTableToArray() to just return an array regardless of length and let code closer to output generation decide if a single element array requires special handling for display purposes but I could well be off base.
The code as it currently is in this PR has had various effects other than those above.
<result>2526</result>
but get this instead.This is the same format returned when you request multiple columns.
Again, this is the same format that is already return for multi-column queries.
Options:
Decide we want the column name preserved everywhere meaning that single column queries will match the format of multi-column queries. Both json and xml outputs will change substantially to bring single column queries in line with multi-column queries and downstream consumers will need to be updated where they expect the single column specific output format.
Decide we want the old behaviour in some contexts and I add in code to detect single column arrays and make the output match what it did previously. Make the tests pass essentially with very few test updates.
Something else?
Review