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: add missing setPbCode() for some arithmetic function #12864

Merged
merged 3 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions expression/builtin_arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,15 @@ func (c *arithmeticIntDivideFunctionClass) getFunction(ctx sessionctx.Context, a
bf.tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticIntDivideIntSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IntDivideInt)
return sig, nil
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETInt, types.ETDecimal, types.ETDecimal)
if mysql.HasUnsignedFlag(lhsTp.Flag) || mysql.HasUnsignedFlag(rhsTp.Flag) {
bf.tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticIntDivideDecimalSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IntDivideDecimal)
return sig, nil
}

Expand Down Expand Up @@ -834,6 +836,7 @@ func (c *arithmeticModFunctionClass) getFunction(ctx sessionctx.Context, args []
bf.tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticModRealSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_ModReal)
return sig, nil
} else if lhsEvalTp == types.ETDecimal || rhsEvalTp == types.ETDecimal {
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETDecimal, types.ETDecimal, types.ETDecimal)
Expand All @@ -842,13 +845,15 @@ func (c *arithmeticModFunctionClass) getFunction(ctx sessionctx.Context, args []
bf.tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticModDecimalSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_ModDecimal)
return sig, nil
} else {
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETInt, types.ETInt, types.ETInt)
if mysql.HasUnsignedFlag(lhsTp.Flag) {
bf.tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticModIntSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_ModInt)
return sig, nil
}
}
Expand Down
15 changes: 15 additions & 0 deletions expression/builtin_arithmetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/testutil"
"github.com/pingcap/tipb/go-tipb"
)

func (s *testEvaluatorSuite) TestSetFlenDecimal4RealOrDecimal(c *C) {
Expand Down Expand Up @@ -376,6 +377,12 @@ func (s *testEvaluatorSuite) TestArithmeticDivide(c *C) {
sig, err := funcs[ast.Div].getFunction(s.ctx, s.datumsToConstants(types.MakeDatums(tc.args...)))
c.Assert(err, IsNil)
c.Assert(sig, NotNil)
switch sig.(type) {
case *builtinArithmeticIntDivideIntSig:
c.Assert(sig.PbCode(), Equals, tipb.ScalarFuncSig_IntDivideInt)
case *builtinArithmeticIntDivideDecimalSig:
c.Assert(sig.PbCode(), Equals, tipb.ScalarFuncSig_IntDivideDecimal)
}
val, err := evalBuiltinFunc(sig, chunk.Row{})
c.Assert(err, IsNil)
c.Assert(val, testutil.DatumEquals, types.NewDatum(tc.expect))
Expand Down Expand Up @@ -601,6 +608,14 @@ func (s *testEvaluatorSuite) TestArithmeticMod(c *C) {
c.Assert(err, IsNil)
c.Assert(sig, NotNil)
val, err := evalBuiltinFunc(sig, chunk.Row{})
switch sig.(type) {
case *builtinArithmeticModRealSig:
c.Assert(sig.PbCode(), Equals, tipb.ScalarFuncSig_ModReal)
case *builtinArithmeticModIntSig:
c.Assert(sig.PbCode(), Equals, tipb.ScalarFuncSig_ModInt)
case *builtinArithmeticModDecimalSig:
c.Assert(sig.PbCode(), Equals, tipb.ScalarFuncSig_ModDecimal)
}
c.Assert(err, IsNil)
c.Assert(val, testutil.DatumEquals, types.NewDatum(tc.expect))
}
Expand Down