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

expression: do not set ParseToJSONFlag to a JSON column #8564

Merged
merged 7 commits into from Dec 12, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions expression/builtin_compare.go
Expand Up @@ -1170,6 +1170,11 @@ func (c *compareFunctionClass) generateCmpSigs(ctx sessionctx.Context, args []Ex
if tp == types.ETJson {
// In compare, if we cast string to JSON, we shouldn't parse it.
for i := range args {
// If arg is a JSON column, we do not need to set the
// ParseToJSONFlag to it.
if _, isColumn := args[i].(*Column); isColumn {
Copy link
Member

@zz-jason zz-jason Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract a common function to do it? There are a lot of duplicated code and comments.

continue
}
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
winoros marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
30 changes: 24 additions & 6 deletions expression/builtin_json.go
Expand Up @@ -174,7 +174,10 @@ func (c *jsonUnquoteFunctionClass) getFunction(ctx sessionctx.Context, args []Ex
return nil, errors.Trace(err)
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETString, types.ETJson)
args[0].GetType().Flag &= ^mysql.ParseToJSONFlag
// If arg is a JSON column, we do not need to set the ParseToJSONFlag to it.
if _, ok := args[0].(*Column); !ok {
args[0].GetType().Flag &= ^mysql.ParseToJSONFlag
}
sig := &builtinJSONUnquoteSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_JsonUnquoteSig)
return sig, nil
Expand Down Expand Up @@ -218,7 +221,10 @@ func (c *jsonSetFunctionClass) getFunction(ctx sessionctx.Context, args []Expres
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETJson, argTps...)
for i := 2; i < len(args); i += 2 {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
// If arg is a JSON column, we do not need to set the ParseToJSONFlag to it.
if _, ok := args[i].(*Column); !ok {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
}
}
sig := &builtinJSONSetSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_JsonSetSig)
Expand Down Expand Up @@ -258,7 +264,10 @@ func (c *jsonInsertFunctionClass) getFunction(ctx sessionctx.Context, args []Exp
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETJson, argTps...)
for i := 2; i < len(args); i += 2 {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
// If arg is a JSON column, we do not need to set the ParseToJSONFlag to it.
if _, ok := args[i].(*Column); !ok {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
}
}
sig := &builtinJSONInsertSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_JsonInsertSig)
Expand Down Expand Up @@ -298,7 +307,10 @@ func (c *jsonReplaceFunctionClass) getFunction(ctx sessionctx.Context, args []Ex
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETJson, argTps...)
for i := 2; i < len(args); i += 2 {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
// If arg is a JSON column, we do not need to set the ParseToJSONFlag to it.
if _, ok := args[i].(*Column); !ok {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
}
}
sig := &builtinJSONReplaceSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_JsonReplaceSig)
Expand Down Expand Up @@ -434,7 +446,10 @@ func (c *jsonObjectFunctionClass) getFunction(ctx sessionctx.Context, args []Exp
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETJson, argTps...)
for i := 1; i < len(args); i += 2 {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
// If arg is a JSON column, we do not need to set the ParseToJSONFlag to it.
if _, ok := args[i].(*Column); !ok {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
}
}
sig := &builtinJSONObjectSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_JsonObjectSig)
Expand Down Expand Up @@ -497,7 +512,10 @@ func (c *jsonArrayFunctionClass) getFunction(ctx sessionctx.Context, args []Expr
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETJson, argTps...)
for i := range args {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
// If arg is a JSON column, we do not need to set the ParseToJSONFlag to it.
if _, ok := args[i].(*Column); !ok {
args[i].GetType().Flag &= ^mysql.ParseToJSONFlag
}
}
sig := &builtinJSONArraySig{bf}
sig.setPbCode(tipb.ScalarFuncSig_JsonArraySig)
Expand Down