Skip to content

Commit

Permalink
clear warning
Browse files Browse the repository at this point in the history
  • Loading branch information
pingyu committed Jan 5, 2019
1 parent 3db8610 commit f05d889
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions expression/builtin_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,15 @@ func (c *jsonSearchFunctionClass) getFunction(ctx sessionctx.Context, args []Exp

func (b *builtinJSONSearchSig) evalJSON(row chunk.Row) (res json.BinaryJSON, isNull bool, err error) {
// json_doc
obj, isNull, err := b.args[0].EvalJSON(b.ctx, row)
var obj json.BinaryJSON
obj, isNull, err = b.args[0].EvalJSON(b.ctx, row)
if isNull || err != nil {
return res, isNull, errors.Trace(err)
}

// one_or_all
containType, isNull, err := b.args[1].EvalString(b.ctx, row)
var containType string
containType, isNull, err = b.args[1].EvalString(b.ctx, row)
if isNull || err != nil {
return res, isNull, errors.Trace(err)
}
Expand All @@ -788,13 +790,15 @@ func (b *builtinJSONSearchSig) evalJSON(row chunk.Row) (res json.BinaryJSON, isN
}

// search_str & escape_char
searchStr, isNull, err := b.args[2].EvalString(b.ctx, row)
var searchStr string
searchStr, isNull, err = b.args[2].EvalString(b.ctx, row)
if isNull || err != nil {
return res, isNull, errors.Trace(err)
}
escape := byte('\\')
if len(b.args) >= 4 {
escapeStr, isNull, err := b.args[3].EvalString(b.ctx, row)
var escapeStr string
escapeStr, isNull, err = b.args[3].EvalString(b.ctx, row)
if err != nil {
return res, isNull, errors.Trace(err)
}
Expand Down
7 changes: 5 additions & 2 deletions expression/builtin_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ func (s *testEvaluatorSuite) TestJSONSearch(c *C) {
{[]interface{}{jsonString, `all`, `10`, nil, `$[1]`}, `"$[1][0].k"`, true},
{[]interface{}{jsonString, `all`, `10`, nil, `$[1][0]`}, `"$[1][0].k"`, true},
{[]interface{}{jsonString, `all`, `abc`, nil, `$[2]`}, `"$[2].x"`, true},
{[]interface{}{jsonString, `all`, `abc`, nil, `$[2]`, `$[0]`}, `["$[2].x", "$[0]"]`, true},
{[]interface{}{jsonString, `all`, `abc`, nil, `$[2]`, `$[2]`}, `"$[2].x"`, true},

// search pattern
{[]interface{}{jsonString, `all`, `%a%`}, `["$[0]", "$[2].x"]`, true},
Expand Down Expand Up @@ -681,9 +683,10 @@ func (s *testEvaluatorSuite) TestJSONSearch(c *C) {
c.Assert(err, IsNil)
switch x := t.expected.(type) {
case string:
j1, err := json.ParseBinaryFromString(x)
var j1, j2 json.BinaryJSON
j1, err = json.ParseBinaryFromString(x)
c.Assert(err, IsNil)
j2 := d.GetMysqlJSON()
j2 = d.GetMysqlJSON()
cmp := json.CompareBinary(j1, j2)
//fmt.Println(j1, j2)
c.Assert(cmp, Equals, 0)
Expand Down
5 changes: 3 additions & 2 deletions types/json/binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func decodeEscapedUnicode(s []byte) (char [4]byte, size int, err error) {
return
}

// quoteString escape spe for JSON_QUOTE
// quoteString escapes interior quote and other characters for JSON_QUOTE
// https://dev.mysql.com/doc/refman/5.7/en/json-creation-functions.html#function_json-quote
// TODO: add JSON_QUOTE builtin
func quoteString(s string) string {
Expand Down Expand Up @@ -959,7 +959,8 @@ func (bj BinaryJSON) Walk(walkFn BinaryJSONWalkFunc, pathExprList ...PathExpress
fullpath := PathExpression{legs: make([]pathLeg, 0, 32), flags: pathExpressionFlag(0)}
if len(pathExprList) > 0 {
for _, pathExpr := range pathExprList {
stop, err := bj.extractToCallback(pathExpr, doWalk, fullpath)
var stop bool
stop, err = bj.extractToCallback(pathExpr, doWalk, fullpath)
if stop || err != nil {
return err
}
Expand Down

0 comments on commit f05d889

Please sign in to comment.