diff --git a/DEPS.bzl b/DEPS.bzl index c5caa87ae2237..f7f416e42ce35 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -5463,15 +5463,37 @@ def go_deps(): name = "com_sourcegraph_sourcegraph_appdash", build_file_proto_mode = "disable_global", importpath = "sourcegraph.com/sourcegraph/appdash", +<<<<<<< HEAD sum = "h1:ucqkfpjg9WzSUubAO62csmucvxl4/JeW3F4I4909XkM=", version = "v0.0.0-20190731080439-ebfcffb1b5c0", +======= + sha256 = "c46b442fa40d2af48e08064f4c16ae3712953a9988cd0f7588fcf5e4fc7a2fed", + strip_prefix = "github.com/sourcegraph/appdash@v0.0.0-20190731080439-ebfcffb1b5c0", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/sourcegraph/appdash/com_github_sourcegraph_appdash-v0.0.0-20190731080439-ebfcffb1b5c0.zip", + "http://ats.apps.svc/gomod/github.com/sourcegraph/appdash/com_github_sourcegraph_appdash-v0.0.0-20190731080439-ebfcffb1b5c0.zip", + "https://cache.hawkingrei.com/gomod/github.com/sourcegraph/appdash/com_github_sourcegraph_appdash-v0.0.0-20190731080439-ebfcffb1b5c0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/sourcegraph/appdash/com_github_sourcegraph_appdash-v0.0.0-20190731080439-ebfcffb1b5c0.zip", + ], +>>>>>>> 3a7bd532a26 (expression: ignore `TypeNULL` in `HandleBinaryLiteral` (#49527)) ) go_repository( name = "com_sourcegraph_sourcegraph_appdash_data", build_file_proto_mode = "disable_global", importpath = "sourcegraph.com/sourcegraph/appdash-data", +<<<<<<< HEAD sum = "h1:e1sMhtVq9AfcEy8AXNb8eSg6gbzfdpYhoNqnPJa+GzI=", version = "v0.0.0-20151005221446-73f23eafcf67", +======= + sha256 = "59b71fa8cdb0fe2b1c02739ccf2daeaf28f2e22c4b178cdc8e1b902ad1022bc0", + strip_prefix = "github.com/sourcegraph/appdash-data@v0.0.0-20151005221446-73f23eafcf67", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/sourcegraph/appdash-data/com_github_sourcegraph_appdash_data-v0.0.0-20151005221446-73f23eafcf67.zip", + "http://ats.apps.svc/gomod/github.com/sourcegraph/appdash-data/com_github_sourcegraph_appdash_data-v0.0.0-20151005221446-73f23eafcf67.zip", + "https://cache.hawkingrei.com/gomod/github.com/sourcegraph/appdash-data/com_github_sourcegraph_appdash_data-v0.0.0-20151005221446-73f23eafcf67.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/sourcegraph/appdash-data/com_github_sourcegraph_appdash_data-v0.0.0-20151005221446-73f23eafcf67.zip", + ], +>>>>>>> 3a7bd532a26 (expression: ignore `TypeNULL` in `HandleBinaryLiteral` (#49527)) ) go_repository( name = "com_stathat_c_consistent", diff --git a/expression/builtin_convert_charset.go b/expression/builtin_convert_charset.go index abd7bfccfe584..03fc599018d7f 100644 --- a/expression/builtin_convert_charset.go +++ b/expression/builtin_convert_charset.go @@ -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) diff --git a/go.mod b/go.mod index 10e5e8bf3086b..29850ffb4d156 100644 --- a/go.mod +++ b/go.mod @@ -294,6 +294,15 @@ 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 +<<<<<<< HEAD github.com/pingcap/tidb/parser => ./parser go.opencensus.io => go.opencensus.io v0.23.1-0.20220331163232-052120675fac +======= + 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)) ) diff --git a/go.sum b/go.sum index f9999d20522cd..dae3b53cb2d7c 100644 --- a/go.sum +++ b/go.sum @@ -912,9 +912,16 @@ 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/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/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= @@ -1616,9 +1623,5 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= -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= stathat.com/c/consistent v1.0.0 h1:ezyc51EGcRPJUxfHGSgJjWzJdj3NiMU9pNfLNGiXV0c= stathat.com/c/consistent v1.0.0/go.mod h1:QkzMWzcbB+yQBL2AttO6sgsQS/JSTapcDISJalmCDS0= diff --git a/tests/integrationtest/r/expression/cast.result b/tests/integrationtest/r/expression/cast.result new file mode 100644 index 0000000000000..6628ec0af24c6 --- /dev/null +++ b/tests/integrationtest/r/expression/cast.result @@ -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 ->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 diff --git a/tests/integrationtest/t/expression/cast.test b/tests/integrationtest/t/expression/cast.test new file mode 100644 index 0000000000000..e1681e4d87934 --- /dev/null +++ b/tests/integrationtest/t/expression/cast.test @@ -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;