Skip to content

Commit 1925b6e

Browse files
Merge pull request #326 from dolthub/andy/json-support-spec
Added function stubs for unimplemented JSON functions
2 parents 01d3dd8 + 9b338a2 commit 1925b6e

File tree

7 files changed

+1045
-0
lines changed

7 files changed

+1045
-0
lines changed

enginetest/queries.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4045,6 +4045,87 @@ var BrokenQueries = []QueryTest{
40454045
{nil, nil, 6},
40464046
},
40474047
},
4048+
{
4049+
Query: "SELECT json_array() FROM dual;",
4050+
},
4051+
{
4052+
Query: "SELECT json_array_append() FROM dual;",
4053+
},
4054+
{
4055+
Query: "SELECT json_array_insert() FROM dual;",
4056+
},
4057+
{
4058+
Query: "SELECT json_contains() FROM dual;",
4059+
},
4060+
{
4061+
Query: "SELECT json_contains_path() FROM dual;",
4062+
},
4063+
{
4064+
Query: "SELECT json_depth() FROM dual;",
4065+
},
4066+
{
4067+
Query: "SELECT json_insert() FROM dual;",
4068+
},
4069+
{
4070+
Query: "SELECT json_keys() FROM dual;",
4071+
},
4072+
{
4073+
Query: "SELECT json_length() FROM dual;",
4074+
},
4075+
{
4076+
Query: "SELECT json_merge_patch() FROM dual;",
4077+
},
4078+
{
4079+
Query: "SELECT json_merge_preserve() FROM dual;",
4080+
},
4081+
{
4082+
Query: "SELECT json_object() FROM dual;",
4083+
},
4084+
{
4085+
Query: "SELECT json_overlaps() FROM dual;",
4086+
},
4087+
{
4088+
Query: "SELECT json_pretty() FROM dual;",
4089+
},
4090+
{
4091+
Query: "SELECT json_quote() FROM dual;",
4092+
},
4093+
{
4094+
Query: "SELECT json_remove() FROM dual;",
4095+
},
4096+
{
4097+
Query: "SELECT json_replace() FROM dual;",
4098+
},
4099+
{
4100+
Query: "SELECT json_schema_valid() FROM dual;",
4101+
},
4102+
{
4103+
Query: "SELECT json_schema_validation_report() FROM dual;",
4104+
},
4105+
{
4106+
Query: "SELECT json_set() FROM dual;",
4107+
},
4108+
{
4109+
Query: "SELECT json_search() FROM dual;",
4110+
},
4111+
{
4112+
Query: "SELECT json_storage_free() FROM dual;",
4113+
},
4114+
{
4115+
Query: "SELECT json_storage_size() FROM dual;",
4116+
},
4117+
{
4118+
Query: "SELECT json_type() FROM dual;",
4119+
},
4120+
{
4121+
Query: "SELECT json_table() FROM dual;",
4122+
},
4123+
{
4124+
Query: "SELECT json_valid() FROM dual;",
4125+
},
4126+
{
4127+
Query: "SELECT json_value() FROM dual;",
4128+
},
40484129
}
40494130

