Repository: matrixorigin/matrixone
Pull request #3572 (2022-06-30 09:46:45)

add compare func with timestamp
**What type of PR is this?**

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

**Which issue(s) this PR fixes:**

issue #3362 #3254 #3270 #3268 

**What this PR does / why we need it:**

Not Available

**Special notes for your reviewer:**

Not Available

**Additional documentation (e.g. design docs, usage docs, etc.):**

Not Available



Patch:
diff --git a/pkg/sql/plan2/function/operator/case_when.go b/pkg/sql/plan2/function/operator/case_when.go
index ff7e832cd..b52e13709 100644
--- a/pkg/sql/plan2/function/operator/case_when.go
+++ b/pkg/sql/plan2/function/operator/case_when.go
@@ -132,7 +132,7 @@ func CwTypeCheckFn(inputTypes []types.T, _ []types.T, ret types.T) bool {
 }
 
 type OrderedValue interface {
-	constraints.Integer | constraints.Float | types.Date | types.Datetime | types.Decimal64
+	constraints.Integer | constraints.Float | types.Date | types.Datetime | types.Decimal64 | types.Timestamp
 }
 
 type NormalType interface {
diff --git a/pkg/sql/plan2/function/operators.go b/pkg/sql/plan2/function/operators.go
index 9b940d4e4..5d42368b8 100644
--- a/pkg/sql/plan2/function/operators.go
+++ b/pkg/sql/plan2/function/operators.go
@@ -615,6 +615,17 @@ var operators = map[int]Functions{
 				ReturnTyp: types.T_bool,
 				Fn:        operator.EqGeneral[bool],
 			},
+			{
+				Index:  17,
+				Flag:   plan.Function_STRICT,
+				Layout: COMPARISON_OPERATOR,
+				Args: []types.T{
+					types.T_timestamp,
+					types.T_timestamp,
+				},
+				ReturnTyp: types.T_bool,
+				Fn:        operator.EqGeneral[types.Timestamp],
+			},
 		},
 	},
 
@@ -809,6 +820,17 @@ var operators = map[int]Functions{
 				ReturnTyp: types.T_bool,
 				Fn:        operator.GtBool,
 			},
+			{
+				Index:  17,
+				Flag:   plan.Function_STRICT,
+				Layout: COMPARISON_OPERATOR,
+				Args: []types.T{
+					types.T_timestamp,
+					types.T_timestamp,
+				},
+				ReturnTyp: types.T_bool,
+				Fn:        operator.GtGeneral[types.Timestamp],
+			},
 		},
 	},
 
@@ -1003,6 +1025,17 @@ var operators = map[int]Functions{
 				ReturnTyp: types.T_bool,
 				Fn:        operator.GeBool,
 			},
+			{
+				Index:  17,
+				Flag:   plan.Function_STRICT,
+				Layout: COMPARISON_OPERATOR,
+				Args: []types.T{
+					types.T_timestamp,
+					types.T_timestamp,
+				},
+				ReturnTyp: types.T_bool,
+				Fn:        operator.GeGeneral[types.Timestamp],
+			},
 		},
 	},
 
@@ -1197,6 +1230,17 @@ var operators = map[int]Functions{
 				ReturnTyp: types.T_bool,
 				Fn:        operator.LtBool,
 			},
+			{
+				Index:  17,
+				Flag:   plan.Function_STRICT,
+				Layout: COMPARISON_OPERATOR,
+				Args: []types.T{
+					types.T_timestamp,
+					types.T_timestamp,
+				},
+				ReturnTyp: types.T_bool,
+				Fn:        operator.LtGeneral[types.Timestamp],
+			},
 		},
 	},
 
@@ -1391,6 +1435,17 @@ var operators = map[int]Functions{
 				ReturnTyp: types.T_bool,
 				Fn:        operator.LeBool,
 			},
+			{
+				Index:  17,
+				Flag:   plan.Function_STRICT,
+				Layout: COMPARISON_OPERATOR,
+				Args: []types.T{
+					types.T_timestamp,
+					types.T_timestamp,
+				},
+				ReturnTyp: types.T_bool,
+				Fn:        operator.LeGeneral[types.Timestamp],
+			},
 		},
 	},
 
