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

test: fix data race in cast as array #40277

Merged
merged 3 commits into from
Jan 3, 2023
Merged
Changes from all commits
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
17 changes: 4 additions & 13 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ func (b *castJSONAsArrayFunctionSig) Clone() builtinFunc {
return newSig
}

// fakeSctx is used to ignore the sql mode, `cast as array` should always return error if any.
var fakeSctx = &stmtctx.StatementContext{InInsertStmt: true}

func (b *castJSONAsArrayFunctionSig) evalJSON(row chunk.Row) (res types.BinaryJSON, isNull bool, err error) {
val, isNull, err := b.args[0].EvalJSON(b.ctx, row)
if isNull || err != nil {
Expand All @@ -474,20 +477,8 @@ func (b *castJSONAsArrayFunctionSig) evalJSON(row chunk.Row) (res types.BinaryJS
if f == nil {
return types.BinaryJSON{}, false, ErrNotSupportedYet.GenWithStackByArgs("CAS-ing JSON to the target type")
}
sc := b.ctx.GetSessionVars().StmtCtx
originalOverflowAsWarning := sc.OverflowAsWarning
originIgnoreTruncate := sc.IgnoreTruncate
originTruncateAsWarning := sc.TruncateAsWarning
sc.OverflowAsWarning = false
sc.IgnoreTruncate = false
sc.TruncateAsWarning = false
defer func() {
sc.OverflowAsWarning = originalOverflowAsWarning
sc.IgnoreTruncate = originIgnoreTruncate
sc.TruncateAsWarning = originTruncateAsWarning
}()
for i := 0; i < val.GetElemCount(); i++ {
item, err := f(sc, val.ArrayGetElem(i), ft)
item, err := f(fakeSctx, val.ArrayGetElem(i), ft)
if err != nil {
return types.BinaryJSON{}, false, err
}
Expand Down