Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Dec 14, 2022
1 parent a91d22f commit fd1bd44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
16 changes: 3 additions & 13 deletions expression/builtin_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,28 +772,18 @@ func (c *jsonMemberOfFunctionClass) getFunction(ctx sessionctx.Context, args []E
if err := c.verifyArgs(args); err != nil {
return nil, err
}

argTps := []types.EvalType{args[0].GetType().EvalType(), types.ETJson}
argTps := []types.EvalType{types.ETJson, types.ETJson}
bf, err := newBaseBuiltinFuncWithTp(ctx, c.funcName, args, types.ETInt, argTps...)
if err != nil {
return nil, err
}
DisableParseJSONFlag4Expr(args[0])
sig := &builtinJSONMemberOfSig{bf}
return sig, nil
}

func (b *builtinJSONMemberOfSig) evalInt(row chunk.Row) (res int64, isNull bool, err error) {
var target types.BinaryJSON
if b.args[0].GetType().EvalType() != types.ETJson {
eval, err := b.args[0].Eval(row)
if err != nil || eval.IsNull() {
return 0, eval.IsNull(), err
}
target = types.CreateBinaryJSON(eval.GetValue())
} else {
target, isNull, err = b.args[0].EvalJSON(b.ctx, row)
}

target, isNull, err := b.args[0].EvalJSON(b.ctx, row)
if isNull || err != nil {
return res, isNull, err
}
Expand Down
6 changes: 3 additions & 3 deletions types/json_binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,9 @@ func OverlapsBinaryJSON(obj, target BinaryJSON) bool {
case JSONTypeCodeArray:
if target.TypeCode == JSONTypeCodeArray {
for i := 0; i < obj.GetElemCount(); i++ {
o := obj.arrayGetElem(i)
o := obj.ArrayGetElem(i)
for j := 0; j < target.GetElemCount(); j++ {
if CompareBinaryJSON(o, target.arrayGetElem(j)) == 0 {
if CompareBinaryJSON(o, target.ArrayGetElem(j)) == 0 {
return true
}
}
Expand All @@ -1138,7 +1138,7 @@ func OverlapsBinaryJSON(obj, target BinaryJSON) bool {
}
elemCount := obj.GetElemCount()
for i := 0; i < elemCount; i++ {
if CompareBinaryJSON(obj.arrayGetElem(i), target) == 0 {
if CompareBinaryJSON(obj.ArrayGetElem(i), target) == 0 {
return true
}
}
Expand Down

0 comments on commit fd1bd44

Please sign in to comment.