Skip to content

Commit

Permalink
test: fix data race in cast as array (#40277)
Browse files Browse the repository at this point in the history
close #40276
  • Loading branch information
xiongjiwei committed Jan 3, 2023
1 parent 5327d07 commit 9aaa93e
Showing 1 changed file with 4 additions and 13 deletions.
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

0 comments on commit 9aaa93e

Please sign in to comment.