Skip to content

Commit

Permalink
expression: wrap some read action in EvalContext to functions (#50530)
Browse files Browse the repository at this point in the history
ref #49090
  • Loading branch information
lcwangchao authored Jan 22, 2024
1 parent 25afff4 commit c47f4c9
Show file tree
Hide file tree
Showing 35 changed files with 802 additions and 776 deletions.
12 changes: 6 additions & 6 deletions pkg/expression/builtin_arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (s *builtinArithmeticMinusIntSig) evalInt(ctx EvalContext, row chunk.Row) (
if isNull || err != nil {
return 0, isNull, err
}
forceToSigned := ctx.GetSessionVars().SQLMode.HasNoUnsignedSubtractionMode()
forceToSigned := sqlMode(ctx).HasNoUnsignedSubtractionMode()
isLHSUnsigned := mysql.HasUnsignedFlag(s.args[0].GetType().GetFlag())
isRHSUnsigned := mysql.HasUnsignedFlag(s.args[1].GetType().GetFlag())

Expand Down Expand Up @@ -723,8 +723,8 @@ func (s *builtinArithmeticDivideDecimalSig) evalDecimal(ctx EvalContext, row chu
if err == types.ErrDivByZero {
return c, true, handleDivisionByZeroError(ctx)
} else if err == types.ErrTruncated {
sc := ctx.GetSessionVars().StmtCtx
err = sc.HandleTruncate(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c))
tc := typeCtx(ctx)
err = tc.HandleTruncate(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c))
} else if err == nil {
_, frac := c.PrecisionAndFrac()
if frac < s.baseBuiltinFunc.tp.GetDecimal() {
Expand Down Expand Up @@ -824,7 +824,7 @@ func (s *builtinArithmeticIntDivideIntSig) evalInt(ctx EvalContext, row chunk.Ro
}

func (s *builtinArithmeticIntDivideDecimalSig) evalInt(ctx EvalContext, row chunk.Row) (ret int64, isNull bool, err error) {
sc := ctx.GetSessionVars().StmtCtx
ec := errCtx(ctx)
var num [2]*types.MyDecimal
for i, arg := range s.args {
num[i], isNull, err = arg.EvalDecimal(ctx, row)
Expand All @@ -839,11 +839,11 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(ctx EvalContext, row chun
return 0, true, handleDivisionByZeroError(ctx)
}
if err == types.ErrTruncated {
err = sc.HandleTruncate(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c))
err = ec.HandleError(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c))
}
if err == types.ErrOverflow {
newErr := errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c)
err = sc.HandleError(newErr)
err = ec.HandleError(newErr)
}
if err != nil {
return 0, true, err
Expand Down
12 changes: 6 additions & 6 deletions pkg/expression/builtin_arithmetic_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (b *builtinArithmeticDivideDecimalSig) vecEvalDecimal(ctx EvalContext, inpu
y := buf.Decimals()
var to types.MyDecimal
var frac int
sc := ctx.GetSessionVars().StmtCtx
ec := errCtx(ctx)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
Expand All @@ -95,7 +95,7 @@ func (b *builtinArithmeticDivideDecimalSig) vecEvalDecimal(ctx EvalContext, inpu
result.SetNull(i, true)
continue
} else if err == types.ErrTruncated {
if err = sc.HandleTruncate(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", to)); err != nil {
if err = ec.HandleError(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", to)); err != nil {
return err
}
} else if err == nil {
Expand Down Expand Up @@ -383,7 +383,7 @@ func (b *builtinArithmeticMinusIntSig) vecEvalInt(ctx EvalContext, input *chunk.
rhi64s := rh.Int64s()
resulti64s := result.Int64s()

forceToSigned := ctx.GetSessionVars().SQLMode.HasNoUnsignedSubtractionMode()
forceToSigned := sqlMode(ctx).HasNoUnsignedSubtractionMode()
isLHSUnsigned := mysql.HasUnsignedFlag(b.args[0].GetType().GetFlag())
isRHSUnsigned := mysql.HasUnsignedFlag(b.args[1].GetType().GetFlag())

Expand Down Expand Up @@ -564,7 +564,7 @@ func (b *builtinArithmeticIntDivideDecimalSig) vectorized() bool {
}

func (b *builtinArithmeticIntDivideDecimalSig) vecEvalInt(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
sc := ctx.GetSessionVars().StmtCtx
ec := errCtx(ctx)
n := input.NumRows()
var err error
var buf [2]*chunk.Column
Expand Down Expand Up @@ -605,10 +605,10 @@ func (b *builtinArithmeticIntDivideDecimalSig) vecEvalInt(ctx EvalContext, input
continue
}
if err == types.ErrTruncated {
err = sc.HandleTruncate(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c))
err = ec.HandleError(errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c))
} else if err == types.ErrOverflow {
newErr := errTruncatedWrongValue.GenWithStackByArgs("DECIMAL", c)
err = sc.HandleError(newErr)
err = ec.HandleError(newErr)
}
if err != nil {
return err
Expand Down
Loading

0 comments on commit c47f4c9

Please sign in to comment.