Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#49527
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
YangKeao authored and ti-chi-bot committed Dec 17, 2023
1 parent 27ee7b8 commit d72ad25
Show file tree
Hide file tree
Showing 6 changed files with 10,731 additions and 1 deletion.
10,518 changes: 10,518 additions & 0 deletions DEPS.bzl

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion expression/builtin_convert_charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ func HandleBinaryLiteral(ctx sessionctx.Context, expr Expression, ec *ExprCollat
return expr
}
return BuildToBinaryFunction(ctx, expr)
} else if argChs == charset.CharsetBin && dstChs != charset.CharsetBin {
} else if argChs == charset.CharsetBin && dstChs != charset.CharsetBin &&
expr.GetType().GetType() != mysql.TypeNull {
ft := expr.GetType().Clone()
ft.SetCharset(ec.Charset)
ft.SetCollate(ec.Collation)
Expand Down
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,21 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

<<<<<<< HEAD
replace github.com/pingcap/tidb/parser => ./parser

// fix potential security issue(CVE-2020-26160) introduced by indirect dependency.
replace github.com/dgrijalva/jwt-go => github.com/form3tech-oss/jwt-go v3.2.6-0.20210809144907-32ab6a8243d7+incompatible
=======
replace (
// fix potential security issue(CVE-2020-26160) introduced by indirect dependency.
github.com/dgrijalva/jwt-go => github.com/form3tech-oss/jwt-go v3.2.6-0.20210809144907-32ab6a8243d7+incompatible
github.com/go-ldap/ldap/v3 => github.com/YangKeao/ldap/v3 v3.4.5-0.20230421065457-369a3bab1117
github.com/pingcap/tidb/pkg/parser => ./pkg/parser

// TODO: `sourcegraph.com/sourcegraph/appdash` has been archived, and the original host has been removed.
// Please remove these dependencies.
sourcegraph.com/sourcegraph/appdash => github.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
sourcegraph.com/sourcegraph/appdash-data => github.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)
>>>>>>> 3a7bd532a26 (expression: ignore `TypeNULL` in `HandleBinaryLiteral` (#49527))
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,14 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
<<<<<<< HEAD
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
=======
github.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0 h1:IJ3DuWHPTJrsqtIqjfdmPTELdTFGefvrOa2eTeRBleQ=
github.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:V952P4GGl1v/MMynLwxVdWEbSZJx+n0oOO3ljnez+WU=
github.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 h1:8ZnTA26bBOoPkAbbitKPgNlpw0Bwt7ZlpYgZWHWJR/w=
github.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:tNZjgbYncKL5HxvDULAr/mWDmFz4B7H8yrXEDlnoIiw=
>>>>>>> 3a7bd532a26 (expression: ignore `TypeNULL` in `HandleBinaryLiteral` (#49527))
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
Expand Down Expand Up @@ -1435,9 +1442,20 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
<<<<<<< HEAD
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0 h1:ucqkfpjg9WzSUubAO62csmucvxl4/JeW3F4I4909XkM=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 h1:e1sMhtVq9AfcEy8AXNb8eSg6gbzfdpYhoNqnPJa+GzI=
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k=
=======
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 h1:UZbZAZfX0wV2zr7YZorDz6GXROfDFj6LvqCRm4VUVKk=
sigs.k8s.io/structured-merge-diff/v4 v4.3.0/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
stathat.com/c/consistent v1.0.0 h1:ezyc51EGcRPJUxfHGSgJjWzJdj3NiMU9pNfLNGiXV0c=
stathat.com/c/consistent v1.0.0/go.mod h1:QkzMWzcbB+yQBL2AttO6sgsQS/JSTapcDISJalmCDS0=
>>>>>>> 3a7bd532a26 (expression: ignore `TypeNULL` in `HandleBinaryLiteral` (#49527))
110 changes: 110 additions & 0 deletions tests/integrationtest/r/expression/cast.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
select cast('' as signed);
cast('' as signed)
0
Level Code Message
Warning 1292 Truncated incorrect INTEGER value: ''
select cast('12345abcde' as signed);
cast('12345abcde' as signed)
12345
Level Code Message
Warning 1292 Truncated incorrect INTEGER value: '12345abcde'
select cast('123e456' as signed);
cast('123e456' as signed)
123
Level Code Message
Warning 1292 Truncated incorrect INTEGER value: '123e456'
select cast('-12345abcde' as signed);
cast('-12345abcde' as signed)
-12345
Level Code Message
Warning 1292 Truncated incorrect INTEGER value: '-12345abcde'
select cast('-123e456' as signed);
cast('-123e456' as signed)
-123
Level Code Message
Warning 1292 Truncated incorrect INTEGER value: '-123e456'
select coercibility(binary('a'));
coercibility(binary('a'))
2
select coercibility(cast('a' as char(10)));
coercibility(cast('a' as char(10)))
2
select coercibility(convert('abc', char(10)));
coercibility(convert('abc', char(10)))
2
drop table if exists t;
create table t(d1 double, f float, d2 decimal(24,8));
insert into t values(0, 0, 0);
select cast(111.1 as datetime) from t;
cast(111.1 as datetime)
2000-01-11 00:00:00
select cast(1311.1 as datetime) from t;
cast(1311.1 as datetime)
NULL
insert into t values(111.1, 1122.1, 31212.111);
insert into t values(121212.1111, 1121212.111111, 11121212.111111);
insert into t values(99991111.1111111, 101.1111111, 20121212121212.1111111);
insert into t values(NULL, NULL, NULL);
insert into t values(1.1, 48.1, 100.1);
insert into t values(1301.11, 1131.111, 100001111.111);
insert into t values(20121212121260.1111111, 20121212126012.1111111, 20121212241212.1111111);
select cast(d1 as datetime), cast(f as datetime), cast(d2 as datetime) from t;
cast(d1 as datetime) cast(f as datetime) cast(d2 as datetime)
NULL NULL NULL
NULL NULL NULL
NULL NULL NULL
NULL NULL NULL
0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00
2000-01-11 00:00:00 2000-11-22 00:00:00 2003-12-12 00:00:00
2012-12-12 00:00:00 0112-12-12 00:00:00 1112-12-12 00:00:00
9999-11-11 00:00:00 2000-01-01 00:00:00 2012-12-12 12:12:12
drop table if exists t;
create table t (col1 bigint, col2 double, col3 decimal, col4 varchar(20), col5 json);
insert into t values (1, 1, 1, "1", "1");
insert into t values (null, null, null, null, null);
select cast(col1 as time), cast(col2 as time), cast(col3 as time), cast(col4 as time), cast(col5 as time) from t where col1 = 1;
cast(col1 as time) cast(col2 as time) cast(col3 as time) cast(col4 as time) cast(col5 as time)
00:00:01 00:00:01 00:00:01 00:00:01 NULL
select cast(col1 as time), cast(col2 as time), cast(col3 as time), cast(col4 as time), cast(col5 as time) from t where col1 is null;
cast(col1 as time) cast(col2 as time) cast(col3 as time) cast(col4 as time) cast(col5 as time)
NULL NULL NULL NULL NULL
select cast(col1 as time(31)) from t where col1 is null;
Error 1426 (42000): Too big precision 31 specified for column 'CAST'. Maximum is 6.
select cast(col2 as time(31)) from t where col1 is null;
Error 1426 (42000): Too big precision 31 specified for column 'CAST'. Maximum is 6.
select cast(col3 as time(31)) from t where col1 is null;
Error 1426 (42000): Too big precision 31 specified for column 'CAST'. Maximum is 6.
select cast(col4 as time(31)) from t where col1 is null;
Error 1426 (42000): Too big precision 31 specified for column 'CAST'. Maximum is 6.
select cast(col5 as time(31)) from t where col1 is null;
Error 1426 (42000): Too big precision 31 specified for column 'CAST'. Maximum is 6.
drop table if exists t1;
create table t1 (c1 text);
insert into t1 values ('a');
update t1 set c1 = cast('61qw' as decimal);
Error 1292 (22007): Truncated incorrect DECIMAL value: '61qw'
select cast('61qw' as decimal);
cast('61qw' as decimal)
61
Level Code Message
Warning 1292 Truncated incorrect DECIMAL value: '61qw'
drop table if exists t;
create table t (y year);
insert into t values (cast('14:15' as time));
select 1 from t where y = YEAR(CURDATE());
1
1
select cast(cast('14:15' as time) as year) = YEAR(CURDATE());
cast(cast('14:15' as time) as year) = YEAR(CURDATE())
1
explain select null as a union all select 'a' as a;
id estRows task access object operator info
Union_8 2.00 root
├─Projection_10 1.00 root <nil>->Column#3
│ └─TableDual_11 1.00 root rows:1
└─Projection_12 1.00 root a->Column#3
└─TableDual_13 1.00 root rows:1
select null as a union all select 'a' as a;
a
NULL
a
69 changes: 69 additions & 0 deletions tests/integrationtest/t/expression/cast.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# TestCastStrToInt
--enable_warnings
select cast('' as signed);
select cast('12345abcde' as signed);
select cast('123e456' as signed);
select cast('-12345abcde' as signed);
select cast('-123e456' as signed);
--disable_warnings

# TestCastCoer
select coercibility(binary('a'));
select coercibility(cast('a' as char(10)));
select coercibility(convert('abc', char(10)));

# TestCastRealAsTime
drop table if exists t;
create table t(d1 double, f float, d2 decimal(24,8));
insert into t values(0, 0, 0);
select cast(111.1 as datetime) from t;
select cast(1311.1 as datetime) from t;
insert into t values(111.1, 1122.1, 31212.111);
insert into t values(121212.1111, 1121212.111111, 11121212.111111);
insert into t values(99991111.1111111, 101.1111111, 20121212121212.1111111);
insert into t values(NULL, NULL, NULL);
insert into t values(1.1, 48.1, 100.1);
insert into t values(1301.11, 1131.111, 100001111.111);
insert into t values(20121212121260.1111111, 20121212126012.1111111, 20121212241212.1111111);
-- sorted_result
select cast(d1 as datetime), cast(f as datetime), cast(d2 as datetime) from t;

# TestCastAsTime
drop table if exists t;
create table t (col1 bigint, col2 double, col3 decimal, col4 varchar(20), col5 json);
insert into t values (1, 1, 1, "1", "1");
insert into t values (null, null, null, null, null);
select cast(col1 as time), cast(col2 as time), cast(col3 as time), cast(col4 as time), cast(col5 as time) from t where col1 = 1;
select cast(col1 as time), cast(col2 as time), cast(col3 as time), cast(col4 as time), cast(col5 as time) from t where col1 is null;
-- error 1426
select cast(col1 as time(31)) from t where col1 is null;
-- error 1426
select cast(col2 as time(31)) from t where col1 is null;
-- error 1426
select cast(col3 as time(31)) from t where col1 is null;
-- error 1426
select cast(col4 as time(31)) from t where col1 is null;
-- error 1426
select cast(col5 as time(31)) from t where col1 is null;

# TestCastErrMsg
drop table if exists t1;
create table t1 (c1 text);
insert into t1 values ('a');
--error 1292
update t1 set c1 = cast('61qw' as decimal);
--enable_warnings
select cast('61qw' as decimal);
--disable_warnings

# TestCastTimeAsYear
drop table if exists t;
create table t (y year);
insert into t values (cast('14:15' as time));
select 1 from t where y = YEAR(CURDATE());
select cast(cast('14:15' as time) as year) = YEAR(CURDATE());

# TestIssue49526
explain select null as a union all select 'a' as a;
--sorted_result
select null as a union all select 'a' as a;

0 comments on commit d72ad25

Please sign in to comment.