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

builtin: add json quote #7832

Merged
merged 4 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
builtin: add json quote integration test
  • Loading branch information
overbool committed Jan 2, 2019
commit 0457ac9064a25a23a68f2be6f7eff0488fbcc76c
2 changes: 1 addition & 1 deletion expression/builtin_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (c *jsonQuoteFunctionClass) getFunction(ctx sessionctx.Context, args []Expr
return nil, errors.Trace(err)
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETString, types.ETJson)
args[0].GetType().Flag &= ^mysql.ParseToJSONFlag
DisableParseJSONFlag4Expr(args[0])
sig := &builtinJSONQuoteSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_JsonQuoteSig)
return sig, nil
Expand Down
16 changes: 16 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,22 @@ func (s *testIntegrationSuite) TestFuncJSON(c *C) {
r = tk.MustQuery(`select json_unquote('hello'), json_unquote('world')`)
r.Check(testkit.Rows("hello world"))

r = tk.MustQuery(`select
json_quote(''),
json_quote('""'),
json_quote('a'),
json_quote('3'),
json_quote('{"a": "b"}'),
json_quote('{"a": "b"}'),
json_quote('hello,"quoted string",world'),
json_quote('hello,"宽字符",world'),
json_quote('Invalid Json string is OK'),
json_quote('1\u2232\u22322')
`)
r.Check(testkit.Rows(
`"" "\"\"" "a" "3" "{\"a\": \"b\"}" "{\"a\": \"b\"}" "hello,\"quoted string\",world" "hello,\"宽字符\",world" "Invalid Json string\tis OK" "1u2232u22322"`,
))

r = tk.MustQuery(`select json_extract(a, '$.a[1]'), json_extract(b, '$.b') from table_json`)
r.Check(testkit.Rows("\"2\" true", "<nil> <nil>"))

Expand Down
1 change: 1 addition & 0 deletions types/json/binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (bj BinaryJSON) Type() string {
}
}

// Quote is for JSON_QUOTE
func (bj BinaryJSON) Quote() string {
return strconv.Quote(hack.String(bj.GetString()))
}
Expand Down