-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expression: fix unexpect invalid json text error when query with json_extract
#21720
Conversation
There is no reward for this challenge pull request, so you can request a reward from @XuHuaiyu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please add some test cases.
data := hack.Slice(val) | ||
if mysql.HasParseToJSONFlag(b.tp.Flag) && json2.Valid(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probabily we don't need use encoding/json
to check the validity, just ParseBInaryFromString and if err is not nil we will fall back to CreateBinary?
@TszKitLo40 Also, would you please check if your PR could fix #13710 ? |
And I aslo have test #13710, it uses the same logic |
I am not sure whether it is the best choice to fix this issue, because it make cause some test case fail. Do you think we can should cast a common string to json? And I don't know why should we check |
I am not sure as well, but I do have concerns about implicit type conversion, perhaps we need to investigate more on MySQLs behavior and to find out if it really a valid fix. Examples like
|
But in this case, it seems that we must cast a string to json. I don't know why do we need to check |
I think it is not always the case, if there is an invalid json string in the argument lists, MySQL would not convert it into json.
|
It seems that it is hard to know whether we should convert the string to json. |
Note that
will produce 0 row in MySQL, and only
will do the work. So I think the fix is not to convert string to json, instead, we can
|
It seems resonable, but if we do that, it seems that we need to change the execution planner? |
@TszKitLo40 Not necessarily, we could do it during runtime, just around the lines you just changed. |
But in the lines I changed, we don't know the type of value to be compared, we need to know it so that we can decide whether we should cast it to json or keep it as string. |
Yeah, I found that it need to change planner. If you don't mind, I would like to take over this issue (I've almost figured out the fix), but you are welcomed to look at other issues on #20804 |
OK, feel free to take over this issue. And I will close this PR. |
What problem does this PR solve?
Issue Number: close #11883
Problem Summary:
What is changed and how it works?
What's Changed:
fix unexpect invalid json text error when query with
json_extract
How it Works:
When a string can't be casted to json, use
json.CreateBinary
Related changes
Check List
Tests
Release note