From 16f2911ac031f4be73d067a0ac408a1dc7b724ea Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Wed, 6 Sep 2023 09:30:41 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #46620 Signed-off-by: ti-chi-bot --- expression/integration_test.go | 46 ++++++++++++++++++++++++++++++++++ types/datum.go | 7 +++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 9eccf5a116de7..9a9cdbc88b806 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7469,3 +7469,49 @@ func TestIfFunctionWithNull(t *testing.T) { tk.MustQuery("select min(if(apply_to_now_days <= 30,loan,null)) as min, max(if(apply_to_now_days <= 720,loan,null)) as max from (select loan, datediff(from_unixtime(unix_timestamp('2023-05-18 18:43:43') + 18000), from_unixtime(apply_time/1000 + 18000)) as apply_to_now_days from orders) t1;").Sort().Check( testkit.Rows("20000 35100")) } +<<<<<<< HEAD:expression/integration_test.go +======= + +func TestIssue41733AndIssue45410(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("create database testIssue41733") + defer tk.MustExec("drop database testIssue41733") + tk.MustExec("use testIssue41733") + + tk.MustExec("create table t_tiny (c0 TINYINT UNSIGNED)") + tk.MustExec("INSERT IGNORE INTO t_tiny(c0) VALUES (1E9)") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) + tk.MustQuery("select * from t_tiny;").Check(testkit.Rows("255")) + + tk.MustExec("create table t_small (c0 SMALLINT UNSIGNED)") + tk.MustExec("INSERT IGNORE INTO t_small(c0) VALUES (1E9)") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) + tk.MustQuery("select * from t_small;").Check(testkit.Rows("65535")) + + tk.MustExec("create table t_medium (c0 MEDIUMINT UNSIGNED)") + tk.MustExec("INSERT IGNORE INTO t_medium(c0) VALUES (1E9)") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) + tk.MustQuery("select * from t_medium;").Check(testkit.Rows("16777215")) + + tk.MustExec("create table t_int (c0 INT UNSIGNED)") + tk.MustExec("INSERT IGNORE INTO t_int(c0) VALUES (1E20)") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) + tk.MustQuery("select * from t_int;").Check(testkit.Rows("4294967295")) + + tk.MustExec("create table t_big (c0 BIGINT UNSIGNED)") + tk.MustExec("INSERT IGNORE INTO t_big(c0) VALUES (1E20)") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) + tk.MustQuery("select * from t_big;").Check(testkit.Rows("18446744073709551615")) + + // Issue 45410 + tk.MustExec("create database testIssue45410") + defer tk.MustExec("drop database testIssue45410") + tk.MustExec("use testIssue45410") + + tk.MustExec("DROP TABLE IF EXISTS t1;") + tk.MustExec("CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL );") + tk.MustExec("INSERT INTO t1 VALUES (0);") + tk.MustQuery("SELECT c1>=CAST('-787360724' AS TIME) FROM t1;").Check(testkit.Rows("1")) +} +>>>>>>> ca696229234 (expression: fix wrong result for unsigned non-const int cmp const duration (#46620)):expression/integration_test/integration_test.go diff --git a/types/datum.go b/types/datum.go index f220df6e0e893..73755f066b8c1 100644 --- a/types/datum.go +++ b/types/datum.go @@ -1192,9 +1192,10 @@ func (d *Datum) convertToUint(sc *stmtctx.StatementContext, target *FieldType) ( case KindMysqlDuration: dec := d.GetMysqlDuration().ToNumber() err = dec.Round(dec, 0, ModeHalfUp) - ival, err1 := dec.ToInt() - if err1 == nil { - val, err = ConvertIntToUint(sc, ival, upperBound, tp) + var err1 error + val, err1 = ConvertDecimalToUint(sc, dec, upperBound, tp) + if err == nil { + err = err1 } case KindMysqlDecimal: val, err = ConvertDecimalToUint(sc, d.GetMysqlDecimal(), upperBound, tp) From d67a07f912f7ea13be36ff24fadf45fb4195badb Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Thu, 7 Sep 2023 14:37:59 +0800 Subject: [PATCH 2/2] resolve conflict --- expression/integration_test.go | 37 +++------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 9a9cdbc88b806..fc791da3dcce8 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7469,41 +7469,11 @@ func TestIfFunctionWithNull(t *testing.T) { tk.MustQuery("select min(if(apply_to_now_days <= 30,loan,null)) as min, max(if(apply_to_now_days <= 720,loan,null)) as max from (select loan, datediff(from_unixtime(unix_timestamp('2023-05-18 18:43:43') + 18000), from_unixtime(apply_time/1000 + 18000)) as apply_to_now_days from orders) t1;").Sort().Check( testkit.Rows("20000 35100")) } -<<<<<<< HEAD:expression/integration_test.go -======= -func TestIssue41733AndIssue45410(t *testing.T) { - store := testkit.CreateMockStore(t) +func TestIssue45410(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() tk := testkit.NewTestKit(t, store) - tk.MustExec("create database testIssue41733") - defer tk.MustExec("drop database testIssue41733") - tk.MustExec("use testIssue41733") - - tk.MustExec("create table t_tiny (c0 TINYINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_tiny(c0) VALUES (1E9)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_tiny;").Check(testkit.Rows("255")) - - tk.MustExec("create table t_small (c0 SMALLINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_small(c0) VALUES (1E9)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_small;").Check(testkit.Rows("65535")) - - tk.MustExec("create table t_medium (c0 MEDIUMINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_medium(c0) VALUES (1E9)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_medium;").Check(testkit.Rows("16777215")) - - tk.MustExec("create table t_int (c0 INT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_int(c0) VALUES (1E20)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_int;").Check(testkit.Rows("4294967295")) - - tk.MustExec("create table t_big (c0 BIGINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_big(c0) VALUES (1E20)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_big;").Check(testkit.Rows("18446744073709551615")) - // Issue 45410 tk.MustExec("create database testIssue45410") defer tk.MustExec("drop database testIssue45410") @@ -7514,4 +7484,3 @@ func TestIssue41733AndIssue45410(t *testing.T) { tk.MustExec("INSERT INTO t1 VALUES (0);") tk.MustQuery("SELECT c1>=CAST('-787360724' AS TIME) FROM t1;").Check(testkit.Rows("1")) } ->>>>>>> ca696229234 (expression: fix wrong result for unsigned non-const int cmp const duration (#46620)):expression/integration_test/integration_test.go