Skip to content

Commit

Permalink
expression: split isTrue and isFalse expression sig (#16542) (#16627)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored May 7, 2020
1 parent 04baec7 commit caf7527
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
20 changes: 20 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4472,3 +4472,23 @@ func (s *testSuite1) TestIssue16854(c *C) {
tk.MustQuery("select distinct a from t order by a").Check(testkit.Rows("WAITING", "PRINTED", "WAITING,PRINTED", "STOCKUP", "WAITING,STOCKUP", "PRINTED,STOCKUP", "WAITING,PRINTED,STOCKUP"))
tk.MustExec("drop table t")
}

func (s *testSuite1) TestIssue15718(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
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', 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())
}
36 changes: 30 additions & 6 deletions expression/builtin_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,27 +425,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 @@ -388,6 +388,18 @@ func getSignatureByPB(ctx sessionctx.Context, sigCode tipb.ScalarFuncSig, tp *ti
f = &builtinRealIsTrueSig{base, false}
case tipb.ScalarFuncSig_DecimalIsTrue:
f = &builtinDecimalIsTrueSig{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_ModInt:
f = &builtinArithmeticModIntSig{base}
case tipb.ScalarFuncSig_ModReal:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
github.com/pingcap/parser v3.0.13-0.20200428073321-7e525711e35d+incompatible
github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2
github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible
github.com/pingcap/tipb v0.0.0-20200401051346-bec3080a5428
github.com/pingcap/tipb v0.0.0-20200426072559-d2c068e96eb3
github.com/prometheus/client_golang v0.9.0
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2 h1:NL23b8tsg6M1Q
github.com/pingcap/pd v1.1.0-beta.0.20191223090411-ea2b748f6ee2/go.mod h1:b4gaAPSxaVVtaB+EHamV4Nsv8JmTdjlw0cTKmp4+dRQ=
github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible h1:I8HirWsu1MZp6t9G/g8yKCEjJJxtHooKakEgccvdJ4M=
github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tipb v0.0.0-20200401051346-bec3080a5428 h1:u2eGnp74AlgviPKRcf49MESRp8RFAhURomJsL2XYC6o=
github.com/pingcap/tipb v0.0.0-20200401051346-bec3080a5428/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
github.com/pingcap/tipb v0.0.0-20200426072559-d2c068e96eb3 h1:rwil8cOXl/TYlhAhvu8LG05Ukw6eRnCRmEbR0uyodbc=
github.com/pingcap/tipb v0.0.0-20200426072559-d2c068e96eb3/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

0 comments on commit caf7527

Please sign in to comment.