40504131
var VersionedQueries = []QueryTest{
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2021 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package aggregation
16+
17+
import (
18+
"github.com/dolthub/go-mysql-server/sql"
19+
"gopkg.in/src-d/go-errors.v1"
20+
)
21+
22+
// ErrUnsupportedJSONFunction is returned when a unsupported JSON function is called.
23+
var ErrUnsupportedJSONFunction = errors.NewKind("unsupported JSON function: %s")
24+
25+
// JSON_ARRAYAGG(col_or_expr) [over_clause]
26+
//
27+
// JSONArrayAgg Aggregates a result set as a single JSON array whose elements consist of the rows. The order of elements
28+
// in this array is undefined. The function acts on a column or an expression that evaluates to a single value. Returns
29+
// NULL if the result contains no rows, or in the event of an error.
30+
//
31+
// https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_json-arrayagg
32+
//
33+
// see also: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-normalization
34+
type JSONArrayAgg struct {
35+
sql.Expression
36+
}
37+
38+
var _ sql.FunctionExpression = JSONArrayAgg{}
39+
40+
// NewJSONArrayAgg creates a new JSONArrayAgg function.
41+
func NewJSONArrayAgg(args ...sql.Expression) (sql.Expression, error) {
42+
return nil, ErrUnsupportedJSONFunction.New(JSONArrayAgg{}.FunctionName())
43+
}
44+
45+
// FunctionName implements sql.FunctionExpression
46+
func (j JSONArrayAgg) FunctionName() string {
47+
return "json_arrayagg"
48+
}
49+
50+
51+
// JSON_OBJECTAGG(key, value) [over_clause]
52+
//
53+
// JSONObjectAgg Takes two column names or expressions as arguments, the first of these being used as a key and the
54+
// second as a value, and returns a JSON object containing key-value pairs. Returns NULL if the result contains no rows,
55+
// or in the event of an error. An error occurs if any key name is NULL or the number of arguments is not equal to 2.
56+
//
57+
// https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_json-objectagg
58+
//
59+
// see also: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-normalization
60+
type JSONObjectAgg struct {
61+
sql.Expression
62+
}
63+
64+
var _ sql.FunctionExpression = JSONObjectAgg{}
65+
66+
// NewJSONObjectAgg creates a new JSONArrayAgg function.
67+
func NewJSONObjectAgg(args ...sql.Expression) (sql.Expression, error) {
68+
return nil, ErrUnsupportedJSONFunction.New(JSONObjectAgg{}.FunctionName())
69+
}
70+
71+
// FunctionName implements sql.FunctionExpression
72+
func (j JSONObjectAgg) FunctionName() string {
73+
return "json_objectagg"
74+
}
75+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2021 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package function
16+
17+
import (
18+
"github.com/dolthub/go-mysql-server/sql"
19+
)
20+
21+
// JSON_CONTAINS(target, candidate[, path])
22+
//
23+
// JSONContains indicates by returning 1 or 0 whether a given candidate JSON document is contained within a target JSON
24+
// document, or, if a path argument was supplied, whether the candidate is found at a specific path within the target.
25+
// Returns NULL if any argument is NULL, or if the path argument does not identify a section of the target document.
26+
// An error occurs if target or candidate is not a valid JSON document, or if the path argument is not a valid path
27+
// expression or contains a * or ** wildcard. To check only whether any data exists at the path, use
28+
// JSON_CONTAINS_PATH() instead.
29+
//
30+
// The following rules define containment:
31+
// - A candidate scalar is contained in a target scalar if and only if they are comparable and are equal. Two scalar
32+
// values are comparable if they have the same JSON_TYPE() types, with the exception that values of types INTEGER
33+
// and DECIMAL are also comparable to each other.
34+
// - A candidate array is contained in a target array if and only if every element in the candidate is contained in
35+
// some element of the target.
36+
// - A candidate non-array is contained in a target array if and only if the candidate is contained in some element
37+
// of the target.
38+
/// - A candidate object is contained in a target object if and only if for each key in the candidate there is a key
39+
// with the same name in the target and the value associated with the candidate key is contained in the value
40+
// associated with the target key.
41+
// Otherwise, the candidate value is not contained in the target document.
42+
//
43+
// https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-contains
44+
type JSONContains struct {
45+
sql.Expression
46+
}
47+
48+
var _ sql.FunctionExpression = JSONContains{}
49+
50+
// NewJSONContains creates a new JSONContains function.
51+
func NewJSONContains(args ...sql.Expression) (sql.Expression, error) {
52+
return nil, ErrUnsupportedJSONFunction.New(JSONContains{}.FunctionName())
53+
}
54+
55+
// FunctionName implements sql.FunctionExpression
56+
func (j JSONContains) FunctionName() string {
57+
return "json_contains"
58+
}

sql/expression/function/json_extract.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import (
2424
"github.com/dolthub/go-mysql-server/sql"
2525
)
2626

27+
// JSON_EXTRACT(json_doc, path[, path] ...)
28+
//
2729
// JSONExtract extracts data from a json document using json paths.
30+
// https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-extract
2831
type JSONExtract struct {
2932
JSON sql.Expression
3033
Paths []sql.Expression

0 commit comments

Comments
 (0)