Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(mtr):add x_function.test(#497) #820

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions mysql-test/suite/tianmu/r/AddDate_function.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# Test ADDDATE function
# Author: syw
#
DROP DATABASE IF EXISTS mcs178_db;
CREATE DATABASE mcs178_db;
USE mcs178_db;
CREATE TABLE t1 (a CHAR(1), b INT, c DATETIME, d DOUBLE)engine=tianmu;
INSERT INTO t1 VALUES ('', NULL, '1990-01-01', NULL),('a', 12, '1212-12-12', 1.19691E+100),('b', 13, '1313-3-13 13:13:13', 2.1961E+18),('c', 14, '1414-4-14', 0.16191),('d', 15, '2015-5-15 15:15:15', 1.971917);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(1) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` datetime DEFAULT NULL,
`d` double DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT ADDDATE('2020-02-02 22:22:22', 1);
ADDDATE('2020-02-02 22:22:22', 1)
2020-02-03 22:22:22
SELECT ADDDATE('2020-02-02 22:22:22', INTERVAL 1 DAY);
ADDDATE('2020-02-02 22:22:22', INTERVAL 1 DAY)
2020-02-03 22:22:22
SELECT ADDDATE('2020-02-02 22:22:22', INTERVAL 1 HOUR);
ADDDATE('2020-02-02 22:22:22', INTERVAL 1 HOUR)
2020-02-02 23:22:22
SELECT ADDDATE('2020-02-02 22:22:22', INTERVAL 1 MINUTE);
ADDDATE('2020-02-02 22:22:22', INTERVAL 1 MINUTE)
2020-02-02 22:23:22
SELECT ADDDATE('2020-02-02 22:22:22', INTERVAL -1 SECOND);
ADDDATE('2020-02-02 22:22:22', INTERVAL -1 SECOND)
2020-02-02 22:22:21
SELECT c, ADDDATE(c, 1) FROM t1;
c ADDDATE(c, 1)
1990-01-01 00:00:00 1990-01-02 00:00:00
1212-12-12 00:00:00 1212-12-13 00:00:00
1313-03-13 13:13:13 1313-03-14 13:13:13
1414-04-14 00:00:00 1414-04-15 00:00:00
2015-05-15 15:15:15 2015-05-16 15:15:15
SELECT c, ADDDATE(c, -2) FROM t1;
c ADDDATE(c, -2)
1990-01-01 00:00:00 1989-12-30 00:00:00
1212-12-12 00:00:00 1212-12-10 00:00:00
1313-03-13 13:13:13 1313-03-11 13:13:13
1414-04-14 00:00:00 1414-04-12 00:00:00
2015-05-15 15:15:15 2015-05-13 15:15:15
SELECT c, ADDDATE(c, INTERVAL -1 HOUR) FROM t1;
c ADDDATE(c, INTERVAL -1 HOUR)
1990-01-01 00:00:00 1989-12-31 23:00:00
1212-12-12 00:00:00 1212-12-11 23:00:00
1313-03-13 13:13:13 1313-03-13 12:13:13
1414-04-14 00:00:00 1414-04-13 23:00:00
2015-05-15 15:15:15 2015-05-15 14:15:15
SELECT c, ADDDATE(c, INTERVAL 1 MINUTE) FROM t1;
c ADDDATE(c, INTERVAL 1 MINUTE)
1990-01-01 00:00:00 1990-01-01 00:01:00
1212-12-12 00:00:00 1212-12-12 00:01:00
1313-03-13 13:13:13 1313-03-13 13:14:13
1414-04-14 00:00:00 1414-04-14 00:01:00
2015-05-15 15:15:15 2015-05-15 15:16:15
SELECT c, ADDDATE(c, INTERVAL 1 SECOND) FROM t1;
c ADDDATE(c, INTERVAL 1 SECOND)
1990-01-01 00:00:00 1990-01-01 00:00:01
1212-12-12 00:00:00 1212-12-12 00:00:01
1313-03-13 13:13:13 1313-03-13 13:13:14
1414-04-14 00:00:00 1414-04-14 00:00:01
2015-05-15 15:15:15 2015-05-15 15:15:16
DROP DATABASE mcs178_db;
72 changes: 72 additions & 0 deletions mysql-test/suite/tianmu/r/AddTime_function.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Test ADDTIME function
# Author: syw
#
DROP DATABASE IF EXISTS mcs179_db;
CREATE DATABASE mcs179_db;
USE mcs179_db;
CREATE TABLE t1 (a CHAR(1), b INT, c DATETIME, d DOUBLE)engine=tianmu;
INSERT INTO t1 VALUES ('', NULL, '1990-01-01', NULL),('a', 12, '1212-12-12', 1.19691E+100),('b', 13, '1313-3-13 13:13:13', 2.1961E+18),('c', 14, '1414-4-14', 0.16191),('d', 15, '2015-5-15 15:15:15', 1.971917);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(1) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` datetime DEFAULT NULL,
`d` double DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT ADDTIME('2020-02-02 22:22:22', '2 1:1:1');
ADDTIME('2020-02-02 22:22:22', '2 1:1:1')
2020-02-04 23:23:23
SELECT ADDTIME('2020-02-02 22:22:22', '2:2:2.1111');
ADDTIME('2020-02-02 22:22:22', '2:2:2.1111')
2020-02-03 00:24:24.111100
SELECT ADDTIME('2020-02-02 22:22:22', '-2:2:2');
ADDTIME('2020-02-02 22:22:22', '-2:2:2')
2020-02-02 20:20:20
SELECT ADDTIME('22:22:22', '03:11:22');
ADDTIME('22:22:22', '03:11:22')
25:33:44
SELECT c, ADDTIME(c, '1 3:3:3') FROM t1;
c ADDTIME(c, '1 3:3:3')
1990-01-01 00:00:00 1990-01-02 03:03:03
1212-12-12 00:00:00 1212-12-13 03:03:03
1313-03-13 13:13:13 1313-03-14 16:16:16
1414-04-14 00:00:00 1414-04-15 03:03:03
2015-05-15 15:15:15 2015-05-16 18:18:18
SELECT c, ADDTIME(c, '-2 1:1:1') FROM t1;
c ADDTIME(c, '-2 1:1:1')
1990-01-01 00:00:00 1989-12-29 22:58:59
1212-12-12 00:00:00 1212-12-09 22:58:59
1313-03-13 13:13:13 1313-03-11 12:12:12
1414-04-14 00:00:00 1414-04-11 22:58:59
2015-05-15 15:15:15 2015-05-13 14:14:14
SELECT c, ADDTIME(c, '100:11:12') FROM t1;
c ADDTIME(c, '100:11:12')
1990-01-01 00:00:00 1990-01-05 04:11:12
1212-12-12 00:00:00 1212-12-16 04:11:12
1313-03-13 13:13:13 1313-03-17 17:24:25
1414-04-14 00:00:00 1414-04-18 04:11:12
2015-05-15 15:15:15 2015-05-19 19:26:27
SELECT c, ADDTIME(c, '-100:11:12') FROM t1;
c ADDTIME(c, '-100:11:12')
1990-01-01 00:00:00 1989-12-27 19:48:48
1212-12-12 00:00:00 1212-12-07 19:48:48
1313-03-13 13:13:13 1313-03-09 09:02:01
1414-04-14 00:00:00 1414-04-09 19:48:48
2015-05-15 15:15:15 2015-05-11 11:04:03
SELECT c, ADDTIME(c, '100:11') FROM t1;
c ADDTIME(c, '100:11')
1990-01-01 00:00:00 1990-01-05 04:11:00
1212-12-12 00:00:00 1212-12-16 04:11:00
1313-03-13 13:13:13 1313-03-17 17:24:13
1414-04-14 00:00:00 1414-04-18 04:11:00
2015-05-15 15:15:15 2015-05-19 19:26:15
SELECT c, ADDTIME(c, '100') FROM t1;
c ADDTIME(c, '100')
1990-01-01 00:00:00 1990-01-01 00:01:00
1212-12-12 00:00:00 1212-12-12 00:01:00
1313-03-13 13:13:13 1313-03-13 13:14:13
1414-04-14 00:00:00 1414-04-14 00:01:00
2015-05-15 15:15:15 2015-05-15 15:16:15
DROP DATABASE mcs179_db;
26 changes: 26 additions & 0 deletions mysql-test/suite/tianmu/r/avg_function.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Test AVG as distributed aggregate function
# Author: syw
#
DROP DATABASE IF EXISTS mcs188_db;
CREATE DATABASE mcs188_db;
USE mcs188_db;
CREATE TABLE t1 (a INT, b CHAR(5))ENGINE=tianmu;
INSERT INTO t1 VALUES (NULL, ''),(1, 'aaa'),(2, 'aaa'),(1, 'ccc'),(4, 'ddd'),(5, 'aaa'),(6, 'ddd'),(7, 'eee');
SELECT AVG(DISTINCT a) FROM t1;
AVG(DISTINCT a)
4.1667
SELECT AVG(DISTINCT a) FROM t1 GROUP BY b HAVING b = 'aaa';
AVG(DISTINCT a)
2.6667
SELECT b, AVG(DISTINCT a) FROM t1 GROUP BY b ORDER BY b DESC;
b AVG(DISTINCT a)
eee 7.0000
ddd 5.0000
ccc 1.0000
aaa 2.6667
NULL
SELECT AVG(a) FROM t1;
AVG(a)
3.7143
DROP DATABASE mcs188_db;
56 changes: 56 additions & 0 deletions mysql-test/suite/tianmu/r/case_function.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Test CASE function
# Author: syw
#
DROP DATABASE IF EXISTS mcs174_db;
CREATE DATABASE mcs174_db;
USE mcs174_db;
CREATE TABLE t1 (a CHAR(1), b INT, c DATETIME, d DOUBLE)engine=tianmu;
INSERT INTO t1 VALUES ('', NULL, '1990-01-01', NULL),('a', 12, '1212-12-12', 1.19691E+100),('b', 13, '1313-3-13 13:13:13', 2.1961E+18),('c', 14, '1414-4-14', 0.16191),('d', 15, '2015-5-15 15:15:15', 1.971917);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(1) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` datetime DEFAULT NULL,
`d` double DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT b, c, (CASE WHEN a = 'b' THEN b ELSE c END) FROM t1;
b c (CASE WHEN a = 'b' THEN b ELSE c END)
NULL 1990-01-01 00:00:00 1990-01-01 00:00:00
12 1212-12-12 00:00:00 1212-12-12 00:00:00
13 1313-03-13 13:13:13 13
14 1414-04-14 00:00:00 1414-04-14 00:00:00
15 2015-05-15 15:15:15 2015-05-15 15:15:15
SELECT b, a, (CASE WHEN b > 13 THEN b ELSE a END) FROM t1;
b a (CASE WHEN b > 13 THEN b ELSE a END)
NULL
12 a a
13 b b
14 c 14
15 d 15
SELECT c, a, (CASE WHEN d > 1 THEN a ELSE c END) FROM t1;
c a (CASE WHEN d > 1 THEN a ELSE c END)
1990-01-01 00:00:00 1990-01-01 00:00:00
1212-12-12 00:00:00 a a
1313-03-13 13:13:13 b b
1414-04-14 00:00:00 c 1414-04-14 00:00:00
2015-05-15 15:15:15 d d
SELECT a, c, (CASE WHEN c IS NULL THEN a ELSE c END) FROM t1;
a c (CASE WHEN c IS NULL THEN a ELSE c END)
1990-01-01 00:00:00 1990-01-01 00:00:00
a 1212-12-12 00:00:00 1212-12-12 00:00:00
b 1313-03-13 13:13:13 1313-03-13 13:13:13
c 1414-04-14 00:00:00 1414-04-14 00:00:00
d 2015-05-15 15:15:15 2015-05-15 15:15:15
SELECT (CASE WHEN a = 'a' THEN 0 ELSE 1 END) FROM t1;
(CASE WHEN a = 'a' THEN 0 ELSE 1 END)
1
0
1
1
1
SELECT (CASE WHEN 10 > 5 THEN 'True' ELSE 'False' END);
(CASE WHEN 10 > 5 THEN 'True' ELSE 'False' END)
True
DROP DATABASE mcs174_db;
76 changes: 76 additions & 0 deletions mysql-test/suite/tianmu/r/char_length_function.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# Test CHAR_LENGTH function
# Author: syw
#
DROP DATABASE IF EXISTS mcs182_db;
CREATE DATABASE mcs182_db;
USE mcs182_db;
CREATE TABLE t1 (a VARCHAR(20))engine=tianmu;
INSERT INTO t1 VALUES (repeat('a', 5)), (repeat('b', 10)), (repeat('c', 20));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(20) DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT CHAR_LENGTH('MariaDB');
CHAR_LENGTH('MariaDB')
7
SELECT CHAR_LENGTH(234);
CHAR_LENGTH(234)
3
SELECT CHAR_LENGTH('~12ab');
CHAR_LENGTH('~12ab')
5
SELECT CHAR_LENGTH('1212-12-12');
CHAR_LENGTH('1212-12-12')
10
SELECT a, CHAR_LENGTH(a) FROM t1 ORDER BY a;
a CHAR_LENGTH(a)
aaaaa 5
bbbbbbbbbb 10
cccccccccccccccccccc 20
SELECT a, CHARACTER_LENGTH(a) FROM t1 ORDER BY a;
a CHARACTER_LENGTH(a)
aaaaa 5
bbbbbbbbbb 10
cccccccccccccccccccc 20
DROP TABLE t1;
CREATE TABLE t1 (a CHAR(1), b INT, c DATETIME, d DOUBLE)engine=tianmu;
INSERT INTO t1 VALUES ('', NULL, '1990-01-01', NULL),('a', 12, '1212-12-12', 1.19691E+100),('b', 13, '1313-3-13 13:13:13', 2.1961E+18),('c', 14, '1414-4-14', 0.16191),('d', 15, '2015-5-15 15:15:15', 1.971917);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(1) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` datetime DEFAULT NULL,
`d` double DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT a, CHARACTER_LENGTH(a) FROM t1 ORDER BY a;
a CHARACTER_LENGTH(a)
0
a 1
b 1
c 1
d 1
SELECT b, CHARACTER_LENGTH(b) FROM t1 ORDER BY b;
b CHARACTER_LENGTH(b)
NULL NULL
12 2
13 2
14 2
15 2
SELECT c, CHARACTER_LENGTH(c) FROM t1 ORDER BY c;
c CHARACTER_LENGTH(c)
1212-12-12 00:00:00 19
1313-03-13 13:13:13 19
1414-04-14 00:00:00 19
1990-01-01 00:00:00 19
2015-05-15 15:15:15 19
SELECT d, CHARACTER_LENGTH(d) FROM t1 ORDER BY d;
d CHARACTER_LENGTH(d)
NULL NULL
0.16191 7
1.971917 8
2.1961e18 9
1.19691e100 11
DROP DATABASE mcs182_db;
32 changes: 32 additions & 0 deletions mysql-test/suite/tianmu/r/date_function.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Test DATE function
# Author: syw
#
DROP DATABASE IF EXISTS mcs183_db;
CREATE DATABASE mcs183_db;
USE mcs183_db;
CREATE TABLE t1 (a DATE, b DATETIME)engine=tianmu;
INSERT INTO t1 VALUES ('1990-01-01', '1990-01-01 0:0:0'), ('1212-12-12', '1111-11-11 11:11:11'), ('3333-03-03', '3333-3-3 3:33:33');
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL,
`b` datetime DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT DATE('1212-12-12 11:11:11');
DATE('1212-12-12 11:11:11')
1212-12-12
SELECT DATE('2020-12-22');
DATE('2020-12-22')
2020-12-22
SELECT a, DATE(a) FROM t1 ORDER BY 1;
a DATE(a)
1212-12-12 1212-12-12
1990-01-01 1990-01-01
3333-03-03 3333-03-03
SELECT b, DATE(b) FROM t1 ORDER BY 1;
b DATE(b)
1111-11-11 11:11:11 1111-11-11
1990-01-01 00:00:00 1990-01-01
3333-03-03 03:33:33 3333-03-03
DROP DATABASE mcs183_db;
32 changes: 32 additions & 0 deletions mysql-test/suite/tianmu/r/day_function.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Test DAY function
# Author: syw
#
DROP DATABASE IF EXISTS mcs184_db;
CREATE DATABASE mcs184_db;
USE mcs184_db;
CREATE TABLE t1 (a DATE, b DATETIME)engine=tianmu;
INSERT INTO t1 VALUES ('1990-10-10', '1990-10-10 0:0:0'), ('1212-12-12', '1111-11-11 11:11:11'), ('3333-03-03', '3333-3-3 3:33:33');
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL,
`b` datetime DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT DAY('1212-12-12 11:11:11');
DAY('1212-12-12 11:11:11')
12
SELECT DAY('2020-12-22');
DAY('2020-12-22')
22
SELECT a, DAY(a) FROM t1 ORDER BY 1;
a DAY(a)
1212-12-12 12
1990-10-10 10
3333-03-03 3
SELECT b, DAY(b) FROM t1 ORDER BY 1;
b DAY(b)
1111-11-11 11:11:11 11
1990-10-10 00:00:00 10
3333-03-03 03:33:33 3
DROP DATABASE mcs184_db;
Loading