[MDEV-25149] JSON_TABLE: Inconsistency in implicit data type conversion Created: 2021-03-15 Updated: 2021-04-21 Resolved: 2021-04-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Affects Version/s: | N/A |
| Fix Version/s: | 10.6.0 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Elena Stepanova | Assignee: | Alexey Botchkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Description |
|
This was a part of code review comments / changes. The example is taken from the review comments as is:
At that point, intcol value in the first row was 0, indicating that the value was retrieved, and an implicit string => number conversion was performed. The question was raised on what grounds this conversion occurs, and why there is no warning about it; eventually the result was changed to the default-on-error, which it is now:
Personally, I am fine with this decision; but to my understanding, the implicit conversion is a general MariaDB approach applied in a variety of cases, so this change may contradict the "official line". Here is the basic example:
I suggest to make sure that serg is okay with the chosen JSON_TABLE behavior, otherwise there is a big chance that later the result will be re-considered and changed for the sake of consistency. In this case it's better to do it right from the beginning than change the behavior later. Of course the review note about a missing warning was also valid and should be taken into account if the logic changes back to returning the converted value. |
| Comments |
| Comment by Elena Stepanova [ 2021-03-15 ] | ||||||||||||||||
|
Besides, here is still the same problem with a slightly different example, so the behavior is already inconsistent even within the current JSON_TABLE implementation:
MySQL returns NULL which indicates an error:
| ||||||||||||||||
| Comment by Elena Stepanova [ 2021-03-23 ] | ||||||||||||||||
|
Raising to a technical blocker. While actual fixing can very well be delayed (even indefinitely), the general approach must be defined, agreed upon, documented and later complied with; otherwise individual fixes upon assorted complaints will only create more discrepancies. What needs to be decided is:
| ||||||||||||||||
| Comment by Sergei Golubchik [ 2021-03-23 ] | ||||||||||||||||
|
The standard specifies is:
So, in the example from the bug description, the result should be 0, 123, 5678, 5678. In the example of the first comment the correct result is "f". Perhaps there should be warnings, as with CAST. Better to actually reuse the CAST code, so that if we'll ever get some strict mode variant where CAST("asd" AS INT) is an error then JSON_TABLE would automatically use the new behavior. | ||||||||||||||||
| Comment by Sergei Petrunia [ 2021-04-09 ] | ||||||||||||||||
|
Agree with serg's comment. I think there should be a warning. The problem with reusing the code from CAST function is that there's no single piece of code to reuse: CAST is implemented by many Items:
also search for create_typecast_item | ||||||||||||||||
| Comment by Alexey Botchkov [ 2021-04-14 ] | ||||||||||||||||
|
That's the change i propose to begin with
| ||||||||||||||||
| Comment by Sergei Petrunia [ 2021-04-14 ] | ||||||||||||||||
|
If we take this patch and run the example from the bug description, we get
That is, converting the first "a":"asd" into integer now produces a warning, but the default '5678' on error rule is still fired. This is not what was described in Serg's comment above. | ||||||||||||||||
| Comment by Sergei Petrunia [ 2021-04-14 ] | ||||||||||||||||
|
Candidate patch: https://gist.github.com/spetrunia/5f4f13ef5fdf91ca1f343bcb34f3c815 | ||||||||||||||||
| Comment by Alexey Botchkov [ 2021-04-15 ] | ||||||||||||||||
|
Here is my version of the fix. | ||||||||||||||||
| Comment by Sergei Petrunia [ 2021-04-15 ] | ||||||||||||||||
|
Review input provided on Slack | ||||||||||||||||
| Comment by Sergei Petrunia [ 2021-04-16 ] | ||||||||||||||||
|
Ok to push |