json: Fix JSON SQL serialization and ensure to run tests#12861
json: Fix JSON SQL serialization and ensure to run tests#12861frouioui merged 1 commit intovitessio:mainfrom
Conversation
There was a bug in the JSON SQL serialization. It would directly serialize a raw JSON string which is wrong, we need to serialize the decoded string into an SQL string instead. The tests didn't expose this since they didn't actually run. This removes the checks since all versions we run these tests against now support JSON. Lastly it also updates the comparison in the tests to use jsondiff which provides far superior output on failures and allows us to remove the ajson dependency entirely. We also remove the old binlog json parser. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
If a new flag is being introduced:
If a workflow is added or modified:
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
|
|
||
| func (v *Value) marshalSQLInternal(top bool, dst []byte) []byte { | ||
| switch v.t { | ||
| switch v.Type() { |
There was a problem hiding this comment.
This ensures we never see a typeRawString but always a properly decoded TypeString.
| skipTest := true | ||
| flavors := []string{"mysql80", "mysql57"} | ||
| for _, flavor := range flavors { | ||
| if strings.EqualFold(env.Flavor, flavor) { |
There was a problem hiding this comment.
env.Flavor contains the GTID flavor which is always MySQL56 and never any of the values we check against. So we were never running these tests.
| compare, s := jsondiff.Compare(qr.Rows[i][1].Raw(), []byte(row[1]), &opts) | ||
| if compare != jsondiff.FullMatch { | ||
| t.Errorf("Diff:\n%s\n", s) | ||
| } |
There was a problem hiding this comment.
This gives us a far more superior error format when it fails and makes it much easier to debug what is going on.
|
Without the marshalling fix it shows an error like: You can see here that things like |
|
@rohit-nayak-ps @mattlord @shlomi-noach The issues with these tests not running also made me dig in and there's a bunch more cases where tests are not actually running. Those are for other JSON related tests but also for generated columns tests. Those latter tests seem broken though, or maybe vreplication has been long broken for these worst case. I have opened a draft PR that showcases this (it's on top of the fixes here) in #12862 |
There was a problem hiding this comment.
Oops, thanks for catching and fixing this early!
I confirmed locally that, by adding "first line\\r\\nsecond line\\rline with escapes\\\\ \\r\\n" to the e2e json test cases, it fails before this PR and succeeds on this PR. (will add this in #12862)
@rohit-nayak-ps Don't think that's needed? Since the test fixes here in this PR already uncover it? So we already have tests that cover this escaping? We can add more though but don't think it's strictly needed. |
I agree that it is already tested, so this is general paranoia I guess, borne out by the issue you found of unit tests not running! |
There was a bug in the JSON SQL serialization. It would directly serialize a raw JSON string which is wrong, we need to serialize the decoded string into an SQL string instead.
The tests didn't expose this since they didn't actually run. This removes the checks since all versions we run these tests against now support JSON.
Lastly it also updates the comparison in the tests to use jsondiff which provides far superior output on failures and allows us to remove the ajson dependency entirely. We also remove the old binlog json parser.
Related Issue(s)
This was broken since #12761
Checklist