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: split isTrue and isFalse expression sig (#16542) #16630

Merged
merged 4 commits into from
Apr 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5385,6 +5385,17 @@ func (s *testSuite1) TestIssue15718(c *C) {
tk.MustExec("create table tt(a decimal(10, 0), b varchar(1), c time);")
tk.MustExec("insert into tt values(0, '2', null), (7, null, '1122'), (NULL, 'w', null), (NULL, '2', '3344'), (NULL, NULL, '0'), (7, 'f', '33');")
tk.MustQuery("select a and b as d, a or c as e from tt;").Check(testkit.Rows("0 <nil>", "<nil> 1", "0 <nil>", "<nil> 1", "<nil> <nil>", "0 1"))

tk.MustExec("drop table if exists tt;")
tk.MustExec("create table tt(a decimal(10, 0), b varchar(1), c time);")
tk.MustExec("insert into tt values(0, '2', '123'), (7, null, '1122'), (null, 'w', null);")
tk.MustQuery("select a and b as d, a, b from tt order by d limit 1;").Check(testkit.Rows("<nil> 7 <nil>"))
tk.MustQuery("select b or c as d, b, c from tt order by d limit 1;").Check(testkit.Rows("<nil> w <nil>"))

tk.MustExec("drop table if exists t0;")
tk.MustExec("CREATE TABLE t0(c0 FLOAT);")
tk.MustExec("INSERT INTO t0(c0) VALUES (NULL);")
tk.MustQuery("SELECT * FROM t0 WHERE NOT(0 OR t0.c0);").Check(testkit.Rows())
}

func (s *testSuite1) TestIssue15767(c *C) {
Expand Down
36 changes: 30 additions & 6 deletions expression/builtin_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,27 +427,51 @@ func (c *isTrueOrFalseFunctionClass) getFunction(ctx sessionctx.Context, args []
switch argTp {
case types.ETReal:
sig = &builtinRealIsTrueSig{bf, c.keepNull}
sig.setPbCode(tipb.ScalarFuncSig_RealIsTrue)
if c.keepNull {
sig.setPbCode(tipb.ScalarFuncSig_RealIsTrueWithNull)
} else {
sig.setPbCode(tipb.ScalarFuncSig_RealIsTrue)
}
case types.ETDecimal:
sig = &builtinDecimalIsTrueSig{bf, c.keepNull}
sig.setPbCode(tipb.ScalarFuncSig_DecimalIsTrue)
if c.keepNull {
sig.setPbCode(tipb.ScalarFuncSig_DecimalIsTrueWithNull)
} else {
sig.setPbCode(tipb.ScalarFuncSig_DecimalIsTrue)
}
case types.ETInt:
sig = &builtinIntIsTrueSig{bf, c.keepNull}
sig.setPbCode(tipb.ScalarFuncSig_IntIsTrue)
if c.keepNull {
sig.setPbCode(tipb.ScalarFuncSig_IntIsTrueWithNull)
} else {
sig.setPbCode(tipb.ScalarFuncSig_IntIsTrue)
}
default:
return nil, errors.Errorf("unexpected types.EvalType %v", argTp)
}
case opcode.IsFalsity:
switch argTp {
case types.ETReal:
sig = &builtinRealIsFalseSig{bf, c.keepNull}
sig.setPbCode(tipb.ScalarFuncSig_RealIsFalse)
if c.keepNull {
sig.setPbCode(tipb.ScalarFuncSig_RealIsFalseWithNull)
} else {
sig.setPbCode(tipb.ScalarFuncSig_RealIsFalse)
}
case types.ETDecimal:
sig = &builtinDecimalIsFalseSig{bf, c.keepNull}
sig.setPbCode(tipb.ScalarFuncSig_DecimalIsFalse)
if c.keepNull {
sig.setPbCode(tipb.ScalarFuncSig_DecimalIsFalseWithNull)
} else {
sig.setPbCode(tipb.ScalarFuncSig_DecimalIsFalse)
}
case types.ETInt:
sig = &builtinIntIsFalseSig{bf, c.keepNull}
sig.setPbCode(tipb.ScalarFuncSig_IntIsFalse)
if c.keepNull {
sig.setPbCode(tipb.ScalarFuncSig_IntIsFalseWithNull)
} else {
sig.setPbCode(tipb.ScalarFuncSig_IntIsFalse)
}
default:
return nil, errors.Errorf("unexpected types.EvalType %v", argTp)
}
Expand Down
12 changes: 12 additions & 0 deletions expression/distsql_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,18 @@ func getSignatureByPB(ctx sessionctx.Context, sigCode tipb.ScalarFuncSig, tp *ti
f = &builtinRealIsFalseSig{base, false}
case tipb.ScalarFuncSig_DecimalIsFalse:
f = &builtinDecimalIsFalseSig{base, false}
case tipb.ScalarFuncSig_IntIsTrueWithNull:
f = &builtinIntIsTrueSig{base, true}
case tipb.ScalarFuncSig_RealIsTrueWithNull:
f = &builtinRealIsTrueSig{base, true}
case tipb.ScalarFuncSig_DecimalIsTrueWithNull:
f = &builtinDecimalIsTrueSig{base, true}
case tipb.ScalarFuncSig_IntIsFalseWithNull:
f = &builtinIntIsFalseSig{base, true}
case tipb.ScalarFuncSig_RealIsFalseWithNull:
f = &builtinRealIsFalseSig{base, true}
case tipb.ScalarFuncSig_DecimalIsFalseWithNull:
f = &builtinDecimalIsFalseSig{base, true}
case tipb.ScalarFuncSig_LeftShift:
f = &builtinLeftShiftSig{base}
case tipb.ScalarFuncSig_RightShift:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/pingcap/pd/v4 v4.0.0-beta.1.0.20200305072537-61d9f9cc35d3
github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible
github.com/pingcap/tipb v0.0.0-20200212061130-c4d518eb1d60
github.com/pingcap/tipb v0.0.0-20200417094153-7316d94df1ee
github.com/prometheus/client_golang v1.0.0
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
github.com/prometheus/common v0.4.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb/go.mod h1:EB/852NM
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible h1:84F7MFMfdAYObrznvRslmVu43aoihrlL+7mMyMlOi0o=
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
github.com/pingcap/tipb v0.0.0-20200212061130-c4d518eb1d60 h1:aJPXrT1u4VfUSGFA2oQVwl4pOXzqe+YI6wed01cjDH4=
github.com/pingcap/tipb v0.0.0-20200212061130-c4d518eb1d60/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
github.com/pingcap/tipb v0.0.0-20200417094153-7316d94df1ee h1:XJQ6/LGzOSc/jo33AD8t7jtc4GohxcyODsYnb+kZXJM=
github.com/pingcap/tipb v0.0.0-20200417094153-7316d94df1ee/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down