-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
adding json_table
function
#1142
Changes from 32 commits
2ac0b17
07d307b
0a89181
da2958b
5a3e53e
db01268
9a687c9
23aeb31
2982d30
19477b5
f1314c8
855b347
a51c1db
6d93e54
5390ab1
9c2f480
2f76cb2
cfb9a6a
5dfcc74
05f39a7
ab28f59
03cedc8
50dedb6
47d4512
040422d
5b51930
01de00d
31d42ea
c28fee8
bd44c84
55dfbd3
a9e1cdf
a758d4d
56dce6e
f4966c3
07b674a
80aca34
fd72a9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2022 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package queries | ||
|
||
import ( | ||
"github.com/dolthub/go-mysql-server/sql" | ||
) | ||
|
||
var JSONTableQueryTests = []QueryTest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need some tests joining json tables to physical tables If they don't work, add skipped tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also tests where the expression for json data comes from a column, not a string literal |
||
{ | ||
Query: "SELECT * FROM JSON_TABLE('[{\"a\":1},{\"a\":2}]',\"$[*]\" COLUMNS(x varchar(100) path \"$.a\")) as tt;", | ||
Expected: []sql.Row{ | ||
{"1"}, | ||
{"2"}, | ||
}, | ||
}, | ||
{ | ||
Query: "SELECT * FROM JSON_TABLE('[{\"a\":1, \"b\":2},{\"a\":3, \"b\":4}]',\"$[*]\" COLUMNS(x int path \"$.a\", y int path \"$.b\")) as tt;", | ||
Expected: []sql.Row{ | ||
{1, 2}, | ||
{3, 4}, | ||
}, | ||
}, | ||
{ | ||
Query: "SELECT * FROM JSON_TABLE('[{\"a\":1.123, \"b\":2.234},{\"a\":3.345, \"b\":4.456}]',\"$[*]\" COLUMNS(x float path \"$.a\", y float path \"$.b\")) as tt;", | ||
Expected: []sql.Row{ | ||
{1.123, 2.234}, | ||
{3.345, 4.456}, | ||
}, | ||
}, | ||
{ | ||
Query: "SELECT * FROM JSON_TABLE(concat('[{},','{}]'),\"$[*]\" COLUMNS(x varchar(100) path \"$.a\",y varchar(100) path \"$.b\")) as t;", | ||
Expected: []sql.Row{ | ||
{nil, nil}, | ||
{nil, nil}, | ||
}, | ||
}, | ||
{ | ||
Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', \"$[*]\" COLUMNS(x int path \"$.a\")) as t1 join JSON_TABLE('[{\"a\":1},{\"a\":2}]', \"$[*]\" COLUMNS(x int path \"$.a\")) as t2;", | ||
Expected: []sql.Row{ | ||
{1, 1}, | ||
{1, 2}, | ||
{2, 1}, | ||
{2, 2}, | ||
}, | ||
}, | ||
{ | ||
Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', \"$[*]\" COLUMNS(x int path \"$.a\")) as t1 join one_pk order by x;", | ||
Expected: []sql.Row{ | ||
{1, 0, 0, 1, 2, 3, 4}, | ||
{1, 1, 10, 11, 12, 13, 14}, | ||
{1, 2, 20, 21, 22, 23, 24}, | ||
{1, 3, 30, 31, 32, 33, 34}, | ||
{2, 0, 0, 1, 2, 3, 4}, | ||
{2, 1, 10, 11, 12, 13, 14}, | ||
{2, 2, 20, 21, 22, 23, 24}, | ||
{2, 3, 30, 31, 32, 33, 34}, | ||
}, | ||
}, | ||
{ | ||
Query: "select * from one_pk join JSON_TABLE('[{\"a\":1},{\"a\":2}]', \"$[*]\" COLUMNS(x int path \"$.a\")) as t1 order by x;", | ||
Expected: []sql.Row{ | ||
{0, 0, 1, 2, 3, 4, 1}, | ||
{1, 10, 11, 12, 13, 14, 1}, | ||
{2, 20, 21, 22, 23, 24, 1}, | ||
{3, 30, 31, 32, 33, 34, 1}, | ||
{0, 0, 1, 2, 3, 4, 2}, | ||
{1, 10, 11, 12, 13, 14, 2}, | ||
{2, 20, 21, 22, 23, 24, 2}, | ||
{3, 30, 31, 32, 33, 34, 2}, | ||
}, | ||
}, | ||
{ | ||
Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', \"$[*]\" COLUMNS(x int path \"$.a\")) as t1 union select * from JSON_TABLE('[{\"b\":3},{\"b\":4}]', \"$[*]\" COLUMNS(y int path \"$.b\")) as t2", | ||
Expected: []sql.Row{ | ||
{1}, | ||
{2}, | ||
{3}, | ||
{4}, | ||
}, | ||
}, | ||
{ | ||
Query: "select * from one_pk where pk in (select x from JSON_TABLE('[{\"a\":1},{\"a\":2}]', \"$[*]\" COLUMNS(x int path \"$.a\")) as t)", | ||
Expected: []sql.Row{ | ||
{1, 10, 11, 12, 13, 14}, | ||
{2, 20, 21, 22, 23, 24}, | ||
}, | ||
}, | ||
{ | ||
Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', \"$[*]\" COLUMNS(x int path \"$.a\")) t1 where x in (select y from JSON_TABLE('[{\"b\":1},{\"b\":100}]', \"$[*]\" COLUMNS(y int path \"$.b\")) as t2)", | ||
Expected: []sql.Row{ | ||
{1}, | ||
}, | ||
}, | ||
{ | ||
Query: "SELECT * FROM JSON_TABLE((select t from json_table_tables),\"$[*]\" COLUMNS(i int path \"$.a\", j int path \"$.b\", k int path \"$.c\", l int path \"$.d\")) as tt;", | ||
Expected: []sql.Row{ | ||
{1, nil, nil, nil}, | ||
{nil, 2, nil, nil}, | ||
{nil, nil, 3, nil}, | ||
{nil, nil, nil, 4}, | ||
}, | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
exec | ||
CREATE TABLE `json_table_tables` ( | ||
`t` varchar(100) | ||
) | ||
---- | ||
|
||
exec | ||
insert into json_table_tables values | ||
('[{"a": 1},{"b": 2},{"c": 3},{"d": 4}]'); | ||
---- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
?
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.
There are rounding errors when using
float64
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.
There really shouldn't be, this is a sign of a bug
Floats should round-trip with no precision loss
Does it come from parsing JSON?