@@ -1585,6 +1640,17 @@ var operators = map[int]Functions{
 				ReturnTyp: types.T_bool,
 				Fn:        operator.NeGeneral[bool],
 			},
+			{
+				Index:  17,
+				Flag:   plan.Function_STRICT,
+				Layout: COMPARISON_OPERATOR,
+				Args: []types.T{
+					types.T_timestamp,
+					types.T_timestamp,
+				},
+				ReturnTyp: types.T_bool,
+				Fn:        operator.NeGeneral[types.Timestamp],
+			},
 		},
 	},
 


Test patch:
diff --git a/test/cases/dtype/datetime.test b/test/cases/dtype/datetime.test
index f3590a26f..bcd7acd3d 100644
--- a/test/cases/dtype/datetime.test
+++ b/test/cases/dtype/datetime.test
@@ -34,23 +34,18 @@ select cast(cast('2000-12-31' as datetime(0)) as date);
 
 #Test cases of query with single table
 drop table if exists t1;
--- @bvt:issue#3362#
 create table t1 (a datetime(0) not null, primary key(a));
 insert into t1 values ('20200101000000'), ('2022-01-02'), ('2022-01-02 00:00:01'), ('2022-01-02 00:00:01.512345');
 select * from t1;
--- @bvt:issue
--- @bvt:issue#3254
 select * from t1 where a='2022-01-02';
--- @bvt:issue
 -- @bvt:issue#3258
 select * from t1 where a>20220102;
 -- @bvt:issue
--- @bvt:issue#3254
 select * from t1 where a!='2022-01-02';
 update t1 set a=DATE_ADD(a ,INTERVAL 1 WEEK) where a>'20220102';
 select * from t1;
 drop table t1;
--- @bvt:issue
+
 -- @bvt:issue#3362
 create table t1 ( a int not null default 1, big datetime(4) primary key);
 insert into t1 (big) values ('20220103'),('2022-01-01'),('2022-01-01 00:00:01'),('2022-01-02 00:00.00.000050');
diff --git a/test/cases/dtype/timestamp.test b/test/cases/dtype/timestamp.test
index 4df6f3b9c..f42bf7bc5 100644
--- a/test/cases/dtype/timestamp.test
+++ b/test/cases/dtype/timestamp.test
@@ -8,16 +8,12 @@ drop table if exists t1;
 create table t1 (a timestamp(0) not null, primary key(a));
 insert into t1 values ('20200101000000'), ('2022-01-02'), ('2022-01-02 00:00:01'), ('2022-01-02 00:00:01.512345');
 select * from t1;
--- @bvt:issue#3270
 select * from t1 where a='2022-01-02';
--- @bvt:issue
 -- @bvt:issue#3268
 select * from t1 where a>20220102;
 -- @bvt:issue
--- @bvt:issue#3268
 select * from t1 where a!='2022-01-02';
 update t1 set a=DATE_ADD(a ,INTERVAL 1 WEEK) where a>'20220102';
-select * from t1;
 -- @bvt:issue
 drop table t1;
 create table t1 ( a int not null default 1, big timestamp(4) primary key);
diff --git a/test/result/dtype/datetime.result b/test/result/dtype/datetime.result
index 103b4e3c2..42e03ecce 100644
--- a/test/result/dtype/datetime.result
+++ b/test/result/dtype/datetime.result
@@ -87,8 +87,8 @@ select * from t1;
 a
 2020-01-01 00:00:00
 2022-01-02 00:00:00
-2022-01-02 00:00:01
-2022-01-02 00:00:02
+2022-01-09 00:00:01
+2022-01-09 00:00:02
 drop table t1;
 create table t1 ( a int not null default 1, big datetime(4) primary key);
 insert into t1 (big) values ('20220103'),('2022-01-01'),('2022-01-01 00:00:01'),('2022-01-02 00:00.00.000050');