Skip to content
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

JSON string comparison seems broken (change in behavior from v0.6.0 and v0.10.0) #474

Closed
andremarianiello opened this issue Jun 17, 2021 · 5 comments · Fixed by #475
Closed

Comments

@andremarianiello
Copy link

In a MySQL server

mysql> select json_extract('{"xid":"hello"}', '$.xid') = "hello";
+----------------------------------------------------+
| json_extract('{"xid":"hello"}', '$.xid') = "hello" |
+----------------------------------------------------+
|                                                  1 |
+----------------------------------------------------+
1 row in set (0.00 sec)

mysql> select json_unquote(json_extract('{"xid":"hello"}', '$.xid')) = "hello";
+------------------------------------------------------------------+
| json_unquote(json_extract('{"xid":"hello"}', '$.xid')) = "hello" |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)

With go-mysql-server v0.6.0

MySQL [(none)]> select json_extract('{"xid":"hello"}', '$.xid') = "hello";
+--------------------------------------------------------+
| JSON_EXTRACT("{\"xid\":\"hello\"}", "$.xid") = "hello" |
+--------------------------------------------------------+
|                                                      1 |
+--------------------------------------------------------+
1 row in set (0.001 sec)

MySQL [(none)]> select json_unquote(json_extract('{"xid":"hello"}', '$.xid')) = "hello";
+----------------------------------------------------------------------+
| JSON_UNQUOTE(JSON_EXTRACT("{\"xid\":\"hello\"}", "$.xid")) = "hello" |
+----------------------------------------------------------------------+
|                                                                    1 |
+----------------------------------------------------------------------+
1 row in set (0.001 sec)

With go-mysql-server v0.10.0

MySQL [(none)]> select json_extract('{"xid":"hello"}', '$.xid') = "hello";
+----------------------------------------------------+
| json_extract('{"xid":"hello"}', '$.xid') = "hello" |
+----------------------------------------------------+
|                                                  0 |
+----------------------------------------------------+
1 row in set (0.001 sec)

MySQL [(none)]> select json_unquote(json_extract('{"xid":"hello"}', '$.xid')) = "hello";
ERROR 1105 (HY000): incompatible conversion to SQL type: LONGTEXT

The comparison is now false and unquoting fails completely. I believe the root cause is sql.LongText.Convert failing to handle JSONDocument values, so Equals.Compare ends up converting the json value to nil.

@andremarianiello
Copy link
Author

Would you like a PR that fixes this behavior?

@timsehn
Copy link
Contributor

timsehn commented Jun 21, 2021 via email

@andremarianiello
Copy link
Author

andremarianiello commented Jun 21, 2021

Looks like @bheni made a change it HEAD that fixes the unquoted behavior, but the quoted behavior still doesn't match with MySQL.

With 8571009

MySQL [(none)]> select json_extract('{"xid":"hello"}', '$.xid') = "hello";
+----------------------------------------------------+
| json_extract('{"xid":"hello"}', '$.xid') = "hello" |
+----------------------------------------------------+
|                                                  0 |
+----------------------------------------------------+
1 row in set (0.001 sec)

MySQL [(none)]> select json_unquote(json_extract('{"xid":"hello"}', '$.xid')) = "hello";
+------------------------------------------------------------------+
| json_unquote(json_extract('{"xid":"hello"}', '$.xid')) = "hello" |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+
1 row in set (0.002 sec)

I'll make a PR to fix the quoted behavior.

@andremarianiello
Copy link
Author

Nevermind, looks like I was beaten to the punch. Thanks @ajnavarro !

@ajnavarro
Copy link
Contributor

Woops! Sorry @andremarianiello ! We were on sync ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants