Conversation
| {false}, | ||
| }, | ||
| }, | ||
| { |
There was a problem hiding this comment.
Also add tests for json_type returning "NULL" and "DOUBLE". You can express a double in a JSON literal using scientific notation (ie "{a: 10e2}")
There was a problem hiding this comment.
I think I was wrong about being able to use scientific notation here.
I think we should add the following tests, to make sure that we respect round-trip conversions of types:
SELECT json_type(json_extract(json_object("a", cast(10 as double)), "$.a")) -> "DOUBLE"
SELECT json_type(json_extract(json_object("a", cast(10 as unsigned)), "$.a")) -> "UNSIGNED INTEGER"
SELECT json_type(json_extract(json_object("a", cast(10 as signed)), "$.a")) -> "INTEGER"
SELECT json_type(json_extract(json_object("a", cast(10 as decimal)), "$.a")) -> "DECIMAL"
It's possible that the way we currently store JSON causes some of these to not work properly. We can disable those tests if it's out of scope to fix them now. But we should still have them as tests.
There was a problem hiding this comment.
didn't see this comment sorry!
test are added here:
#2355
| row sql.Row | ||
| exp interface{} | ||
| err bool | ||
| }{ |
There was a problem hiding this comment.
Add a test here for DECIMAL. You may have to explicitly pass in a Decimal object to the Row.
There was a problem hiding this comment.
Raw decimals can't be used in json_type(); it has to go through a cast(<dec> to json).
There is an enginetest for this
There was a problem hiding this comment.
Ah, gotcha. Sounds good then.
| { | ||
| Query: "select json_type(cast(cast(1 as unsigned) as json));", | ||
| Expected: []sql.Row{ | ||
| {"UNSIGNED INTEGER"}, |
There was a problem hiding this comment.
oooh, nice work! The docs don't mention "UNSIGNED INTEGER" as a possible response, but that's exactly what MySQL returns! Good job reversing engineering MySQL's behavior here.
| case map[string]interface{}: | ||
| return "OBJECT", nil | ||
| default: | ||
| return "OPAQUE", nil |
There was a problem hiding this comment.
Any way to trigger OPAQUE? I don't think I saw that in any of the tests.
There was a problem hiding this comment.
I haven't found a query that spits out OPAQUE in MySQL or dolt
enginetest/queries/queries.go
Outdated
| {"TIME"}, | ||
| }, | ||
| }, | ||
| // missing year cast |
There was a problem hiding this comment.
Are we still missing something for this? I saw we added cast to year syntax in vitess and some code in GMS for casting. Just curious what else is needed for this one.
There was a problem hiding this comment.
oops this test should not be skipped; will fix
MySQL Docs:
https://dev.mysql.com/doc/refman/8.0/en/json-attribute-functions.html#function_json-type
Companion PR:
dolthub/vitess#314