From 527346d4b6b015a0d90d7a05fc84216244b835ab Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 16:19:47 +0800 Subject: [PATCH 001/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130024/create_table.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 assignments/ass1/submission/18307130024/create_table.sql diff --git a/assignments/ass1/submission/18307130024/create_table.sql b/assignments/ass1/submission/18307130024/create_table.sql new file mode 100644 index 0000000..e69de29 From fd474eaef4f21e4e1312c6f4ed9064baa4bb5806 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 16:23:16 +0800 Subject: [PATCH 002/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130024/create_table.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/assignments/ass1/submission/18307130024/create_table.sql b/assignments/ass1/submission/18307130024/create_table.sql index e69de29..fbadd87 100644 --- a/assignments/ass1/submission/18307130024/create_table.sql +++ b/assignments/ass1/submission/18307130024/create_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE employee +( + INT id + , +); +INSERT INTO employee +VALUES + (1); \ No newline at end of file From 1a78c271500b61b63c474b674fa0209691947710 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 16:24:33 +0800 Subject: [PATCH 003/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130024/create_table.sql | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assignments/ass1/submission/18307130024/create_table.sql b/assignments/ass1/submission/18307130024/create_table.sql index fbadd87..44e431f 100644 --- a/assignments/ass1/submission/18307130024/create_table.sql +++ b/assignments/ass1/submission/18307130024/create_table.sql @@ -5,4 +5,8 @@ CREATE TABLE employee ); INSERT INTO employee VALUES - (1); \ No newline at end of file + (1); +CREATE TABLE eee +( + INT l +); \ No newline at end of file From 527fc952a804fe68ef96567ec7fa3cb2f8bad56c Mon Sep 17 00:00:00 2001 From: xudinghuan <61900920+xudinghuan@users.noreply.github.com> Date: Fri, 13 Mar 2020 01:35:53 -0700 Subject: [PATCH 004/189] Create 18307130031 --- assignments/ass1/submission/18307130031 | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/18307130031 diff --git a/assignments/ass1/submission/18307130031 b/assignments/ass1/submission/18307130031 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/assignments/ass1/submission/18307130031 @@ -0,0 +1 @@ + From b16003d251bae1d56a9f562f6991355d38c9e072 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 16:45:06 +0800 Subject: [PATCH 005/189] submission of xxx for ass1 --- .../submission/18307130024/create_table.sql | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/assignments/ass1/submission/18307130024/create_table.sql b/assignments/ass1/submission/18307130024/create_table.sql index 44e431f..153266c 100644 --- a/assignments/ass1/submission/18307130024/create_table.sql +++ b/assignments/ass1/submission/18307130024/create_table.sql @@ -1,12 +1,16 @@ -CREATE TABLE employee +create table employee ( - INT id - , + id int primary key, + name varchar(32), + office varchar(32), + age int constraint cstage check(age <= 100 and age >= 0) ); -INSERT INTO employee -VALUES - (1); -CREATE TABLE eee + +create table book ( - INT l -); \ No newline at end of file + id int primary key, + name varchar(32), + author varchar(32), + publisher varchar(32) +); + From d9a6f8420eab3948bfdb441e0f4d96e2d448f239 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 13 Mar 2020 16:49:15 +0800 Subject: [PATCH 006/189] update deadline --- content/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/index.md b/content/index.md index c24caff..e2a51a4 100644 --- a/content/index.md +++ b/content/index.md @@ -17,7 +17,8 @@ This course is an introductory course to database systems. In this course, you w |Week No.|Date|Content|Additional Materials| |--------|----|-------|-------------------| -|1|xx-xx|xxx|xxx| +|3|2020-03-13|Assignment 1 Released

|| +|4|2020-03-20|
Assignment 1 Due|| ## Assignment Guidance From 98b18a240980b8939a48cf66ce16618ad1465516 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 17:02:01 +0800 Subject: [PATCH 007/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130024/create_table.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assignments/ass1/submission/18307130024/create_table.sql b/assignments/ass1/submission/18307130024/create_table.sql index 153266c..be71b64 100644 --- a/assignments/ass1/submission/18307130024/create_table.sql +++ b/assignments/ass1/submission/18307130024/create_table.sql @@ -14,3 +14,12 @@ create table book publisher varchar(32) ); +create table record +( + book_id int, + employee_id int, + time date, + foreign key(book_id) references book(id) on delete cascade, + foreign key(employee_id) references employee(id) on delete cascade +); + From d427e46c3f7b42fdf7bec297b39d241a93010884 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 17:05:08 +0800 Subject: [PATCH 008/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130024/create_table.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/assignments/ass1/submission/18307130024/create_table.sql b/assignments/ass1/submission/18307130024/create_table.sql index be71b64..e0a821e 100644 --- a/assignments/ass1/submission/18307130024/create_table.sql +++ b/assignments/ass1/submission/18307130024/create_table.sql @@ -23,3 +23,4 @@ create table record foreign key(employee_id) references employee(id) on delete cascade ); +create table l(); \ No newline at end of file From 94058847df07ee6d3aa153e9df6649b301d35e57 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 17:24:06 +0800 Subject: [PATCH 009/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130024/1.sql | 3 +++ assignments/ass1/submission/18307130024/2.sql | 4 ++++ assignments/ass1/submission/18307130024/3.sql | 4 ++++ assignments/ass1/submission/18307130024/create_table.sql | 2 -- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 assignments/ass1/submission/18307130024/1.sql create mode 100644 assignments/ass1/submission/18307130024/2.sql create mode 100644 assignments/ass1/submission/18307130024/3.sql diff --git a/assignments/ass1/submission/18307130024/1.sql b/assignments/ass1/submission/18307130024/1.sql new file mode 100644 index 0000000..16d4edd --- /dev/null +++ b/assignments/ass1/submission/18307130024/1.sql @@ -0,0 +1,3 @@ +select * +from employee +where name = "Jones"; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/2.sql b/assignments/ass1/submission/18307130024/2.sql new file mode 100644 index 0000000..205c677 --- /dev/null +++ b/assignments/ass1/submission/18307130024/2.sql @@ -0,0 +1,4 @@ +select name +from employee +where id = 1 or id = 2 +; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/3.sql b/assignments/ass1/submission/18307130024/3.sql new file mode 100644 index 0000000..7198628 --- /dev/null +++ b/assignments/ass1/submission/18307130024/3.sql @@ -0,0 +1,4 @@ +select name +from employee +where id != 1 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/create_table.sql b/assignments/ass1/submission/18307130024/create_table.sql index e0a821e..c0f3cb1 100644 --- a/assignments/ass1/submission/18307130024/create_table.sql +++ b/assignments/ass1/submission/18307130024/create_table.sql @@ -22,5 +22,3 @@ create table record foreign key(book_id) references book(id) on delete cascade, foreign key(employee_id) references employee(id) on delete cascade ); - -create table l(); \ No newline at end of file From 1985486ba71496ab85e79daed6ed9d714dc3c0fe Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 13 Mar 2020 17:25:52 +0800 Subject: [PATCH 010/189] correct path --- content/assignment1/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/assignment1/readme.md b/content/assignment1/readme.md index fe7fda8..1c7547d 100644 --- a/content/assignment1/readme.md +++ b/content/assignment1/readme.md @@ -28,7 +28,7 @@ Then `git clone` your forked project in your local environment. You need to [set git clone https://github.com/your-github-id/IDBS-Spring20-Fudan.git ``` -Once you've cloned the project in your local environment, get to `IDBS-Spring20-Fudan/assignments/submission` and create a directory and name it by your student id, for example `IDBS-Spring20-Fudan/assignments/submission/16307130177`, and this directory will be your working directory. **You are ONLY allowed to modify files under this directory, any other modifications outside this directory will make your submission invalid.** +Once you've cloned the project in your local environment, get to `IDBS-Spring20-Fudan/assignments/ass1/submission` and create a directory and name it by your student id, for example `IDBS-Spring20-Fudan/assignments/ass1/submission/16307130177`, and this directory will be your working directory. **You are ONLY allowed to modify files under this directory, any other modifications outside this directory will make your submission invalid.** ## Table Creation From 8decaeff176238b89d745ff8160bfc2c33d3a306 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Fri, 13 Mar 2020 17:47:59 +0800 Subject: [PATCH 011/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130024/4.sql | 4 ++++ assignments/ass1/submission/18307130024/5.sql | 4 ++++ assignments/ass1/submission/18307130024/6.sql | 8 ++++++++ assignments/ass1/submission/18307130024/7.sql | 4 ++++ assignments/ass1/submission/18307130024/8.sql | 1 + 5 files changed, 21 insertions(+) create mode 100644 assignments/ass1/submission/18307130024/4.sql create mode 100644 assignments/ass1/submission/18307130024/5.sql create mode 100644 assignments/ass1/submission/18307130024/6.sql create mode 100644 assignments/ass1/submission/18307130024/7.sql create mode 100644 assignments/ass1/submission/18307130024/8.sql diff --git a/assignments/ass1/submission/18307130024/4.sql b/assignments/ass1/submission/18307130024/4.sql new file mode 100644 index 0000000..812b978 --- /dev/null +++ b/assignments/ass1/submission/18307130024/4.sql @@ -0,0 +1,4 @@ +select name +from employee +where age >= 25 and age <= 30 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/5.sql b/assignments/ass1/submission/18307130024/5.sql new file mode 100644 index 0000000..2f73db5 --- /dev/null +++ b/assignments/ass1/submission/18307130024/5.sql @@ -0,0 +1,4 @@ +select * +from employee +where name like 'J%' +order by age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/6.sql b/assignments/ass1/submission/18307130024/6.sql new file mode 100644 index 0000000..24dedbe --- /dev/null +++ b/assignments/ass1/submission/18307130024/6.sql @@ -0,0 +1,8 @@ +select distinct A.publisher +from book as A, book as B, book as C +where A.publisher = B.publisher + and B.publisher = C.publisher + and A.id != B.id + and B.id != C.id + and A.id != C.id +order by A.publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/7.sql b/assignments/ass1/submission/18307130024/7.sql new file mode 100644 index 0000000..1683b98 --- /dev/null +++ b/assignments/ass1/submission/18307130024/7.sql @@ -0,0 +1,4 @@ +select distinct book_id +from record +where unix_timestamp(time) > unix_timestamp('2016-10-31') +order by book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/8.sql b/assignments/ass1/submission/18307130024/8.sql new file mode 100644 index 0000000..79543a0 --- /dev/null +++ b/assignments/ass1/submission/18307130024/8.sql @@ -0,0 +1 @@ +select id, name; \ No newline at end of file From 14ed2bea75e9c1d697957da68c7013860e1ca699 Mon Sep 17 00:00:00 2001 From: 18300200015-cty <18300200015@fudan.edu.cn> Date: Fri, 13 Mar 2020 18:00:12 +0800 Subject: [PATCH 012/189] test --- assignments/ass1/submission/18300200015/create_table.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 assignments/ass1/submission/18300200015/create_table.sql diff --git a/assignments/ass1/submission/18300200015/create_table.sql b/assignments/ass1/submission/18300200015/create_table.sql new file mode 100644 index 0000000..e69de29 From 4fc30a3568627b1e5dab94139c5319334676a384 Mon Sep 17 00:00:00 2001 From: mirackk <49869026+mirackk@users.noreply.github.com> Date: Fri, 13 Mar 2020 20:19:27 +0800 Subject: [PATCH 013/189] for test --- test.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 test.md diff --git a/test.md b/test.md new file mode 100644 index 0000000..63d3c2d --- /dev/null +++ b/test.md @@ -0,0 +1 @@ +just for test From b6e5ea48ed309156f4003a6b464f15c096de8068 Mon Sep 17 00:00:00 2001 From: HatsuneHan <61576872@qq.com> Date: Fri, 13 Mar 2020 21:17:11 +0800 Subject: [PATCH 014/189] submission of hxy for ass1 --- assignments/ass1/submission/18300750006/1.sql | 1 + assignments/ass1/submission/18300750006/2.sql | 1 + assignments/ass1/submission/18300750006/3.sql | 1 + assignments/ass1/submission/18300750006/4.sql | 1 + assignments/ass1/submission/18300750006/5.sql | 1 + assignments/ass1/submission/18300750006/6.sql | 2 ++ assignments/ass1/submission/18300750006/7.sql | 2 ++ assignments/ass1/submission/18300750006/8.sql | 6 ++++++ .../submission/18300750006/create_table.sql | 18 ++++++++++++++++++ 9 files changed, 33 insertions(+) create mode 100644 assignments/ass1/submission/18300750006/1.sql create mode 100644 assignments/ass1/submission/18300750006/2.sql create mode 100644 assignments/ass1/submission/18300750006/3.sql create mode 100644 assignments/ass1/submission/18300750006/4.sql create mode 100644 assignments/ass1/submission/18300750006/5.sql create mode 100644 assignments/ass1/submission/18300750006/6.sql create mode 100644 assignments/ass1/submission/18300750006/7.sql create mode 100644 assignments/ass1/submission/18300750006/8.sql create mode 100644 assignments/ass1/submission/18300750006/create_table.sql diff --git a/assignments/ass1/submission/18300750006/1.sql b/assignments/ass1/submission/18300750006/1.sql new file mode 100644 index 0000000..c0e5dc9 --- /dev/null +++ b/assignments/ass1/submission/18300750006/1.sql @@ -0,0 +1 @@ +SELECT * FROM employee WHERE name="Jones" ; diff --git a/assignments/ass1/submission/18300750006/2.sql b/assignments/ass1/submission/18300750006/2.sql new file mode 100644 index 0000000..716608f --- /dev/null +++ b/assignments/ass1/submission/18300750006/2.sql @@ -0,0 +1 @@ +SELECT name FROM employee WHERE id = 1 OR id = 2 ; \ No newline at end of file diff --git a/assignments/ass1/submission/18300750006/3.sql b/assignments/ass1/submission/18300750006/3.sql new file mode 100644 index 0000000..de04d6e --- /dev/null +++ b/assignments/ass1/submission/18300750006/3.sql @@ -0,0 +1 @@ +SELECT name FROM employee WHERE id != 1 ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18300750006/4.sql b/assignments/ass1/submission/18300750006/4.sql new file mode 100644 index 0000000..43e343a --- /dev/null +++ b/assignments/ass1/submission/18300750006/4.sql @@ -0,0 +1 @@ +SELECT name FROM employee WHERE age <= 30 AND age >= 25 ORDER BY id ; \ No newline at end of file diff --git a/assignments/ass1/submission/18300750006/5.sql b/assignments/ass1/submission/18300750006/5.sql new file mode 100644 index 0000000..d8dba6b --- /dev/null +++ b/assignments/ass1/submission/18300750006/5.sql @@ -0,0 +1 @@ +SELECT * FROM employee WHERE name LIKE "J%" ORDER BY age ; \ No newline at end of file diff --git a/assignments/ass1/submission/18300750006/6.sql b/assignments/ass1/submission/18300750006/6.sql new file mode 100644 index 0000000..4e5b794 --- /dev/null +++ b/assignments/ass1/submission/18300750006/6.sql @@ -0,0 +1,2 @@ +SELECT DISTINCT X.publisher FROM book AS X , book AS Y + WHERE X.name != Y.name AND X.publisher = Y.publisher ORDER BY publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18300750006/7.sql b/assignments/ass1/submission/18300750006/7.sql new file mode 100644 index 0000000..26da632 --- /dev/null +++ b/assignments/ass1/submission/18300750006/7.sql @@ -0,0 +1,2 @@ +SELECT DISTINCT book_id FROM record + WHERE time > "2016-10-31" ORDER BY book_id ; \ No newline at end of file diff --git a/assignments/ass1/submission/18300750006/8.sql b/assignments/ass1/submission/18300750006/8.sql new file mode 100644 index 0000000..954e6f6 --- /dev/null +++ b/assignments/ass1/submission/18300750006/8.sql @@ -0,0 +1,6 @@ +SELECT employee.id, employee.name, COUNT(record.employee_id) + AS num FROM (employee INNER JOIN record + ON employee.id = record.employee_id ) + GROUP BY employee.id + HAVING COUNT(record.employee_id) >=2 + ORDER BY COUNT(record.employee_id) DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/18300750006/create_table.sql b/assignments/ass1/submission/18300750006/create_table.sql new file mode 100644 index 0000000..918af5e --- /dev/null +++ b/assignments/ass1/submission/18300750006/create_table.sql @@ -0,0 +1,18 @@ +CREATE TABLE employee + ( id VARCHAR(32) NOT NULL PRIMARY KEY, + name CHAR(32) NOT NULL, + office CHAR(32) NOT NULL, + age INT NOT NULL CHECK(age >= 0 AND age <= 100)); + +CREATE TABLE book + ( id VARCHAR(32) NOT NULL PRIMARY KEY, + name CHAR(32) NOT NULL, + author CHAR(32) NOT NULL, + publisher CHAR(32) NOT NULL); + +CREATE TABLE record + ( book_id VARCHAR(32) NOT NULL, + employee_id CHAR(32) NOT NULL, + time DATE NOT NULL, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id)); \ No newline at end of file From e820e1f0c23c42d06bfdbaf88e152fda6c5cd2c9 Mon Sep 17 00:00:00 2001 From: flock <863813609.qq.com> Date: Sat, 14 Mar 2020 10:28:27 +0800 Subject: [PATCH 015/189] submission of 18307130130 for ass1 --- assignments/ass1/submission/18307130130/1.sql | 3 +++ assignments/ass1/submission/18307130130/2.sql | 3 +++ assignments/ass1/submission/18307130130/3.sql | 4 ++++ assignments/ass1/submission/18307130130/4.sql | 4 ++++ assignments/ass1/submission/18307130130/5.sql | 4 ++++ assignments/ass1/submission/18307130130/6.sql | 5 +++++ assignments/ass1/submission/18307130130/7.sql | 4 ++++ assignments/ass1/submission/18307130130/8.sql | 6 ++++++ .../submission/18307130130/create_table.sql | 18 ++++++++++++++++++ 9 files changed, 51 insertions(+) create mode 100644 assignments/ass1/submission/18307130130/1.sql create mode 100644 assignments/ass1/submission/18307130130/2.sql create mode 100644 assignments/ass1/submission/18307130130/3.sql create mode 100644 assignments/ass1/submission/18307130130/4.sql create mode 100644 assignments/ass1/submission/18307130130/5.sql create mode 100644 assignments/ass1/submission/18307130130/6.sql create mode 100644 assignments/ass1/submission/18307130130/7.sql create mode 100644 assignments/ass1/submission/18307130130/8.sql create mode 100644 assignments/ass1/submission/18307130130/create_table.sql diff --git a/assignments/ass1/submission/18307130130/1.sql b/assignments/ass1/submission/18307130130/1.sql new file mode 100644 index 0000000..d55ab8e --- /dev/null +++ b/assignments/ass1/submission/18307130130/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE employee.name='Jones'; diff --git a/assignments/ass1/submission/18307130130/2.sql b/assignments/ass1/submission/18307130130/2.sql new file mode 100644 index 0000000..f1a619f --- /dev/null +++ b/assignments/ass1/submission/18307130130/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE employee.id='1' OR id='2'; diff --git a/assignments/ass1/submission/18307130130/3.sql b/assignments/ass1/submission/18307130130/3.sql new file mode 100644 index 0000000..3a66f20 --- /dev/null +++ b/assignments/ass1/submission/18307130130/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE employee.id!='1' +ORDER BY id DESC; diff --git a/assignments/ass1/submission/18307130130/4.sql b/assignments/ass1/submission/18307130130/4.sql new file mode 100644 index 0000000..417734f --- /dev/null +++ b/assignments/ass1/submission/18307130130/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE employee.age>=25 AND age<=30 +ORDER BY id DESC; diff --git a/assignments/ass1/submission/18307130130/5.sql b/assignments/ass1/submission/18307130130/5.sql new file mode 100644 index 0000000..b8a1f33 --- /dev/null +++ b/assignments/ass1/submission/18307130130/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name LIKE 'J%' +ORDER BY age; diff --git a/assignments/ass1/submission/18307130130/6.sql b/assignments/ass1/submission/18307130130/6.sql new file mode 100644 index 0000000..ed175e3 --- /dev/null +++ b/assignments/ass1/submission/18307130130/6.sql @@ -0,0 +1,5 @@ +SELECT DISTINCT publisher +FROM book +GROUP BY publisher + HAVING COUNT(*)>1 +ORDER BY publisher ; diff --git a/assignments/ass1/submission/18307130130/7.sql b/assignments/ass1/submission/18307130130/7.sql new file mode 100644 index 0000000..95baaba --- /dev/null +++ b/assignments/ass1/submission/18307130130/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT book_id +FROM record +WHERE time>'2016-10-31' +ORDER BY book_id; diff --git a/assignments/ass1/submission/18307130130/8.sql b/assignments/ass1/submission/18307130130/8.sql new file mode 100644 index 0000000..21e7e61 --- /dev/null +++ b/assignments/ass1/submission/18307130130/8.sql @@ -0,0 +1,6 @@ +SELECT employee.id,name,COUNT(*) as num +FROM employee LEFT OUTER JOIN record ON employee.id=record.employee_id +GROUP BY employee.id + HAVING COUNT(*)>1 +ORDER BY 3 DESC; + diff --git a/assignments/ass1/submission/18307130130/create_table.sql b/assignments/ass1/submission/18307130130/create_table.sql new file mode 100644 index 0000000..1851de3 --- /dev/null +++ b/assignments/ass1/submission/18307130130/create_table.sql @@ -0,0 +1,18 @@ +CREATE TABLE `employee` + (`id` VARCHAR(32) NOT NULL, + `name` VARCHAR(32) NOT NULL, + `office` VARCHAR(32) NOT NULL, + `age` INTEGER NOT NULL, + PRIMARY KEY(`id`)); +CREATE TABLE `book` + (`id` VARCHAR(32) NOT NULL, + `name` VARCHAR(32) NOT NULL, + `author` VARCHAR(32) NOT NULL, + `publisher` VARCHAR(32) NOT NULL, + PRIMARY KEY(`id`)); +CREATE TABLE `record` + (book_id VARCHAR(32) NOT NULL, + employee_id VARCHAR(32) NOT NULL, + `time` DATE NOT NULL, + FOREIGN KEY (book_id) REFERENCES book (`id`), + FOREIGN KEY (employee_id) REFERENCES employee (`id`)); From b63ffe8a6950006d9765812ddbd7c58671631533 Mon Sep 17 00:00:00 2001 From: Fan Date: Sat, 14 Mar 2020 11:04:24 +0800 Subject: [PATCH 016/189] submission of 18307130182 for ass1 --- assignments/ass1/submission/18307130182/1.sql | 1 + assignments/ass1/submission/18307130182/2.sql | 2 ++ assignments/ass1/submission/18307130182/3.sql | 3 +++ assignments/ass1/submission/18307130182/4.sql | 3 +++ assignments/ass1/submission/18307130182/5.sql | 3 +++ assignments/ass1/submission/18307130182/6.sql | 2 ++ assignments/ass1/submission/18307130182/7.sql | 2 ++ assignments/ass1/submission/18307130182/8.sql | 5 ++++ .../submission/18307130182/create_table.sql | 23 +++++++++++++++++++ 9 files changed, 44 insertions(+) create mode 100644 assignments/ass1/submission/18307130182/1.sql create mode 100644 assignments/ass1/submission/18307130182/2.sql create mode 100644 assignments/ass1/submission/18307130182/3.sql create mode 100644 assignments/ass1/submission/18307130182/4.sql create mode 100644 assignments/ass1/submission/18307130182/5.sql create mode 100644 assignments/ass1/submission/18307130182/6.sql create mode 100644 assignments/ass1/submission/18307130182/7.sql create mode 100644 assignments/ass1/submission/18307130182/8.sql create mode 100644 assignments/ass1/submission/18307130182/create_table.sql diff --git a/assignments/ass1/submission/18307130182/1.sql b/assignments/ass1/submission/18307130182/1.sql new file mode 100644 index 0000000..c2e92f5 --- /dev/null +++ b/assignments/ass1/submission/18307130182/1.sql @@ -0,0 +1 @@ +SELECT * FROM employee WHERE name='Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/2.sql b/assignments/ass1/submission/18307130182/2.sql new file mode 100644 index 0000000..99488a3 --- /dev/null +++ b/assignments/ass1/submission/18307130182/2.sql @@ -0,0 +1,2 @@ +SELECT name FROM employee +WHERE id=1 OR id=2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/3.sql b/assignments/ass1/submission/18307130182/3.sql new file mode 100644 index 0000000..6054930 --- /dev/null +++ b/assignments/ass1/submission/18307130182/3.sql @@ -0,0 +1,3 @@ +SELECT name FROM employee +WHERE id!=1 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/4.sql b/assignments/ass1/submission/18307130182/4.sql new file mode 100644 index 0000000..97c89e2 --- /dev/null +++ b/assignments/ass1/submission/18307130182/4.sql @@ -0,0 +1,3 @@ +SELECT name FROM employee +WHERE age BETWEEN 25 AND 30 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/5.sql b/assignments/ass1/submission/18307130182/5.sql new file mode 100644 index 0000000..a809598 --- /dev/null +++ b/assignments/ass1/submission/18307130182/5.sql @@ -0,0 +1,3 @@ +SELECT * FROM employee +WHERE name LIKE 'j%' +ORDER BY age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/6.sql b/assignments/ass1/submission/18307130182/6.sql new file mode 100644 index 0000000..ea97397 --- /dev/null +++ b/assignments/ass1/submission/18307130182/6.sql @@ -0,0 +1,2 @@ +SELECT DISTINCT publisher FROM book +ORDER BY publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/7.sql b/assignments/ass1/submission/18307130182/7.sql new file mode 100644 index 0000000..2ab12d8 --- /dev/null +++ b/assignments/ass1/submission/18307130182/7.sql @@ -0,0 +1,2 @@ +SELECT DISTINCT book_id FROM record +WHERE time>'2016-10-31'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/8.sql b/assignments/ass1/submission/18307130182/8.sql new file mode 100644 index 0000000..bdf4fde --- /dev/null +++ b/assignments/ass1/submission/18307130182/8.sql @@ -0,0 +1,5 @@ +SELECT employee.id, employee.name, COUNT(*) AS num +FROM employee INNER JOIN record ON employee.id=record.employee_id +GROUP BY employee.id +HAVING num>1 +ORDER BY num DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130182/create_table.sql b/assignments/ass1/submission/18307130182/create_table.sql new file mode 100644 index 0000000..60b6876 --- /dev/null +++ b/assignments/ass1/submission/18307130182/create_table.sql @@ -0,0 +1,23 @@ +CREATE TABLE employee( + id INT PRIMARY KEY, + name VARCHAR(32), + office VARCHAR(32), + age TINYINT +); + +CREATE TABLE book( + id INT PRIMARY KEY, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32) +); + +CREATE TABLE record( + book_id INT, + employee_id INT, + time DATE, + FOREIGN KEY (book_id) + REFERENCES book(id), + FOREIGN KEY (employee_id) + REFERENCES employee(id) +); \ No newline at end of file From d558ee792999b7589ff0b8338cb24bedeb9de7f0 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Sat, 14 Mar 2020 17:52:25 +0800 Subject: [PATCH 017/189] submission of 18307130024 for ass1 --- assignments/ass1/submission/18307130024/6.sql | 13 +++++-------- assignments/ass1/submission/18307130024/8.sql | 8 +++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/assignments/ass1/submission/18307130024/6.sql b/assignments/ass1/submission/18307130024/6.sql index 24dedbe..bfd247d 100644 --- a/assignments/ass1/submission/18307130024/6.sql +++ b/assignments/ass1/submission/18307130024/6.sql @@ -1,8 +1,5 @@ -select distinct A.publisher -from book as A, book as B, book as C -where A.publisher = B.publisher - and B.publisher = C.publisher - and A.id != B.id - and B.id != C.id - and A.id != C.id -order by A.publisher; \ No newline at end of file +select distinct publisher +from book +group by publisher +having count(*) > 2 +order by publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/8.sql b/assignments/ass1/submission/18307130024/8.sql index 79543a0..1419129 100644 --- a/assignments/ass1/submission/18307130024/8.sql +++ b/assignments/ass1/submission/18307130024/8.sql @@ -1 +1,7 @@ -select id, name; \ No newline at end of file +select id, name, count(employee_id) as num +from record, employee +where employee_id = id +group by employee_id +having num > 1 +order by num desc +; \ No newline at end of file From 02429b81ee166318fa33c71410c95e6737a73e1d Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Sat, 14 Mar 2020 17:55:56 +0800 Subject: [PATCH 018/189] submission of 18307130024 for ass1 --- assignments/ass1/submission/18307130024/1.sql | 3 ++- assignments/ass1/submission/18307130024/2.sql | 2 +- assignments/ass1/submission/18307130024/3.sql | 3 ++- assignments/ass1/submission/18307130024/4.sql | 3 ++- assignments/ass1/submission/18307130024/5.sql | 3 ++- assignments/ass1/submission/18307130024/6.sql | 3 ++- assignments/ass1/submission/18307130024/7.sql | 3 ++- assignments/ass1/submission/18307130024/8.sql | 2 +- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/assignments/ass1/submission/18307130024/1.sql b/assignments/ass1/submission/18307130024/1.sql index 16d4edd..baa7807 100644 --- a/assignments/ass1/submission/18307130024/1.sql +++ b/assignments/ass1/submission/18307130024/1.sql @@ -1,3 +1,4 @@ select * from employee -where name = "Jones"; \ No newline at end of file +where name = "Jones" +; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/2.sql b/assignments/ass1/submission/18307130024/2.sql index 205c677..8e53280 100644 --- a/assignments/ass1/submission/18307130024/2.sql +++ b/assignments/ass1/submission/18307130024/2.sql @@ -1,4 +1,4 @@ select name from employee where id = 1 or id = 2 -; \ No newline at end of file +; diff --git a/assignments/ass1/submission/18307130024/3.sql b/assignments/ass1/submission/18307130024/3.sql index 7198628..f2e016c 100644 --- a/assignments/ass1/submission/18307130024/3.sql +++ b/assignments/ass1/submission/18307130024/3.sql @@ -1,4 +1,5 @@ select name from employee where id != 1 -order by id; \ No newline at end of file +order by id +; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/4.sql b/assignments/ass1/submission/18307130024/4.sql index 812b978..d030a45 100644 --- a/assignments/ass1/submission/18307130024/4.sql +++ b/assignments/ass1/submission/18307130024/4.sql @@ -1,4 +1,5 @@ select name from employee where age >= 25 and age <= 30 -order by id; \ No newline at end of file +order by id +; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/5.sql b/assignments/ass1/submission/18307130024/5.sql index 2f73db5..2c42a01 100644 --- a/assignments/ass1/submission/18307130024/5.sql +++ b/assignments/ass1/submission/18307130024/5.sql @@ -1,4 +1,5 @@ select * from employee where name like 'J%' -order by age; \ No newline at end of file +order by age +; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/6.sql b/assignments/ass1/submission/18307130024/6.sql index bfd247d..06fa72b 100644 --- a/assignments/ass1/submission/18307130024/6.sql +++ b/assignments/ass1/submission/18307130024/6.sql @@ -2,4 +2,5 @@ select distinct publisher from book group by publisher having count(*) > 2 -order by publisher; \ No newline at end of file +order by publisher +; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/7.sql b/assignments/ass1/submission/18307130024/7.sql index 1683b98..6865e0b 100644 --- a/assignments/ass1/submission/18307130024/7.sql +++ b/assignments/ass1/submission/18307130024/7.sql @@ -1,4 +1,5 @@ select distinct book_id from record where unix_timestamp(time) > unix_timestamp('2016-10-31') -order by book_id; \ No newline at end of file +order by book_id +; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130024/8.sql b/assignments/ass1/submission/18307130024/8.sql index 1419129..a87b24e 100644 --- a/assignments/ass1/submission/18307130024/8.sql +++ b/assignments/ass1/submission/18307130024/8.sql @@ -4,4 +4,4 @@ where employee_id = id group by employee_id having num > 1 order by num desc -; \ No newline at end of file +; From 67c23015e53a0faf364666dd64b8c23749983af2 Mon Sep 17 00:00:00 2001 From: EZlzh <1127598375@qq.com> Date: Sat, 14 Mar 2020 21:35:53 +0800 Subject: [PATCH 019/189] submission of 18307130126 for ass1 --- assignments/ass1/submission/18307130126/1.sql | 3 +++ assignments/ass1/submission/18307130126/2.sql | 3 +++ assignments/ass1/submission/18307130126/3.sql | 3 +++ assignments/ass1/submission/18307130126/4.sql | 3 +++ assignments/ass1/submission/18307130126/5.sql | 3 +++ assignments/ass1/submission/18307130126/6.sql | 3 +++ assignments/ass1/submission/18307130126/7.sql | 3 +++ assignments/ass1/submission/18307130126/8.sql | 5 +++++ .../submission/18307130126/create_table.sql | 22 +++++++++++++++++++ 9 files changed, 48 insertions(+) create mode 100644 assignments/ass1/submission/18307130126/1.sql create mode 100644 assignments/ass1/submission/18307130126/2.sql create mode 100644 assignments/ass1/submission/18307130126/3.sql create mode 100644 assignments/ass1/submission/18307130126/4.sql create mode 100644 assignments/ass1/submission/18307130126/5.sql create mode 100644 assignments/ass1/submission/18307130126/6.sql create mode 100644 assignments/ass1/submission/18307130126/7.sql create mode 100644 assignments/ass1/submission/18307130126/8.sql create mode 100644 assignments/ass1/submission/18307130126/create_table.sql diff --git a/assignments/ass1/submission/18307130126/1.sql b/assignments/ass1/submission/18307130126/1.sql new file mode 100644 index 0000000..eaf45d4 --- /dev/null +++ b/assignments/ass1/submission/18307130126/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name='Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/2.sql b/assignments/ass1/submission/18307130126/2.sql new file mode 100644 index 0000000..c626871 --- /dev/null +++ b/assignments/ass1/submission/18307130126/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id=1 OR id=2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/3.sql b/assignments/ass1/submission/18307130126/3.sql new file mode 100644 index 0000000..954f7ea --- /dev/null +++ b/assignments/ass1/submission/18307130126/3.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id!=1 ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/4.sql b/assignments/ass1/submission/18307130126/4.sql new file mode 100644 index 0000000..010ba27 --- /dev/null +++ b/assignments/ass1/submission/18307130126/4.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE age between 25 and 30 ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/5.sql b/assignments/ass1/submission/18307130126/5.sql new file mode 100644 index 0000000..5335afc --- /dev/null +++ b/assignments/ass1/submission/18307130126/5.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name like 'J%' ORDER BY age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/6.sql b/assignments/ass1/submission/18307130126/6.sql new file mode 100644 index 0000000..b3c7f10 --- /dev/null +++ b/assignments/ass1/submission/18307130126/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT X.publisher +FROM book AS X, book AS Y +WHERE X.publisher=Y.publisher AND X.id!=Y.id ORDER BY publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/7.sql b/assignments/ass1/submission/18307130126/7.sql new file mode 100644 index 0000000..dacf3eb --- /dev/null +++ b/assignments/ass1/submission/18307130126/7.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT book_id +FROM record +WHERE time>'2016-10-31' ORDER BY book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/8.sql b/assignments/ass1/submission/18307130126/8.sql new file mode 100644 index 0000000..625c5bf --- /dev/null +++ b/assignments/ass1/submission/18307130126/8.sql @@ -0,0 +1,5 @@ +SELECT id, name, COUNT(*) AS num +FROM employee INNER JOIN record ON id=employee_id +GROUP BY id +HAVING num>1 +ORDER BY num DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130126/create_table.sql b/assignments/ass1/submission/18307130126/create_table.sql new file mode 100644 index 0000000..cd4dc99 --- /dev/null +++ b/assignments/ass1/submission/18307130126/create_table.sql @@ -0,0 +1,22 @@ +CREATE TABLE employee + (id INT NOT NULL, + name CHAR (32), + office CHAR (32), + age INT CHECK(age between 0 and 100), + PRIMARY KEY (id)); + +CREATE TABLE book + (id INT NOT NULL, + name CHAR (32), + author CHAR (32), + publisher CHAR (32), + PRIMARY KEY (id)); + +CREATE TABLE record + (book_id INT, + employee_id INT, + time DATE, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id)); + + \ No newline at end of file From 1fc61ff437bb551c1e18f67dba63717174a57abd Mon Sep 17 00:00:00 2001 From: 18307130128-yanghang <18307130128@fudan.edu.cn> Date: Sun, 15 Mar 2020 14:32:15 +0800 Subject: [PATCH 020/189] submission of 18307130128 for ass1 --- assignments/ass1/submission/18307130128/1.sql | 3 +++ assignments/ass1/submission/18307130128/2.sql | 3 +++ assignments/ass1/submission/18307130128/3.sql | 4 ++++ assignments/ass1/submission/18307130128/4.sql | 4 ++++ assignments/ass1/submission/18307130128/5.sql | 4 ++++ assignments/ass1/submission/18307130128/6.sql | 4 ++++ assignments/ass1/submission/18307130128/7.sql | 4 ++++ assignments/ass1/submission/18307130128/8.sql | 6 +++++ .../submission/18307130128/create_table.sql | 23 +++++++++++++++++++ 9 files changed, 55 insertions(+) create mode 100644 assignments/ass1/submission/18307130128/1.sql create mode 100644 assignments/ass1/submission/18307130128/2.sql create mode 100644 assignments/ass1/submission/18307130128/3.sql create mode 100644 assignments/ass1/submission/18307130128/4.sql create mode 100644 assignments/ass1/submission/18307130128/5.sql create mode 100644 assignments/ass1/submission/18307130128/6.sql create mode 100644 assignments/ass1/submission/18307130128/7.sql create mode 100644 assignments/ass1/submission/18307130128/8.sql create mode 100644 assignments/ass1/submission/18307130128/create_table.sql diff --git a/assignments/ass1/submission/18307130128/1.sql b/assignments/ass1/submission/18307130128/1.sql new file mode 100644 index 0000000..b642003 --- /dev/null +++ b/assignments/ass1/submission/18307130128/1.sql @@ -0,0 +1,3 @@ +select * +from employee +where name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130128/2.sql b/assignments/ass1/submission/18307130128/2.sql new file mode 100644 index 0000000..ac99236 --- /dev/null +++ b/assignments/ass1/submission/18307130128/2.sql @@ -0,0 +1,3 @@ +select name +from employee +where id = 1 or id = 2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130128/3.sql b/assignments/ass1/submission/18307130128/3.sql new file mode 100644 index 0000000..7198628 --- /dev/null +++ b/assignments/ass1/submission/18307130128/3.sql @@ -0,0 +1,4 @@ +select name +from employee +where id != 1 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130128/4.sql b/assignments/ass1/submission/18307130128/4.sql new file mode 100644 index 0000000..5db48e1 --- /dev/null +++ b/assignments/ass1/submission/18307130128/4.sql @@ -0,0 +1,4 @@ +select name +from employee +where age between 25 and 30 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130128/5.sql b/assignments/ass1/submission/18307130128/5.sql new file mode 100644 index 0000000..2f73db5 --- /dev/null +++ b/assignments/ass1/submission/18307130128/5.sql @@ -0,0 +1,4 @@ +select * +from employee +where name like 'J%' +order by age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130128/6.sql b/assignments/ass1/submission/18307130128/6.sql new file mode 100644 index 0000000..18b8f12 --- /dev/null +++ b/assignments/ass1/submission/18307130128/6.sql @@ -0,0 +1,4 @@ +select distinct publisher +from book +where publisher is not null +order by 1; diff --git a/assignments/ass1/submission/18307130128/7.sql b/assignments/ass1/submission/18307130128/7.sql new file mode 100644 index 0000000..fad0c79 --- /dev/null +++ b/assignments/ass1/submission/18307130128/7.sql @@ -0,0 +1,4 @@ +select distinct book_id +from record +where time > '2016-10-31' +order by 1; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130128/8.sql b/assignments/ass1/submission/18307130128/8.sql new file mode 100644 index 0000000..7895d9e --- /dev/null +++ b/assignments/ass1/submission/18307130128/8.sql @@ -0,0 +1,6 @@ +select id, name, count(*) as num +from employee, record +where employee.id = record.employee_id +group by id + having num > 1 +order by 3; diff --git a/assignments/ass1/submission/18307130128/create_table.sql b/assignments/ass1/submission/18307130128/create_table.sql new file mode 100644 index 0000000..efe8dcb --- /dev/null +++ b/assignments/ass1/submission/18307130128/create_table.sql @@ -0,0 +1,23 @@ +create table employee( + id int, + name varchar(32), + office varchar(32), + age int check (age between 0 and 100), + primary key(id) +); + +create table book( + id int, + name varchar(32), + author varchar(32), + publisher varchar(32), + primary key(id) +); + +create table record( + book_id int, + employee_id int, + time date, + foreign key(book_id) references book(id), + foreign key(employee_id) references employee(id) +); \ No newline at end of file From 508d5d20ecb5f7a3d723b5a8b471761cd134809a Mon Sep 17 00:00:00 2001 From: 18307130071-YuhengZhao <18307130071@fudan.edu.cn> Date: Sun, 15 Mar 2020 16:06:25 +0800 Subject: [PATCH 021/189] submission of YuhengZhao_18307130071 for ass1 --- assignments/ass1/submission/18307130071/1.sql | 3 +++ assignments/ass1/submission/18307130071/2.sql | 3 +++ assignments/ass1/submission/18307130071/3.sql | 6 +++++ assignments/ass1/submission/18307130071/4.sql | 6 +++++ assignments/ass1/submission/18307130071/5.sql | 4 ++++ assignments/ass1/submission/18307130071/6.sql | 5 +++++ assignments/ass1/submission/18307130071/7.sql | 3 +++ assignments/ass1/submission/18307130071/8.sql | 4 ++++ .../submission/18307130071/create_table.sql | 22 +++++++++++++++++++ 9 files changed, 56 insertions(+) create mode 100644 assignments/ass1/submission/18307130071/1.sql create mode 100644 assignments/ass1/submission/18307130071/2.sql create mode 100644 assignments/ass1/submission/18307130071/3.sql create mode 100644 assignments/ass1/submission/18307130071/4.sql create mode 100644 assignments/ass1/submission/18307130071/5.sql create mode 100644 assignments/ass1/submission/18307130071/6.sql create mode 100644 assignments/ass1/submission/18307130071/7.sql create mode 100644 assignments/ass1/submission/18307130071/8.sql create mode 100644 assignments/ass1/submission/18307130071/create_table.sql diff --git a/assignments/ass1/submission/18307130071/1.sql b/assignments/ass1/submission/18307130071/1.sql new file mode 100644 index 0000000..9b5894e --- /dev/null +++ b/assignments/ass1/submission/18307130071/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name = `jones`; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130071/2.sql b/assignments/ass1/submission/18307130071/2.sql new file mode 100644 index 0000000..7db6127 --- /dev/null +++ b/assignments/ass1/submission/18307130071/2.sql @@ -0,0 +1,3 @@ +SELECT `name` +FROM empolyee +WHERE id = '1' OR id = '2'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130071/3.sql b/assignments/ass1/submission/18307130071/3.sql new file mode 100644 index 0000000..b425ff4 --- /dev/null +++ b/assignments/ass1/submission/18307130071/3.sql @@ -0,0 +1,6 @@ +SELECT `name` +FROM employee +WHERE NOT EXISTS ( SELECT * + FROM employee + WHERE id = '1' ) +ORDER BY `id`; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130071/4.sql b/assignments/ass1/submission/18307130071/4.sql new file mode 100644 index 0000000..dada85d --- /dev/null +++ b/assignments/ass1/submission/18307130071/4.sql @@ -0,0 +1,6 @@ +SELECT `name` +FROM employee +WHERE EXISTS (SELECT * + FROM employee + WHERE age BETWEEN '25' AND '30') +ORDER BY `id`; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130071/5.sql b/assignments/ass1/submission/18307130071/5.sql new file mode 100644 index 0000000..51b5369 --- /dev/null +++ b/assignments/ass1/submission/18307130071/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE `name` like 'J%' +ORDER BY `age`; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130071/6.sql b/assignments/ass1/submission/18307130071/6.sql new file mode 100644 index 0000000..9affcbe --- /dev/null +++ b/assignments/ass1/submission/18307130071/6.sql @@ -0,0 +1,5 @@ +SELECT `publisher` +FROM book +GROUP BY `publisher` +HAVING count(*) > 1 +ORDER BY `name`; diff --git a/assignments/ass1/submission/18307130071/7.sql b/assignments/ass1/submission/18307130071/7.sql new file mode 100644 index 0000000..f955257 --- /dev/null +++ b/assignments/ass1/submission/18307130071/7.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT id +FROM book, record +WHERE `id` = `book_id` AND `time`.AFTER (2016-10-31); \ No newline at end of file diff --git a/assignments/ass1/submission/18307130071/8.sql b/assignments/ass1/submission/18307130071/8.sql new file mode 100644 index 0000000..a48485a --- /dev/null +++ b/assignments/ass1/submission/18307130071/8.sql @@ -0,0 +1,4 @@ +SELECT `id`, `name`, num +FROM ( SELECT `id`, `name`, COUNT(*) AS num FROM record GROUP BY employee_id HAVING num > 1 ) AS A, employee +WHERE `id` = `employee_id` +ORDER BY num DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130071/create_table.sql b/assignments/ass1/submission/18307130071/create_table.sql new file mode 100644 index 0000000..2eb4672 --- /dev/null +++ b/assignments/ass1/submission/18307130071/create_table.sql @@ -0,0 +1,22 @@ + +CREATE TABLE employee ( + `id` int , + `name` char(32) , + `office` char(32) , + `age` int CHECK (age>0&&age<100) , + PRIMARY KEY (`id`) +); +CREATE TABLE book ( + `id` char(32) , + `name` char(32) , + `author` char(32) , + `publisher` char(32) , + PRIMARY KEY (`id`) +); +CREATE TABLE record ( + `book_id` char(32) , + `employee_id` int , + `time` DATE, + FOREIGN KEY (`book_id`) REFERENCES book(`id`), + FOREIGN KEY (`employee_id`) REFERENCES employee(`id`) +) \ No newline at end of file From 5e3e4819bdab411a102b2688d6578a987a4f780d Mon Sep 17 00:00:00 2001 From: 18300200015-cty <18300200015@fudan.edu.cn> Date: Sun, 15 Mar 2020 16:13:37 +0800 Subject: [PATCH 022/189] submission of cty for ass1 --- assignments/ass1/submission/18300200015/1.sql | 3 +++ assignments/ass1/submission/18300200015/2.sql | 3 +++ assignments/ass1/submission/18300200015/3.sql | 4 ++++ assignments/ass1/submission/18300200015/4.sql | 4 ++++ assignments/ass1/submission/18300200015/5.sql | 4 ++++ assignments/ass1/submission/18300200015/6.sql | 4 ++++ assignments/ass1/submission/18300200015/7.sql | 4 ++++ assignments/ass1/submission/18300200015/8.sql | 6 +++++ .../submission/18300200015/create_table.sql | 23 +++++++++++++++++++ 9 files changed, 55 insertions(+) create mode 100644 assignments/ass1/submission/18300200015/1.sql create mode 100644 assignments/ass1/submission/18300200015/2.sql create mode 100644 assignments/ass1/submission/18300200015/3.sql create mode 100644 assignments/ass1/submission/18300200015/4.sql create mode 100644 assignments/ass1/submission/18300200015/5.sql create mode 100644 assignments/ass1/submission/18300200015/6.sql create mode 100644 assignments/ass1/submission/18300200015/7.sql create mode 100644 assignments/ass1/submission/18300200015/8.sql diff --git a/assignments/ass1/submission/18300200015/1.sql b/assignments/ass1/submission/18300200015/1.sql new file mode 100644 index 0000000..25a69a7 --- /dev/null +++ b/assignments/ass1/submission/18300200015/1.sql @@ -0,0 +1,3 @@ +select * +from employee +where name='Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/2.sql b/assignments/ass1/submission/18300200015/2.sql new file mode 100644 index 0000000..37b4864 --- /dev/null +++ b/assignments/ass1/submission/18300200015/2.sql @@ -0,0 +1,3 @@ +select name +from employee +where id='1' or id='2'; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/3.sql b/assignments/ass1/submission/18300200015/3.sql new file mode 100644 index 0000000..5c948a6 --- /dev/null +++ b/assignments/ass1/submission/18300200015/3.sql @@ -0,0 +1,4 @@ +select name +from employee +where id!='1' +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/4.sql b/assignments/ass1/submission/18300200015/4.sql new file mode 100644 index 0000000..11a4b14 --- /dev/null +++ b/assignments/ass1/submission/18300200015/4.sql @@ -0,0 +1,4 @@ +select name +from employee +where age>=25 and age<=30 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/5.sql b/assignments/ass1/submission/18300200015/5.sql new file mode 100644 index 0000000..2f73db5 --- /dev/null +++ b/assignments/ass1/submission/18300200015/5.sql @@ -0,0 +1,4 @@ +select * +from employee +where name like 'J%' +order by age; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/6.sql b/assignments/ass1/submission/18300200015/6.sql new file mode 100644 index 0000000..6e9153d --- /dev/null +++ b/assignments/ass1/submission/18300200015/6.sql @@ -0,0 +1,4 @@ +select distinct x.publisher +from book as x,book as y +where x.publisher=y.publisher and x.name!=y.name +order by publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/7.sql b/assignments/ass1/submission/18300200015/7.sql new file mode 100644 index 0000000..03e6ada --- /dev/null +++ b/assignments/ass1/submission/18300200015/7.sql @@ -0,0 +1,4 @@ +select book_id +from record +where time>'2016-10-31' +order by book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/8.sql b/assignments/ass1/submission/18300200015/8.sql new file mode 100644 index 0000000..9d5e526 --- /dev/null +++ b/assignments/ass1/submission/18300200015/8.sql @@ -0,0 +1,6 @@ +select employee.id,employee.name,count(record.employee_id) +from record,employee +where record.employee_id=employee.id +group by employee.id +having count(record.employee_id)>=2 +order by count(record.employee_id) desc; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200015/create_table.sql b/assignments/ass1/submission/18300200015/create_table.sql index e69de29..836b128 100644 --- a/assignments/ass1/submission/18300200015/create_table.sql +++ b/assignments/ass1/submission/18300200015/create_table.sql @@ -0,0 +1,23 @@ +create table employee( + id int, + name varchar(32), + office varchar(32), + age smallint, + primary key(id) +); + +create table book( + id int, + name varchar(32), + author varchar(32), + publisher varchar(32), + primary key(id) +); + +create table record( + book_id int, + employee_id int, + time date, + foreign key(book_id)references book(id), + foreign key(employee_id)references employee(id) +); \ No newline at end of file From e3b2c91ecda8aa6b296ce3532de2af81a31e3c93 Mon Sep 17 00:00:00 2001 From: vincy233 <644255997@qq.com> Date: Sun, 15 Mar 2020 18:04:32 +0800 Subject: [PATCH 023/189] submission of 18307130341 for ass1 --- assignments/ass1/submission/18307130341/1.sql | 3 +++ assignments/ass1/submission/18307130341/2.sql | 3 +++ assignments/ass1/submission/18307130341/3.sql | 4 ++++ assignments/ass1/submission/18307130341/4.sql | 4 ++++ assignments/ass1/submission/18307130341/5.sql | 4 ++++ assignments/ass1/submission/18307130341/6.sql | 3 +++ assignments/ass1/submission/18307130341/7.sql | 4 ++++ assignments/ass1/submission/18307130341/8.sql | 6 ++++++ .../submission/18307130341/create_table.sql | 20 +++++++++++++++++++ 9 files changed, 51 insertions(+) create mode 100644 assignments/ass1/submission/18307130341/1.sql create mode 100644 assignments/ass1/submission/18307130341/2.sql create mode 100644 assignments/ass1/submission/18307130341/3.sql create mode 100644 assignments/ass1/submission/18307130341/4.sql create mode 100644 assignments/ass1/submission/18307130341/5.sql create mode 100644 assignments/ass1/submission/18307130341/6.sql create mode 100644 assignments/ass1/submission/18307130341/7.sql create mode 100644 assignments/ass1/submission/18307130341/8.sql create mode 100644 assignments/ass1/submission/18307130341/create_table.sql diff --git a/assignments/ass1/submission/18307130341/1.sql b/assignments/ass1/submission/18307130341/1.sql new file mode 100644 index 0000000..d55ab8e --- /dev/null +++ b/assignments/ass1/submission/18307130341/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE employee.name='Jones'; diff --git a/assignments/ass1/submission/18307130341/2.sql b/assignments/ass1/submission/18307130341/2.sql new file mode 100644 index 0000000..0412192 --- /dev/null +++ b/assignments/ass1/submission/18307130341/2.sql @@ -0,0 +1,3 @@ +SELECT employee.name +FROM employee +WHERE employee.id=1 OR employee.id=2; diff --git a/assignments/ass1/submission/18307130341/3.sql b/assignments/ass1/submission/18307130341/3.sql new file mode 100644 index 0000000..83762ea --- /dev/null +++ b/assignments/ass1/submission/18307130341/3.sql @@ -0,0 +1,4 @@ +SELECT employee.name +FROM employee +WHERE employee.id!=1 +ORDER BY employee.id diff --git a/assignments/ass1/submission/18307130341/4.sql b/assignments/ass1/submission/18307130341/4.sql new file mode 100644 index 0000000..9fbb791 --- /dev/null +++ b/assignments/ass1/submission/18307130341/4.sql @@ -0,0 +1,4 @@ +SELECT employee.name +FROM employee +WHERE employee.age>=25 AND employee.age<=30 +ORDER BY employee.id diff --git a/assignments/ass1/submission/18307130341/5.sql b/assignments/ass1/submission/18307130341/5.sql new file mode 100644 index 0000000..1132215 --- /dev/null +++ b/assignments/ass1/submission/18307130341/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE employee.name LIKE 'J%' +ORDER BY employee.age diff --git a/assignments/ass1/submission/18307130341/6.sql b/assignments/ass1/submission/18307130341/6.sql new file mode 100644 index 0000000..cc28707 --- /dev/null +++ b/assignments/ass1/submission/18307130341/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT book.publisher +FROM book +ORDER BY book.publisher; diff --git a/assignments/ass1/submission/18307130341/7.sql b/assignments/ass1/submission/18307130341/7.sql new file mode 100644 index 0000000..50da121 --- /dev/null +++ b/assignments/ass1/submission/18307130341/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT record.book_id +FROM record +WHERE record.time>'2016-10-31' +ORDER BY record.book_id; diff --git a/assignments/ass1/submission/18307130341/8.sql b/assignments/ass1/submission/18307130341/8.sql new file mode 100644 index 0000000..d1510bd --- /dev/null +++ b/assignments/ass1/submission/18307130341/8.sql @@ -0,0 +1,6 @@ +SELECT employee.id,employee.name,COUNT(*) AS num +FROM employee,record +WHERE employee.id=record.employee_id +GROUP BY employee.id + HAVING COUNT(*)>1 +ORDER BY num DESC; diff --git a/assignments/ass1/submission/18307130341/create_table.sql b/assignments/ass1/submission/18307130341/create_table.sql new file mode 100644 index 0000000..6a9ccf6 --- /dev/null +++ b/assignments/ass1/submission/18307130341/create_table.sql @@ -0,0 +1,20 @@ +CREATE TABLE employee + (id INTEGER NOT NULL , + name CHAR(32) NOT NULL, + office CHAR(32) NOT NULL, + age SMALLINT NOT NULL, + PRIMARY KEY(id)); + +CREATE TABLE book + (id INTEGER NOT NULL, + name CHAR(32) NOT NULL, + author CHAR(32) NOT NULL, + publisher CHAR(32) NOT NULL, + PRIMARY KEY(id)); + +CREATE TABLE record + (book_id INTEGER NOT NULL, + employee_id INTEGER NOT NULL, + time DATE NOT NULL, + FOREIGN KEY (employee_id) REFERENCES employee(id), + FOREIGN KEY (book_id) REFERENCES book(id)); From eaf671f95eb70c2ed0fda9d32254115d8cd11169 Mon Sep 17 00:00:00 2001 From: xiaoas Date: Mon, 16 Mar 2020 12:57:50 +0800 Subject: [PATCH 024/189] submission of 18307130027 for ass1 --- assignments/ass1/submission/18307130027/1.sql | 1 + assignments/ass1/submission/18307130027/2.sql | 1 + assignments/ass1/submission/18307130027/3.sql | 1 + assignments/ass1/submission/18307130027/4.sql | 1 + assignments/ass1/submission/18307130027/5.sql | 1 + assignments/ass1/submission/18307130027/6.sql | 1 + assignments/ass1/submission/18307130027/7.sql | 1 + assignments/ass1/submission/18307130027/8.sql | 3 +++ .../submission/18307130027/create_table.sql | 24 +++++++++++++++++++ 9 files changed, 34 insertions(+) create mode 100644 assignments/ass1/submission/18307130027/1.sql create mode 100644 assignments/ass1/submission/18307130027/2.sql create mode 100644 assignments/ass1/submission/18307130027/3.sql create mode 100644 assignments/ass1/submission/18307130027/4.sql create mode 100644 assignments/ass1/submission/18307130027/5.sql create mode 100644 assignments/ass1/submission/18307130027/6.sql create mode 100644 assignments/ass1/submission/18307130027/7.sql create mode 100644 assignments/ass1/submission/18307130027/8.sql create mode 100644 assignments/ass1/submission/18307130027/create_table.sql diff --git a/assignments/ass1/submission/18307130027/1.sql b/assignments/ass1/submission/18307130027/1.sql new file mode 100644 index 0000000..602ea89 --- /dev/null +++ b/assignments/ass1/submission/18307130027/1.sql @@ -0,0 +1 @@ +select * from employee where name = 'Jones'; diff --git a/assignments/ass1/submission/18307130027/2.sql b/assignments/ass1/submission/18307130027/2.sql new file mode 100644 index 0000000..0501dce --- /dev/null +++ b/assignments/ass1/submission/18307130027/2.sql @@ -0,0 +1 @@ +select name from employee where id = 1 or id = 2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130027/3.sql b/assignments/ass1/submission/18307130027/3.sql new file mode 100644 index 0000000..89949f8 --- /dev/null +++ b/assignments/ass1/submission/18307130027/3.sql @@ -0,0 +1 @@ +select name from employee where id != 1 order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130027/4.sql b/assignments/ass1/submission/18307130027/4.sql new file mode 100644 index 0000000..7c2106f --- /dev/null +++ b/assignments/ass1/submission/18307130027/4.sql @@ -0,0 +1 @@ +select name from employee where age between 25 and 30; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130027/5.sql b/assignments/ass1/submission/18307130027/5.sql new file mode 100644 index 0000000..3efd17d --- /dev/null +++ b/assignments/ass1/submission/18307130027/5.sql @@ -0,0 +1 @@ +select * from employee where name like 'g%'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130027/6.sql b/assignments/ass1/submission/18307130027/6.sql new file mode 100644 index 0000000..8641e04 --- /dev/null +++ b/assignments/ass1/submission/18307130027/6.sql @@ -0,0 +1 @@ +select distinct publisher from book order by publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130027/7.sql b/assignments/ass1/submission/18307130027/7.sql new file mode 100644 index 0000000..6bfefe3 --- /dev/null +++ b/assignments/ass1/submission/18307130027/7.sql @@ -0,0 +1 @@ +select distinct book_id from record where time > '2016-10-31' order by book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130027/8.sql b/assignments/ass1/submission/18307130027/8.sql new file mode 100644 index 0000000..3640b9f --- /dev/null +++ b/assignments/ass1/submission/18307130027/8.sql @@ -0,0 +1,3 @@ +select employee.id, employee.name, count(*) as num +from employee inner join record on employee.id = record.employee_id +group by employee.id having num > 1 order by num DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130027/create_table.sql b/assignments/ass1/submission/18307130027/create_table.sql new file mode 100644 index 0000000..c9d283d --- /dev/null +++ b/assignments/ass1/submission/18307130027/create_table.sql @@ -0,0 +1,24 @@ +-- CREATE DATABASE IF NOT EXISTS ass1; +-- USE ass1; +CREATE TABLE employee ( + id INT NOT NULL, + name VARCHAR(32), + office VARCHAR(32), + age INT, + PRIMARY KEY (id)); +CREATE TABLE book ( + id INT NOT NULL, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32), + primary key (id) +); +CREATE TABLE record ( + book_id INT, + employee_id INT, + time DATE, + FOREIGN KEY (book_id) + REFERENCES book(id), + FOREIGN KEY (employee_id) + REFERENCES employee(id) +); \ No newline at end of file From 8b6a1dcd377b1e0764cbc1866d2c9272d313b9df Mon Sep 17 00:00:00 2001 From: mirackk <49869026+mirackk@users.noreply.github.com> Date: Mon, 16 Mar 2020 19:25:34 +0800 Subject: [PATCH 025/189] Delete test.md --- test.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test.md diff --git a/test.md b/test.md deleted file mode 100644 index 63d3c2d..0000000 --- a/test.md +++ /dev/null @@ -1 +0,0 @@ -just for test From db23592c2fdaf8aa7520cb44ce9dacaa17e19886 Mon Sep 17 00:00:00 2001 From: ccccy <56527943+cc-yue@users.noreply.github.com> Date: Tue, 17 Mar 2020 01:33:08 +0800 Subject: [PATCH 026/189] Create 18307130122 --- assignments/ass1/submission/18307130122 | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/18307130122 diff --git a/assignments/ass1/submission/18307130122 b/assignments/ass1/submission/18307130122 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/assignments/ass1/submission/18307130122 @@ -0,0 +1 @@ + From 39d642723d53210262b8ffe3bc245bc748ac2822 Mon Sep 17 00:00:00 2001 From: ccccy <56527943+cc-yue@users.noreply.github.com> Date: Tue, 17 Mar 2020 01:34:00 +0800 Subject: [PATCH 027/189] Delete 18307130122 --- assignments/ass1/submission/18307130122 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 assignments/ass1/submission/18307130122 diff --git a/assignments/ass1/submission/18307130122 b/assignments/ass1/submission/18307130122 deleted file mode 100644 index 8b13789..0000000 --- a/assignments/ass1/submission/18307130122 +++ /dev/null @@ -1 +0,0 @@ - From 9ef6dd5f37d0eeb027151af4d1bb5dfc833a7b20 Mon Sep 17 00:00:00 2001 From: ccccy <56527943+cc-yue@users.noreply.github.com> Date: Tue, 17 Mar 2020 01:38:16 +0800 Subject: [PATCH 028/189] Create 0.0 --- assignments/ass1/submission/183071301220/0.0 | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/183071301220/0.0 diff --git a/assignments/ass1/submission/183071301220/0.0 b/assignments/ass1/submission/183071301220/0.0 new file mode 100644 index 0000000..883dabd --- /dev/null +++ b/assignments/ass1/submission/183071301220/0.0 @@ -0,0 +1 @@ + test From 117e7d95ac22cc0c31a3065c260e8fdb1c886cbb Mon Sep 17 00:00:00 2001 From: ccccy <56527943+cc-yue@users.noreply.github.com> Date: Tue, 17 Mar 2020 01:42:10 +0800 Subject: [PATCH 029/189] Delete 0.0 --- assignments/ass1/submission/183071301220/0.0 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 assignments/ass1/submission/183071301220/0.0 diff --git a/assignments/ass1/submission/183071301220/0.0 b/assignments/ass1/submission/183071301220/0.0 deleted file mode 100644 index 883dabd..0000000 --- a/assignments/ass1/submission/183071301220/0.0 +++ /dev/null @@ -1 +0,0 @@ - test From e92221498894b219b577ea7b72bbe2bfc94ae4c3 Mon Sep 17 00:00:00 2001 From: ccccy <56527943+cc-yue@users.noreply.github.com> Date: Tue, 17 Mar 2020 01:42:33 +0800 Subject: [PATCH 030/189] Create test --- assignments/ass1/submission/18307130122/test | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/18307130122/test diff --git a/assignments/ass1/submission/18307130122/test b/assignments/ass1/submission/18307130122/test new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/assignments/ass1/submission/18307130122/test @@ -0,0 +1 @@ + From 6b1a43e68731463c783c6c0167b974ebc75bcc4d Mon Sep 17 00:00:00 2001 From: NoSW Date: Mon, 16 Mar 2020 20:42:25 -0700 Subject: [PATCH 031/189] submission of 18300200012 for ass1 --- assignments/ass1/submission/18300200012/1.sql | 3 +++ assignments/ass1/submission/18300200012/2.sql | 3 +++ assignments/ass1/submission/18300200012/3.sql | 4 +++ assignments/ass1/submission/18300200012/4.sql | 4 +++ assignments/ass1/submission/18300200012/5.sql | 4 +++ assignments/ass1/submission/18300200012/6.sql | 5 ++++ assignments/ass1/submission/18300200012/7.sql | 4 +++ assignments/ass1/submission/18300200012/8.sql | 5 ++++ .../submission/18300200012/create_table.sql | 27 +++++++++++++++++++ 9 files changed, 59 insertions(+) create mode 100644 assignments/ass1/submission/18300200012/1.sql create mode 100644 assignments/ass1/submission/18300200012/2.sql create mode 100644 assignments/ass1/submission/18300200012/3.sql create mode 100644 assignments/ass1/submission/18300200012/4.sql create mode 100644 assignments/ass1/submission/18300200012/5.sql create mode 100644 assignments/ass1/submission/18300200012/6.sql create mode 100644 assignments/ass1/submission/18300200012/7.sql create mode 100644 assignments/ass1/submission/18300200012/8.sql create mode 100644 assignments/ass1/submission/18300200012/create_table.sql diff --git a/assignments/ass1/submission/18300200012/1.sql b/assignments/ass1/submission/18300200012/1.sql new file mode 100644 index 0000000..388c920 --- /dev/null +++ b/assignments/ass1/submission/18300200012/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name="Jones"; diff --git a/assignments/ass1/submission/18300200012/2.sql b/assignments/ass1/submission/18300200012/2.sql new file mode 100644 index 0000000..ee21d36 --- /dev/null +++ b/assignments/ass1/submission/18300200012/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id=1 or id = 2; diff --git a/assignments/ass1/submission/18300200012/3.sql b/assignments/ass1/submission/18300200012/3.sql new file mode 100644 index 0000000..ba5640b --- /dev/null +++ b/assignments/ass1/submission/18300200012/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id!=1 +ORDER BY id; diff --git a/assignments/ass1/submission/18300200012/4.sql b/assignments/ass1/submission/18300200012/4.sql new file mode 100644 index 0000000..62cc442 --- /dev/null +++ b/assignments/ass1/submission/18300200012/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age BETWEEN 25 AND 30 +ORDER BY id; diff --git a/assignments/ass1/submission/18300200012/5.sql b/assignments/ass1/submission/18300200012/5.sql new file mode 100644 index 0000000..105e4b5 --- /dev/null +++ b/assignments/ass1/submission/18300200012/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name LIKE "J%" +ORDER BY age; diff --git a/assignments/ass1/submission/18300200012/6.sql b/assignments/ass1/submission/18300200012/6.sql new file mode 100644 index 0000000..71fde1a --- /dev/null +++ b/assignments/ass1/submission/18300200012/6.sql @@ -0,0 +1,5 @@ +SELECT publisher +FROM book +GROUP BY publisher +HAVING count(id)>2 +ORDER BY publisher ; diff --git a/assignments/ass1/submission/18300200012/7.sql b/assignments/ass1/submission/18300200012/7.sql new file mode 100644 index 0000000..9205254 --- /dev/null +++ b/assignments/ass1/submission/18300200012/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT book_id AS id +FROM record +WHERE time > '2016-10-31' +ORDER BY book_id; diff --git a/assignments/ass1/submission/18300200012/8.sql b/assignments/ass1/submission/18300200012/8.sql new file mode 100644 index 0000000..6ec0683 --- /dev/null +++ b/assignments/ass1/submission/18300200012/8.sql @@ -0,0 +1,5 @@ +SELECT id,name,count(id) AS num +FROM employee JOIN record ON id = employee_id +GROUP BY id,name +HAVING num>1 +ORDER BY num DESC diff --git a/assignments/ass1/submission/18300200012/create_table.sql b/assignments/ass1/submission/18300200012/create_table.sql new file mode 100644 index 0000000..57fa527 --- /dev/null +++ b/assignments/ass1/submission/18300200012/create_table.sql @@ -0,0 +1,27 @@ +CREATE TABLE employee + ( + id INT NOT NULL, + name VARCHAR(32), + office VARCHAR(32), + age INT, + check (age <= 100 and age >= 0), + PRIMARY KEY (id) + ); + +CREATE TABLE book + ( + id INT NOT NULL, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32), + PRIMARY KEY (id) + ); + +CREATE TABLE record + ( + book_id INT, + employee_id INT, + time DATE, + FOREIGN KEY(book_id) references book(id), + FOREIGN KEY(employee_id) references employee(id) + ); From 48b4ce0a277ee6356c23e7cbe04fb6b11a15edd2 Mon Sep 17 00:00:00 2001 From: riteme <1412803389@qq.com> Date: Tue, 17 Mar 2020 14:34:44 +0800 Subject: [PATCH 032/189] submission of 18307130172 for ass1 --- assignments/ass1/18307130172/1.sql | 3 +++ assignments/ass1/18307130172/2.sql | 3 +++ assignments/ass1/18307130172/3.sql | 4 +++ assignments/ass1/18307130172/4.sql | 4 +++ assignments/ass1/18307130172/5.sql | 4 +++ assignments/ass1/18307130172/6.sql | 3 +++ assignments/ass1/18307130172/7.sql | 4 +++ assignments/ass1/18307130172/8.sql | 5 ++++ assignments/ass1/18307130172/create_table.sql | 26 +++++++++++++++++++ 9 files changed, 56 insertions(+) create mode 100644 assignments/ass1/18307130172/1.sql create mode 100644 assignments/ass1/18307130172/2.sql create mode 100644 assignments/ass1/18307130172/3.sql create mode 100644 assignments/ass1/18307130172/4.sql create mode 100644 assignments/ass1/18307130172/5.sql create mode 100644 assignments/ass1/18307130172/6.sql create mode 100644 assignments/ass1/18307130172/7.sql create mode 100644 assignments/ass1/18307130172/8.sql create mode 100644 assignments/ass1/18307130172/create_table.sql diff --git a/assignments/ass1/18307130172/1.sql b/assignments/ass1/18307130172/1.sql new file mode 100644 index 0000000..acc564c --- /dev/null +++ b/assignments/ass1/18307130172/1.sql @@ -0,0 +1,3 @@ +select * +from employee +where name = "Jones"; diff --git a/assignments/ass1/18307130172/2.sql b/assignments/ass1/18307130172/2.sql new file mode 100644 index 0000000..a57f3af --- /dev/null +++ b/assignments/ass1/18307130172/2.sql @@ -0,0 +1,3 @@ +select name +from employee +where id in (1, 2); diff --git a/assignments/ass1/18307130172/3.sql b/assignments/ass1/18307130172/3.sql new file mode 100644 index 0000000..3509c2d --- /dev/null +++ b/assignments/ass1/18307130172/3.sql @@ -0,0 +1,4 @@ +select name +from employee +where id != 1 +order by id; diff --git a/assignments/ass1/18307130172/4.sql b/assignments/ass1/18307130172/4.sql new file mode 100644 index 0000000..aff610c --- /dev/null +++ b/assignments/ass1/18307130172/4.sql @@ -0,0 +1,4 @@ +select name +from employee +where age between 25 and 30 +order by id; diff --git a/assignments/ass1/18307130172/5.sql b/assignments/ass1/18307130172/5.sql new file mode 100644 index 0000000..9d9aebf --- /dev/null +++ b/assignments/ass1/18307130172/5.sql @@ -0,0 +1,4 @@ +select * +from employee +where name like "J%" +order by age; diff --git a/assignments/ass1/18307130172/6.sql b/assignments/ass1/18307130172/6.sql new file mode 100644 index 0000000..c58b81e --- /dev/null +++ b/assignments/ass1/18307130172/6.sql @@ -0,0 +1,3 @@ +select distinct publisher +from book +order by publisher; diff --git a/assignments/ass1/18307130172/7.sql b/assignments/ass1/18307130172/7.sql new file mode 100644 index 0000000..23cdf4e --- /dev/null +++ b/assignments/ass1/18307130172/7.sql @@ -0,0 +1,4 @@ +select distinct id +from book inner join record on id = book_id +where time > '2016-10-31' +order by id; diff --git a/assignments/ass1/18307130172/8.sql b/assignments/ass1/18307130172/8.sql new file mode 100644 index 0000000..323bf6e --- /dev/null +++ b/assignments/ass1/18307130172/8.sql @@ -0,0 +1,5 @@ +select id, name, count(*) as num +from employee inner join record on id = employee_id +group by id +having num > 1 +order by num desc; diff --git a/assignments/ass1/18307130172/create_table.sql b/assignments/ass1/18307130172/create_table.sql new file mode 100644 index 0000000..f5cb9d5 --- /dev/null +++ b/assignments/ass1/18307130172/create_table.sql @@ -0,0 +1,26 @@ +create database if not exists ass1; +use ass1; + +create table if not exists employee ( + id int auto_increment primary key, + name varchar(32), + office varchar(32), + age int, + check (age between 0 and 100) +); +create table if not exists book ( + id int auto_increment primary key, + name varchar(32), + author varchar(32), + publisher varchar(32) +); +create table if not exists record ( + book_id int, + employee_id int, + time date, + primary key (book_id, employee_id), + foreign key (book_id) + references book (id), + foreign key (employee_id) + references employee (id) +); From b6a7b875630cd4e6e144ed462f15bcafa329924a Mon Sep 17 00:00:00 2001 From: riteme <1412803389@qq.com> Date: Tue, 17 Mar 2020 14:42:14 +0800 Subject: [PATCH 033/189] Fix typo --- content/assignment1/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/assignment1/readme.md b/content/assignment1/readme.md index 1c7547d..c3b5f62 100644 --- a/content/assignment1/readme.md +++ b/content/assignment1/readme.md @@ -70,7 +70,7 @@ For each part, create a file in your working directory, for example `1.sql`, `2. 4. Query the name of all employees with age between 25 and 30 (inclusively, ordered by ID) 5. Qeury all fields for employees whose name started with `J` (ordered by age) 6. Query the names of all publishers, if one publisher has more than two books in the database, output the name of the publisher only once (ordered by name, ascii order) -7. Query the id of all boos that is borrowed after `2016-10-31`, also the IDs should be distinct (ordered by id) +7. Query the id of all books that is borrowed after `2016-10-31`, also the IDs should be distinct (ordered by id) 8. Query for each employee who has borrowed book more than once, output the `id`, `name`, and number of borrow record (name the field `num`), ordered by `num` in descending order. This one is kind of challenging, the TA's solution uses JOIN, GROUP BY, HAVING and ORDER BY, check them out if you don't know what does these key words mean for MySQL. ## Submit Your Solution From a016a73668a2ea9d9ada0d04a5e28826b5895205 Mon Sep 17 00:00:00 2001 From: unicornt Date: Tue, 17 Mar 2020 17:13:29 +0800 Subject: [PATCH 034/189] =?UTF-8?q?submission=20of=20=E8=B5=B5=E6=96=87?= =?UTF-8?q?=E8=BD=A9=20for=20ass1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assignments/ass1/submission/18307130104/1.sql | 3 +++ assignments/ass1/submission/18307130104/2.sql | 3 +++ assignments/ass1/submission/18307130104/3.sql | 4 ++++ assignments/ass1/submission/18307130104/4.sql | 4 ++++ assignments/ass1/submission/18307130104/5.sql | 4 ++++ assignments/ass1/submission/18307130104/6.sql | 3 +++ assignments/ass1/submission/18307130104/7.sql | 4 ++++ assignments/ass1/submission/18307130104/8.sql | 6 ++++++ .../submission/18307130104/create_table.sql | 18 ++++++++++++++++++ 9 files changed, 49 insertions(+) create mode 100644 assignments/ass1/submission/18307130104/1.sql create mode 100644 assignments/ass1/submission/18307130104/2.sql create mode 100644 assignments/ass1/submission/18307130104/3.sql create mode 100644 assignments/ass1/submission/18307130104/4.sql create mode 100644 assignments/ass1/submission/18307130104/5.sql create mode 100644 assignments/ass1/submission/18307130104/6.sql create mode 100644 assignments/ass1/submission/18307130104/7.sql create mode 100644 assignments/ass1/submission/18307130104/8.sql create mode 100644 assignments/ass1/submission/18307130104/create_table.sql diff --git a/assignments/ass1/submission/18307130104/1.sql b/assignments/ass1/submission/18307130104/1.sql new file mode 100644 index 0000000..42f8cb2 --- /dev/null +++ b/assignments/ass1/submission/18307130104/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee AS X +WHERE X.name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/2.sql b/assignments/ass1/submission/18307130104/2.sql new file mode 100644 index 0000000..cc8fef5 --- /dev/null +++ b/assignments/ass1/submission/18307130104/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee AS X +WHERE X.id = '1' OR X.id = '2'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/3.sql b/assignments/ass1/submission/18307130104/3.sql new file mode 100644 index 0000000..87362f3 --- /dev/null +++ b/assignments/ass1/submission/18307130104/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee AS X +WHERE X.id != 1 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/4.sql b/assignments/ass1/submission/18307130104/4.sql new file mode 100644 index 0000000..1a2e09a --- /dev/null +++ b/assignments/ass1/submission/18307130104/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee AS X +WHERE X.age >= 25 AND X.age <=30 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/5.sql b/assignments/ass1/submission/18307130104/5.sql new file mode 100644 index 0000000..e2b50dc --- /dev/null +++ b/assignments/ass1/submission/18307130104/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee AS X +WHERE X.name REGEXP '^J' +ORDER BY X.age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/6.sql b/assignments/ass1/submission/18307130104/6.sql new file mode 100644 index 0000000..534975f --- /dev/null +++ b/assignments/ass1/submission/18307130104/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/7.sql b/assignments/ass1/submission/18307130104/7.sql new file mode 100644 index 0000000..aec2867 --- /dev/null +++ b/assignments/ass1/submission/18307130104/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT employee_id +FROM record +WHERE time > '2016-10-31' +ORDER BY employee_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/8.sql b/assignments/ass1/submission/18307130104/8.sql new file mode 100644 index 0000000..f103aa2 --- /dev/null +++ b/assignments/ass1/submission/18307130104/8.sql @@ -0,0 +1,6 @@ +SELECT id, name, COUNT(DISTINCT book_id) AS num +FROM employee, record +WHERE id = employee_id +GROUP BY id + HAVING num > 1 +ORDER BY num DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130104/create_table.sql b/assignments/ass1/submission/18307130104/create_table.sql new file mode 100644 index 0000000..48a647a --- /dev/null +++ b/assignments/ass1/submission/18307130104/create_table.sql @@ -0,0 +1,18 @@ +CREATE TABLE employee + (id CHAR(4) NOT NULL, + name VARCHAR(32), + office VARCHAR(32), + age SMALLINT, + PRIMARY KEY(id)); +CREATE TABLE book + (id CHAR(4) NOT NULL, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32), + PRIMARY KEY(id)); +CREATE TABLE record + (book_id CHAR(4) NOT NULL, + employee_id CHAR(4) NOT NULL, + time DATE, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id)); \ No newline at end of file From 9253348e1c0fd05b28bec9b4c0bbee2fda91ddb2 Mon Sep 17 00:00:00 2001 From: chenyue <535727512@qq.com> Date: Tue, 17 Mar 2020 18:42:29 +0800 Subject: [PATCH 035/189] submission of 18307130122 for ass1 --- assignments/ass1/submission/18307130122/1.sql | 3 +++ assignments/ass1/submission/18307130122/2.sql | 3 +++ assignments/ass1/submission/18307130122/3.sql | 5 +++++ assignments/ass1/submission/18307130122/4.sql | 4 ++++ assignments/ass1/submission/18307130122/5.sql | 4 ++++ assignments/ass1/submission/18307130122/6.sql | 4 ++++ assignments/ass1/submission/18307130122/7.sql | 4 ++++ assignments/ass1/submission/18307130122/8.sql | 5 +++++ .../submission/18307130122/create_table.sql | 20 +++++++++++++++++++ 9 files changed, 52 insertions(+) create mode 100644 assignments/ass1/submission/18307130122/1.sql create mode 100644 assignments/ass1/submission/18307130122/2.sql create mode 100644 assignments/ass1/submission/18307130122/3.sql create mode 100644 assignments/ass1/submission/18307130122/4.sql create mode 100644 assignments/ass1/submission/18307130122/5.sql create mode 100644 assignments/ass1/submission/18307130122/6.sql create mode 100644 assignments/ass1/submission/18307130122/7.sql create mode 100644 assignments/ass1/submission/18307130122/8.sql create mode 100644 assignments/ass1/submission/18307130122/create_table.sql diff --git a/assignments/ass1/submission/18307130122/1.sql b/assignments/ass1/submission/18307130122/1.sql new file mode 100644 index 0000000..f4b3678 --- /dev/null +++ b/assignments/ass1/submission/18307130122/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +where name='Jones'; diff --git a/assignments/ass1/submission/18307130122/2.sql b/assignments/ass1/submission/18307130122/2.sql new file mode 100644 index 0000000..196b6cf --- /dev/null +++ b/assignments/ass1/submission/18307130122/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id='1' OR id='2' diff --git a/assignments/ass1/submission/18307130122/3.sql b/assignments/ass1/submission/18307130122/3.sql new file mode 100644 index 0000000..9b0a636 --- /dev/null +++ b/assignments/ass1/submission/18307130122/3.sql @@ -0,0 +1,5 @@ +SELECT name +FROM employee +where id!='1' +ORDER BY id + diff --git a/assignments/ass1/submission/18307130122/4.sql b/assignments/ass1/submission/18307130122/4.sql new file mode 100644 index 0000000..1260183 --- /dev/null +++ b/assignments/ass1/submission/18307130122/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age>=25 AND age<=30 +ORDER BY id diff --git a/assignments/ass1/submission/18307130122/5.sql b/assignments/ass1/submission/18307130122/5.sql new file mode 100644 index 0000000..c8e5c94 --- /dev/null +++ b/assignments/ass1/submission/18307130122/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name like "J%" +ORDER BY age diff --git a/assignments/ass1/submission/18307130122/6.sql b/assignments/ass1/submission/18307130122/6.sql new file mode 100644 index 0000000..799d1c0 --- /dev/null +++ b/assignments/ass1/submission/18307130122/6.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT publisher +FROM book +WHERE publisher!='' +ORDER BY publisher diff --git a/assignments/ass1/submission/18307130122/7.sql b/assignments/ass1/submission/18307130122/7.sql new file mode 100644 index 0000000..8b4496d --- /dev/null +++ b/assignments/ass1/submission/18307130122/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT book_id +FROM record +WHERE time > '2016-10-31' +ORDER BY book_id diff --git a/assignments/ass1/submission/18307130122/8.sql b/assignments/ass1/submission/18307130122/8.sql new file mode 100644 index 0000000..cf0dd2d --- /dev/null +++ b/assignments/ass1/submission/18307130122/8.sql @@ -0,0 +1,5 @@ +SELECT employee.id,employee.name,count(employee.id) AS num +FROM employee INNER JOIN record ON employee.id=record.employee_id +GROUP BY employee.id +HAVING num>1 +ORDER BY num diff --git a/assignments/ass1/submission/18307130122/create_table.sql b/assignments/ass1/submission/18307130122/create_table.sql new file mode 100644 index 0000000..2f4e5eb --- /dev/null +++ b/assignments/ass1/submission/18307130122/create_table.sql @@ -0,0 +1,20 @@ +cREATE TABLE employee +(id INT NOT NULL, +name VARCHAR(32) NOT NULL, +office VARCHAR(32) NOT NULL, +age SMALLINT NOT NULL, +PRIMARY KEY(id)); + +CREATE TABLE book +(id INT NOT NULL, +name VARCHAR(32) NOT NULL, +author VARCHAR(32) NOT NULL, +publisher VARCHAR(32) NOT NULL, +PRIMARY KEY(id)); + +CREATE TABLE record +(book_id INT NOT NULL, +employee_id INT NOT NULL, +time DATE NOT NULL, +FOREIGN KEY(book_id) REFERENCES book(id), +FOREIGN KEY(employee_id) REFERENCES employee(id)); From 219d3b0586a4f576fb69705c4166484db3205003 Mon Sep 17 00:00:00 2001 From: ccccy <56527943+cc-yue@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:27:50 +0800 Subject: [PATCH 036/189] Delete test --- assignments/ass1/submission/18307130122/test | 1 - 1 file changed, 1 deletion(-) delete mode 100644 assignments/ass1/submission/18307130122/test diff --git a/assignments/ass1/submission/18307130122/test b/assignments/ass1/submission/18307130122/test deleted file mode 100644 index 8b13789..0000000 --- a/assignments/ass1/submission/18307130122/test +++ /dev/null @@ -1 +0,0 @@ - From ef1e527bab744d59ba7b7889ba03f88a084a141c Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Tue, 17 Mar 2020 21:34:19 +0800 Subject: [PATCH 037/189] submission of 18307130024 for ass1 --- assignments/ass1/submission/18307130024/6.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/assignments/ass1/submission/18307130024/6.sql b/assignments/ass1/submission/18307130024/6.sql index 06fa72b..c71b3f8 100644 --- a/assignments/ass1/submission/18307130024/6.sql +++ b/assignments/ass1/submission/18307130024/6.sql @@ -1,6 +1,4 @@ select distinct publisher from book -group by publisher -having count(*) > 2 order by publisher ; \ No newline at end of file From df31170966845929bd39a7fb98f1963aee6bb897 Mon Sep 17 00:00:00 2001 From: Pryest <495945214@qq.com> Date: Tue, 17 Mar 2020 07:31:46 -0700 Subject: [PATCH 038/189] submission of 18307130213 Runyu Peng for ass1 --- assignments/ass1/submission/18307130213/1.sql | 3 +++ assignments/ass1/submission/18307130213/2.sql | 3 +++ assignments/ass1/submission/18307130213/3.sql | 4 ++++ assignments/ass1/submission/18307130213/4.sql | 4 ++++ assignments/ass1/submission/18307130213/5.sql | 3 +++ assignments/ass1/submission/18307130213/6.sql | 3 +++ assignments/ass1/submission/18307130213/7.sql | 4 ++++ assignments/ass1/submission/18307130213/8.sql | 6 ++++++ .../submission/18307130213/create_table.sql | 19 +++++++++++++++++++ 9 files changed, 49 insertions(+) create mode 100644 assignments/ass1/submission/18307130213/1.sql create mode 100644 assignments/ass1/submission/18307130213/2.sql create mode 100644 assignments/ass1/submission/18307130213/3.sql create mode 100644 assignments/ass1/submission/18307130213/4.sql create mode 100644 assignments/ass1/submission/18307130213/5.sql create mode 100644 assignments/ass1/submission/18307130213/6.sql create mode 100644 assignments/ass1/submission/18307130213/7.sql create mode 100644 assignments/ass1/submission/18307130213/8.sql create mode 100644 assignments/ass1/submission/18307130213/create_table.sql diff --git a/assignments/ass1/submission/18307130213/1.sql b/assignments/ass1/submission/18307130213/1.sql new file mode 100644 index 0000000..b3b7af1 --- /dev/null +++ b/assignments/ass1/submission/18307130213/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM EMPLOYEE +WHERE NAME='Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130213/2.sql b/assignments/ass1/submission/18307130213/2.sql new file mode 100644 index 0000000..5ee7f95 --- /dev/null +++ b/assignments/ass1/submission/18307130213/2.sql @@ -0,0 +1,3 @@ +SELECT NAME +FROM EMPLOYEE +WHERE ID=1 OR ID=2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130213/3.sql b/assignments/ass1/submission/18307130213/3.sql new file mode 100644 index 0000000..c2a8703 --- /dev/null +++ b/assignments/ass1/submission/18307130213/3.sql @@ -0,0 +1,4 @@ +SELECT NAME +FROM EMPLOYEE +WHERE ID<>1 +ORDER BY ID ASC; diff --git a/assignments/ass1/submission/18307130213/4.sql b/assignments/ass1/submission/18307130213/4.sql new file mode 100644 index 0000000..be2bee3 --- /dev/null +++ b/assignments/ass1/submission/18307130213/4.sql @@ -0,0 +1,4 @@ +SELECT NAME +FROM EMPLOYEE +WHERE AGE BETWEEN 25 AND 30 +ORDER BY ID ASC; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130213/5.sql b/assignments/ass1/submission/18307130213/5.sql new file mode 100644 index 0000000..18706b6 --- /dev/null +++ b/assignments/ass1/submission/18307130213/5.sql @@ -0,0 +1,3 @@ +SELECT * +FROM EMPLOYEE +WHERE NAME LIKE 'J%'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130213/6.sql b/assignments/ass1/submission/18307130213/6.sql new file mode 100644 index 0000000..27b805a --- /dev/null +++ b/assignments/ass1/submission/18307130213/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT PUBLISHER +FROM BOOK +ORDER BY PUBLISHER; diff --git a/assignments/ass1/submission/18307130213/7.sql b/assignments/ass1/submission/18307130213/7.sql new file mode 100644 index 0000000..a8e3db9 --- /dev/null +++ b/assignments/ass1/submission/18307130213/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT ID +FROM BOOK,RECORD +WHERE BOOK.ID = RECORD.BOOK_ID AND RECORD.TIME > 2016-10-31 +ORDER BY ID ASC; diff --git a/assignments/ass1/submission/18307130213/8.sql b/assignments/ass1/submission/18307130213/8.sql new file mode 100644 index 0000000..38465aa --- /dev/null +++ b/assignments/ass1/submission/18307130213/8.sql @@ -0,0 +1,6 @@ +SELECT DISTINCT ID,NAME,COUNT(*) AS NUM +FROM EMPLOYEE,RECORD +WHERE EMPLOYEE.ID=RECORD.EMPLOYEE_ID +GROUP BY ID + HAVING NUM > 1 +ORDER BY NUM DESC; diff --git a/assignments/ass1/submission/18307130213/create_table.sql b/assignments/ass1/submission/18307130213/create_table.sql new file mode 100644 index 0000000..8032571 --- /dev/null +++ b/assignments/ass1/submission/18307130213/create_table.sql @@ -0,0 +1,19 @@ +CREATE TABLE EMPLOYEE ( ID INT NOT NULL, + NAME VARCHAR(32) NOT NULL, + OFFICE VARCHAR(32) NOT NULL, + AGE SMALLINT NOT NULL, + PRIMARY KEY(ID), + CHECK(AGE BETWEEN 0 AND 100)); + +CREATE TABLE BOOK ( ID INT NOT NULL, + NAME VARCHAR(32) NOT NULL, + AUTHOR VARCHAR(32) NOT NULL, + PUBLISHER VARCHAR(32) NOT NULL, + PRIMARY KEY(ID)); + +CREATE TABLE RECORD ( BOOK_ID INT NOT NULL, + EMPLOYEE_ID INT NOT NULL, + TIME DATE NOT NULL, + FOREIGN KEY(BOOK_ID) REFERENCES BOOK(ID), + FOREIGN KEY(EMPLOYEE_ID) REFERENCES EMPLOYEE(ID), + PRIMARY KEY(BOOK_ID,EMPLOYEE_ID)); From 849319090f2c74c3dd30822062f0afdadb95d037 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Wed, 18 Mar 2020 05:10:16 +0800 Subject: [PATCH 039/189] Create create_table.sql --- .../submission/18307130003/create_table.sql | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 assignments/ass1/submission/18307130003/create_table.sql diff --git a/assignments/ass1/submission/18307130003/create_table.sql b/assignments/ass1/submission/18307130003/create_table.sql new file mode 100644 index 0000000..8f6c798 --- /dev/null +++ b/assignments/ass1/submission/18307130003/create_table.sql @@ -0,0 +1,28 @@ +CREATE TABLE employee ( + PRIMARY KEY (id), + id INT NOT NULL, + name VARCHAR(32) NOT NULL, + office VARCHAR(32), + age INT, + CONSTRAINT age_range CHECK ( + age BETWEEN 0 + AND 100 + ) +); + +CREATE TABLE book ( + PRIMARY KEY (id), + id INT NOT NULL, + name VARCHAR(32) NOT NULL, + author VARCHAR(32), + publisher VARCHAR(32), +); + +CREATE TABLE record ( + PRIMARY KEY (book_id, employee_id), + book_id INT NOT NULL, + employee_id INT NOT NULL, + time DATE, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id) +); \ No newline at end of file From d0ae50713b7223d4922f01599f382b7b24e74202 Mon Sep 17 00:00:00 2001 From: lilili2000 <18307130297@fudan.edu.cn> Date: Wed, 18 Mar 2020 08:53:10 +0800 Subject: [PATCH 040/189] submission of 18307130297 for ass1 --- assignments/ass1/18307130297/1.sql | 3 +++ assignments/ass1/18307130297/2.sql | 3 +++ assignments/ass1/18307130297/3.sql | 4 ++++ assignments/ass1/18307130297/4.sql | 4 ++++ assignments/ass1/18307130297/5.sql | 4 ++++ assignments/ass1/18307130297/6.sql | 6 +++++ assignments/ass1/18307130297/7.sql | 4 ++++ assignments/ass1/18307130297/8.sql | 6 +++++ assignments/ass1/18307130297/create_table.sql | 23 +++++++++++++++++++ 9 files changed, 57 insertions(+) create mode 100644 assignments/ass1/18307130297/1.sql create mode 100644 assignments/ass1/18307130297/2.sql create mode 100644 assignments/ass1/18307130297/3.sql create mode 100644 assignments/ass1/18307130297/4.sql create mode 100644 assignments/ass1/18307130297/5.sql create mode 100644 assignments/ass1/18307130297/6.sql create mode 100644 assignments/ass1/18307130297/7.sql create mode 100644 assignments/ass1/18307130297/8.sql create mode 100644 assignments/ass1/18307130297/create_table.sql diff --git a/assignments/ass1/18307130297/1.sql b/assignments/ass1/18307130297/1.sql new file mode 100644 index 0000000..1997d95 --- /dev/null +++ b/assignments/ass1/18307130297/1.sql @@ -0,0 +1,3 @@ +select * +from employee +where name="Jones"; \ No newline at end of file diff --git a/assignments/ass1/18307130297/2.sql b/assignments/ass1/18307130297/2.sql new file mode 100644 index 0000000..b37eade --- /dev/null +++ b/assignments/ass1/18307130297/2.sql @@ -0,0 +1,3 @@ +select name +from employee +where id=1 or id=2; \ No newline at end of file diff --git a/assignments/ass1/18307130297/3.sql b/assignments/ass1/18307130297/3.sql new file mode 100644 index 0000000..d4d070d --- /dev/null +++ b/assignments/ass1/18307130297/3.sql @@ -0,0 +1,4 @@ +select name +from employee +where id!=1 +order by id; \ No newline at end of file diff --git a/assignments/ass1/18307130297/4.sql b/assignments/ass1/18307130297/4.sql new file mode 100644 index 0000000..5db48e1 --- /dev/null +++ b/assignments/ass1/18307130297/4.sql @@ -0,0 +1,4 @@ +select name +from employee +where age between 25 and 30 +order by id; \ No newline at end of file diff --git a/assignments/ass1/18307130297/5.sql b/assignments/ass1/18307130297/5.sql new file mode 100644 index 0000000..61786c1 --- /dev/null +++ b/assignments/ass1/18307130297/5.sql @@ -0,0 +1,4 @@ +select* +from employee +where name like 'J%' +order by age; \ No newline at end of file diff --git a/assignments/ass1/18307130297/6.sql b/assignments/ass1/18307130297/6.sql new file mode 100644 index 0000000..051ec3d --- /dev/null +++ b/assignments/ass1/18307130297/6.sql @@ -0,0 +1,6 @@ +select distinct name +from employee,record +where id=employee_id +group by id + having sum(book_id)>2 +order by name; \ No newline at end of file diff --git a/assignments/ass1/18307130297/7.sql b/assignments/ass1/18307130297/7.sql new file mode 100644 index 0000000..7863c7c --- /dev/null +++ b/assignments/ass1/18307130297/7.sql @@ -0,0 +1,4 @@ +select distinct id +from record +where time>2016-10-31 +order by id; \ No newline at end of file diff --git a/assignments/ass1/18307130297/8.sql b/assignments/ass1/18307130297/8.sql new file mode 100644 index 0000000..c452600 --- /dev/null +++ b/assignments/ass1/18307130297/8.sql @@ -0,0 +1,6 @@ +select id,name,count(*) +from employee,record +where id=employee_id +group by employee_id + having sum(book_id)>1 +order by count(*) desc; \ No newline at end of file diff --git a/assignments/ass1/18307130297/create_table.sql b/assignments/ass1/18307130297/create_table.sql new file mode 100644 index 0000000..0fcbf8d --- /dev/null +++ b/assignments/ass1/18307130297/create_table.sql @@ -0,0 +1,23 @@ +create table employee( + id int, + name varchar(32), + office varchar(32), + age int, + primary key(id) +); + +create table book( + id int, + name varchar(32), + author varchar(32), + publisher varchar(32), + primary key(id) +); + +create table record( + book_id int, + employee_id int, + time DATE, + foreign key(book_id)references book(id), + foreign key(employee_id)references employee(id) +); \ No newline at end of file From f1a300f6a2392cb3169ec9ad8192b476b8dc6046 Mon Sep 17 00:00:00 2001 From: lilili2000 <18307130297@fudan.edu.cn> Date: Wed, 18 Mar 2020 09:06:48 +0800 Subject: [PATCH 041/189] submission of 18307130297 for ass1 --- assignments/ass1/18307130297/6.sql | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/assignments/ass1/18307130297/6.sql b/assignments/ass1/18307130297/6.sql index 051ec3d..c70eb89 100644 --- a/assignments/ass1/18307130297/6.sql +++ b/assignments/ass1/18307130297/6.sql @@ -1,6 +1,5 @@ -select distinct name -from employee,record -where id=employee_id -group by id - having sum(book_id)>2 -order by name; \ No newline at end of file +select publisher +from book +group by publisher + having count(*)>2 +order by publisher; \ No newline at end of file From e869cd861423e51249f33f9068a350d43aa0b8d0 Mon Sep 17 00:00:00 2001 From: bblss123 Date: Wed, 18 Mar 2020 10:55:16 +0800 Subject: [PATCH 042/189] submission of 18307130102 for ass1 --- assignments/ass1/submission/18307130102/1.sql | 2 ++ assignments/ass1/submission/18307130102/2.sql | 2 ++ assignments/ass1/submission/18307130102/3.sql | 3 +++ assignments/ass1/submission/18307130102/4.sql | 3 +++ assignments/ass1/submission/18307130102/5.sql | 3 +++ assignments/ass1/submission/18307130102/6.sql | 2 ++ assignments/ass1/submission/18307130102/7.sql | 3 +++ assignments/ass1/submission/18307130102/8.sql | 5 +++++ .../submission/18307130102/create_table.sql | 22 +++++++++++++++++++ 9 files changed, 45 insertions(+) create mode 100644 assignments/ass1/submission/18307130102/1.sql create mode 100644 assignments/ass1/submission/18307130102/2.sql create mode 100644 assignments/ass1/submission/18307130102/3.sql create mode 100644 assignments/ass1/submission/18307130102/4.sql create mode 100644 assignments/ass1/submission/18307130102/5.sql create mode 100644 assignments/ass1/submission/18307130102/6.sql create mode 100644 assignments/ass1/submission/18307130102/7.sql create mode 100644 assignments/ass1/submission/18307130102/8.sql create mode 100644 assignments/ass1/submission/18307130102/create_table.sql diff --git a/assignments/ass1/submission/18307130102/1.sql b/assignments/ass1/submission/18307130102/1.sql new file mode 100644 index 0000000..0457289 --- /dev/null +++ b/assignments/ass1/submission/18307130102/1.sql @@ -0,0 +1,2 @@ +SELECT * FROM employee +WHERE name = "Jones"; diff --git a/assignments/ass1/submission/18307130102/2.sql b/assignments/ass1/submission/18307130102/2.sql new file mode 100644 index 0000000..6e43f00 --- /dev/null +++ b/assignments/ass1/submission/18307130102/2.sql @@ -0,0 +1,2 @@ +SELECT name FROM employee +WHERE id = 1 OR id = 2; diff --git a/assignments/ass1/submission/18307130102/3.sql b/assignments/ass1/submission/18307130102/3.sql new file mode 100644 index 0000000..35864d5 --- /dev/null +++ b/assignments/ass1/submission/18307130102/3.sql @@ -0,0 +1,3 @@ +SELECT name FORM employee +WHERE id != 1 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130102/4.sql b/assignments/ass1/submission/18307130102/4.sql new file mode 100644 index 0000000..32e6c2f --- /dev/null +++ b/assignments/ass1/submission/18307130102/4.sql @@ -0,0 +1,3 @@ +SELECT name FROM employee +WHERE age >= 25 AND age <= 30 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130102/5.sql b/assignments/ass1/submission/18307130102/5.sql new file mode 100644 index 0000000..f5992ed --- /dev/null +++ b/assignments/ass1/submission/18307130102/5.sql @@ -0,0 +1,3 @@ +SELECT * FROM employee +WHERE name LIKE "J%" +ORDER BY age; diff --git a/assignments/ass1/submission/18307130102/6.sql b/assignments/ass1/submission/18307130102/6.sql new file mode 100644 index 0000000..a749a5f --- /dev/null +++ b/assignments/ass1/submission/18307130102/6.sql @@ -0,0 +1,2 @@ +SELECT DISTINCT publisher FROM book +ORDER BY publisher; diff --git a/assignments/ass1/submission/18307130102/7.sql b/assignments/ass1/submission/18307130102/7.sql new file mode 100644 index 0000000..693e983 --- /dev/null +++ b/assignments/ass1/submission/18307130102/7.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT id FROM book, record +WHERE book.id = record.book_id AND record.time > to_date('2016-10-31') +ORDER BY id; diff --git a/assignments/ass1/submission/18307130102/8.sql b/assignments/ass1/submission/18307130102/8.sql new file mode 100644 index 0000000..a2a4863 --- /dev/null +++ b/assignments/ass1/submission/18307130102/8.sql @@ -0,0 +1,5 @@ +SELECT id, name, count(*) AS num +FROM employee JOIN record ON id = employee_id +GROUP BY id +HAVING num >= 2 +ORDER BY num DESC; diff --git a/assignments/ass1/submission/18307130102/create_table.sql b/assignments/ass1/submission/18307130102/create_table.sql new file mode 100644 index 0000000..af0364b --- /dev/null +++ b/assignments/ass1/submission/18307130102/create_table.sql @@ -0,0 +1,22 @@ +CREATE TABLE employee( + id INTEGER, + name CHAR(32) NOT NULL, + office CHAR(32) NOT NULL, + age CHAR(32) NOT NULL, + PRIMARY KEY(id) +); +CREATE TABLE book( + id INTEGER, + name CHAR(32) NOT NULL, + author CHAR(32) NOT NULL, + publisher CHAR(32) NOT NULL, + PRIMARY KEY(id) +); +CREATE TABLE record( + book_id INTEGER, + employee_id INTEGER, + time DATE, + -- PRIMARY KEY (book_id), + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id) +); \ No newline at end of file From 734c3ce0f9ae47a17145427d5e86356b2f15b6ca Mon Sep 17 00:00:00 2001 From: bblss123 Date: Wed, 18 Mar 2020 11:08:06 +0800 Subject: [PATCH 043/189] submission of 18307130102 for ass1 --- assignments/ass1/submission/18307130102/3.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/ass1/submission/18307130102/3.sql b/assignments/ass1/submission/18307130102/3.sql index 35864d5..d5605fa 100644 --- a/assignments/ass1/submission/18307130102/3.sql +++ b/assignments/ass1/submission/18307130102/3.sql @@ -1,3 +1,3 @@ -SELECT name FORM employee +SELECT name FROM employee WHERE id != 1 ORDER BY id; From f5677fdf6e72360af29f4908ab91eb3edf1e5da8 Mon Sep 17 00:00:00 2001 From: bblss123 Date: Wed, 18 Mar 2020 11:11:35 +0800 Subject: [PATCH 044/189] submission of 18307130102 for ass1 --- assignments/ass1/submission/18307130102/create_table.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assignments/ass1/submission/18307130102/create_table.sql b/assignments/ass1/submission/18307130102/create_table.sql index af0364b..b31a4b1 100644 --- a/assignments/ass1/submission/18307130102/create_table.sql +++ b/assignments/ass1/submission/18307130102/create_table.sql @@ -19,4 +19,5 @@ CREATE TABLE record( -- PRIMARY KEY (book_id), FOREIGN KEY (book_id) REFERENCES book(id), FOREIGN KEY (employee_id) REFERENCES employee(id) -); \ No newline at end of file +); + From bdd0e7a64f166fb149b201ba1a9a73f67899d1e6 Mon Sep 17 00:00:00 2001 From: CAGeng <18307130154@fudan.edu.cn> Date: Tue, 17 Mar 2020 21:05:05 -0700 Subject: [PATCH 045/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130154/1.sql | 3 +++ assignments/ass1/submission/18307130154/2.sql | 3 +++ assignments/ass1/submission/18307130154/3.sql | 4 ++++ assignments/ass1/submission/18307130154/4.sql | 4 ++++ assignments/ass1/submission/18307130154/5.sql | 4 ++++ assignments/ass1/submission/18307130154/6.sql | 5 +++++ assignments/ass1/submission/18307130154/7.sql | 4 ++++ assignments/ass1/submission/18307130154/8.sql | 6 ++++++ assignments/ass1/submission/18307130154/create_table.sql | 0 9 files changed, 33 insertions(+) create mode 100644 assignments/ass1/submission/18307130154/1.sql create mode 100644 assignments/ass1/submission/18307130154/2.sql create mode 100644 assignments/ass1/submission/18307130154/3.sql create mode 100644 assignments/ass1/submission/18307130154/4.sql create mode 100644 assignments/ass1/submission/18307130154/5.sql create mode 100644 assignments/ass1/submission/18307130154/6.sql create mode 100644 assignments/ass1/submission/18307130154/7.sql create mode 100644 assignments/ass1/submission/18307130154/8.sql create mode 100644 assignments/ass1/submission/18307130154/create_table.sql diff --git a/assignments/ass1/submission/18307130154/1.sql b/assignments/ass1/submission/18307130154/1.sql new file mode 100644 index 0000000..3063bc3 --- /dev/null +++ b/assignments/ass1/submission/18307130154/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name = 'Jones'; diff --git a/assignments/ass1/submission/18307130154/2.sql b/assignments/ass1/submission/18307130154/2.sql new file mode 100644 index 0000000..c987621 --- /dev/null +++ b/assignments/ass1/submission/18307130154/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id = 1 or id = 2; diff --git a/assignments/ass1/submission/18307130154/3.sql b/assignments/ass1/submission/18307130154/3.sql new file mode 100644 index 0000000..c815986 --- /dev/null +++ b/assignments/ass1/submission/18307130154/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id <>1 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130154/4.sql b/assignments/ass1/submission/18307130154/4.sql new file mode 100644 index 0000000..9baf0bd --- /dev/null +++ b/assignments/ass1/submission/18307130154/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age >= 25 AND age <= 30 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130154/5.sql b/assignments/ass1/submission/18307130154/5.sql new file mode 100644 index 0000000..9861e56 --- /dev/null +++ b/assignments/ass1/submission/18307130154/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name LIKE 'j%' +ORDER BY age; diff --git a/assignments/ass1/submission/18307130154/6.sql b/assignments/ass1/submission/18307130154/6.sql new file mode 100644 index 0000000..b0d51a8 --- /dev/null +++ b/assignments/ass1/submission/18307130154/6.sql @@ -0,0 +1,5 @@ +SELECT DISTINCT publisher +FROM book AS X +WHERE 2 <= (SELECT COUNT(*) FROM book AS Y + WHERE Y.publisher = X.publisher) +ORDER BY publisher ; diff --git a/assignments/ass1/submission/18307130154/7.sql b/assignments/ass1/submission/18307130154/7.sql new file mode 100644 index 0000000..9eab10f --- /dev/null +++ b/assignments/ass1/submission/18307130154/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT id +FROM book +WHERE id IN(SELECT book_id FROM record + WHERE time > '2016-10-31'); diff --git a/assignments/ass1/submission/18307130154/8.sql b/assignments/ass1/submission/18307130154/8.sql new file mode 100644 index 0000000..2bba8ec --- /dev/null +++ b/assignments/ass1/submission/18307130154/8.sql @@ -0,0 +1,6 @@ +SELECT id , name , COUNT(*) AS num +FROM employee, record +WHERE id = employee_id +GROUP BY id + HAVING COUNT(*) >1 +ORDER BY COUNT(*) DESC; diff --git a/assignments/ass1/submission/18307130154/create_table.sql b/assignments/ass1/submission/18307130154/create_table.sql new file mode 100644 index 0000000..e69de29 From 8a901a82eaef44b70921fa3b0f75c527974cc280 Mon Sep 17 00:00:00 2001 From: LucasXXII Date: Wed, 18 Mar 2020 12:30:56 +0800 Subject: [PATCH 046/189] submission of 15307130201 for ass1 --- assignments/ass1/submission/15307130201/1.sql | 3 +++ assignments/ass1/submission/15307130201/2.sql | 3 +++ assignments/ass1/submission/15307130201/3.sql | 4 ++++ assignments/ass1/submission/15307130201/4.sql | 4 ++++ assignments/ass1/submission/15307130201/5.sql | 4 ++++ assignments/ass1/submission/15307130201/6.sql | 3 +++ assignments/ass1/submission/15307130201/7.sql | 4 ++++ assignments/ass1/submission/15307130201/8.sql | 6 ++++++ .../submission/15307130201/create_table.sql | 21 +++++++++++++++++++ 9 files changed, 52 insertions(+) create mode 100644 assignments/ass1/submission/15307130201/1.sql create mode 100644 assignments/ass1/submission/15307130201/2.sql create mode 100644 assignments/ass1/submission/15307130201/3.sql create mode 100644 assignments/ass1/submission/15307130201/4.sql create mode 100644 assignments/ass1/submission/15307130201/5.sql create mode 100644 assignments/ass1/submission/15307130201/6.sql create mode 100644 assignments/ass1/submission/15307130201/7.sql create mode 100644 assignments/ass1/submission/15307130201/8.sql create mode 100644 assignments/ass1/submission/15307130201/create_table.sql diff --git a/assignments/ass1/submission/15307130201/1.sql b/assignments/ass1/submission/15307130201/1.sql new file mode 100644 index 0000000..aa0e9f9 --- /dev/null +++ b/assignments/ass1/submission/15307130201/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/2.sql b/assignments/ass1/submission/15307130201/2.sql new file mode 100644 index 0000000..0b3fc76 --- /dev/null +++ b/assignments/ass1/submission/15307130201/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id = 1 OR id = 2; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/3.sql b/assignments/ass1/submission/15307130201/3.sql new file mode 100644 index 0000000..406fce7 --- /dev/null +++ b/assignments/ass1/submission/15307130201/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id != 1 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/4.sql b/assignments/ass1/submission/15307130201/4.sql new file mode 100644 index 0000000..61db3c7 --- /dev/null +++ b/assignments/ass1/submission/15307130201/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age >= 25 and age <= 30 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/5.sql b/assignments/ass1/submission/15307130201/5.sql new file mode 100644 index 0000000..03088b7 --- /dev/null +++ b/assignments/ass1/submission/15307130201/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name LIKE 'J%' +ORDER BY age; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/6.sql b/assignments/ass1/submission/15307130201/6.sql new file mode 100644 index 0000000..534975f --- /dev/null +++ b/assignments/ass1/submission/15307130201/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/7.sql b/assignments/ass1/submission/15307130201/7.sql new file mode 100644 index 0000000..f6b1026 --- /dev/null +++ b/assignments/ass1/submission/15307130201/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT book_id +FROM record +WHERE time >= '2016-10-31' +ORDER BY book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/8.sql b/assignments/ass1/submission/15307130201/8.sql new file mode 100644 index 0000000..94d13d1 --- /dev/null +++ b/assignments/ass1/submission/15307130201/8.sql @@ -0,0 +1,6 @@ +SELECT e.id, e.name, COUNT(*) as num +FROM employee AS e, record +WHERE e.id = record.employee_id +GROUP BY e.id +HAVING num > 1 +ORDER BY num DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/15307130201/create_table.sql b/assignments/ass1/submission/15307130201/create_table.sql new file mode 100644 index 0000000..9a8f64b --- /dev/null +++ b/assignments/ass1/submission/15307130201/create_table.sql @@ -0,0 +1,21 @@ +CREATE TABLE employee ( + id INT(16), + name VARCHAR(32), + office VARCHAR(32), + age INT(8), + PRIMARY KEY (id) +); +CREATE TABLE book ( + id INT(16), + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32), + PRIMARY KEY (id) +); +CREATE TABLE record ( + book_id INT(16), + employee_id INT(16), + time DATE, + FOREIGN KEY (book_id) REFERENCES book (id), + FOREIGN KEY (employee_id) REFERENCES employee (id) +); From d95c6621feba11ff56dff1edf2e69f9656afe92d Mon Sep 17 00:00:00 2001 From: kleinercubs <1910481653@qq.com> Date: Wed, 18 Mar 2020 16:22:22 +0800 Subject: [PATCH 047/189] submission of 18307130252 for ass1 --- assignments/ass1/submission/18307130252/1.sql | 4 +++ assignments/ass1/submission/18307130252/2.sql | 4 +++ assignments/ass1/submission/18307130252/3.sql | 4 +++ assignments/ass1/submission/18307130252/4.sql | 5 ++++ assignments/ass1/submission/18307130252/5.sql | 5 ++++ assignments/ass1/submission/18307130252/6.sql | 4 +++ assignments/ass1/submission/18307130252/7.sql | 5 ++++ assignments/ass1/submission/18307130252/8.sql | 7 ++++++ .../submission/18307130252/create_table.sql | 25 +++++++++++++++++++ 9 files changed, 63 insertions(+) create mode 100644 assignments/ass1/submission/18307130252/1.sql create mode 100644 assignments/ass1/submission/18307130252/2.sql create mode 100644 assignments/ass1/submission/18307130252/3.sql create mode 100644 assignments/ass1/submission/18307130252/4.sql create mode 100644 assignments/ass1/submission/18307130252/5.sql create mode 100644 assignments/ass1/submission/18307130252/6.sql create mode 100644 assignments/ass1/submission/18307130252/7.sql create mode 100644 assignments/ass1/submission/18307130252/8.sql create mode 100644 assignments/ass1/submission/18307130252/create_table.sql diff --git a/assignments/ass1/submission/18307130252/1.sql b/assignments/ass1/submission/18307130252/1.sql new file mode 100644 index 0000000..c3fdae5 --- /dev/null +++ b/assignments/ass1/submission/18307130252/1.sql @@ -0,0 +1,4 @@ +select * +from employee +where name = "Jones"; + diff --git a/assignments/ass1/submission/18307130252/2.sql b/assignments/ass1/submission/18307130252/2.sql new file mode 100644 index 0000000..603ef4c --- /dev/null +++ b/assignments/ass1/submission/18307130252/2.sql @@ -0,0 +1,4 @@ +select name +from employee +where id = 1 or id = 2; + diff --git a/assignments/ass1/submission/18307130252/3.sql b/assignments/ass1/submission/18307130252/3.sql new file mode 100644 index 0000000..3509c2d --- /dev/null +++ b/assignments/ass1/submission/18307130252/3.sql @@ -0,0 +1,4 @@ +select name +from employee +where id != 1 +order by id; diff --git a/assignments/ass1/submission/18307130252/4.sql b/assignments/ass1/submission/18307130252/4.sql new file mode 100644 index 0000000..ea007fd --- /dev/null +++ b/assignments/ass1/submission/18307130252/4.sql @@ -0,0 +1,5 @@ +select name +from employee +where 25 <= age and age <= 30 +order by id; + diff --git a/assignments/ass1/submission/18307130252/5.sql b/assignments/ass1/submission/18307130252/5.sql new file mode 100644 index 0000000..c999f9f --- /dev/null +++ b/assignments/ass1/submission/18307130252/5.sql @@ -0,0 +1,5 @@ +select * +from employee +where name like "J%" +order by age; + diff --git a/assignments/ass1/submission/18307130252/6.sql b/assignments/ass1/submission/18307130252/6.sql new file mode 100644 index 0000000..f933e40 --- /dev/null +++ b/assignments/ass1/submission/18307130252/6.sql @@ -0,0 +1,4 @@ +select distinct publisher +from book +order by publisher; + diff --git a/assignments/ass1/submission/18307130252/7.sql b/assignments/ass1/submission/18307130252/7.sql new file mode 100644 index 0000000..ecdc161 --- /dev/null +++ b/assignments/ass1/submission/18307130252/7.sql @@ -0,0 +1,5 @@ +select distinct book_id +from record +where time > str_to_date('2016-10-31', "%Y-%m-%d") +order by book_id; + diff --git a/assignments/ass1/submission/18307130252/8.sql b/assignments/ass1/submission/18307130252/8.sql new file mode 100644 index 0000000..a52d04d --- /dev/null +++ b/assignments/ass1/submission/18307130252/8.sql @@ -0,0 +1,7 @@ +select employee.id, name, X.num +from employee left outer join ((select employee_id as id, count(*) as num + from record + group by employee_id) as X ) +on employee.id = X.id +where X.num > 1 +order by X.num desc; diff --git a/assignments/ass1/submission/18307130252/create_table.sql b/assignments/ass1/submission/18307130252/create_table.sql new file mode 100644 index 0000000..c853e5e --- /dev/null +++ b/assignments/ass1/submission/18307130252/create_table.sql @@ -0,0 +1,25 @@ +create table employee( + id varchar(32) not null, + name varchar(32), + office varchar(32), + age smallint, + primary key(id) +); + +create table book( + id varchar(32) not null, + name varchar(32), + author varchar(32), + publisher varchar(32), + primary key(id) +); + +create table record( + book_id varchar(32), + employee_id varchar(32), + time date, + foreign key(book_id) references book(id), + foreign key(employee_id) references employee(id) +); + + From f50e259c7814d4a1bdaa6aea26b860b5e5c23cc6 Mon Sep 17 00:00:00 2001 From: YinxuanH <18307130340@fudan.edu.cn> Date: Thu, 19 Mar 2020 08:20:39 +0800 Subject: [PATCH 048/189] submission of xxx for ass1 --- assignments/ass1/submission/18307130340/1.sql | 4 ++++ assignments/ass1/submission/18307130340/2.sql | 4 ++++ assignments/ass1/submission/18307130340/3.sql | 5 ++++ assignments/ass1/submission/18307130340/4.sql | 5 ++++ assignments/ass1/submission/18307130340/5.sql | 5 ++++ assignments/ass1/submission/18307130340/6.sql | 4 ++++ assignments/ass1/submission/18307130340/7.sql | 5 ++++ assignments/ass1/submission/18307130340/8.sql | 6 +++++ .../submission/18307130340/create_table.sql | 24 +++++++++++++++++++ 9 files changed, 62 insertions(+) create mode 100644 assignments/ass1/submission/18307130340/1.sql create mode 100644 assignments/ass1/submission/18307130340/2.sql create mode 100644 assignments/ass1/submission/18307130340/3.sql create mode 100644 assignments/ass1/submission/18307130340/4.sql create mode 100644 assignments/ass1/submission/18307130340/5.sql create mode 100644 assignments/ass1/submission/18307130340/6.sql create mode 100644 assignments/ass1/submission/18307130340/7.sql create mode 100644 assignments/ass1/submission/18307130340/8.sql create mode 100644 assignments/ass1/submission/18307130340/create_table.sql diff --git a/assignments/ass1/submission/18307130340/1.sql b/assignments/ass1/submission/18307130340/1.sql new file mode 100644 index 0000000..e06ea3d --- /dev/null +++ b/assignments/ass1/submission/18307130340/1.sql @@ -0,0 +1,4 @@ +#Query all fields for employees named Jones +select * +from employee +where name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/2.sql b/assignments/ass1/submission/18307130340/2.sql new file mode 100644 index 0000000..489c051 --- /dev/null +++ b/assignments/ass1/submission/18307130340/2.sql @@ -0,0 +1,4 @@ +#Query the name of employees with ID equals to 1 or 2 (order dose not matter) +select name +from employee +where id = 1 or id = 2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/3.sql b/assignments/ass1/submission/18307130340/3.sql new file mode 100644 index 0000000..cf9003b --- /dev/null +++ b/assignments/ass1/submission/18307130340/3.sql @@ -0,0 +1,5 @@ +#Query the name of all employees except the one whose ID is 1 (ordered by ID) +select name +from employee +where id <> 1 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/4.sql b/assignments/ass1/submission/18307130340/4.sql new file mode 100644 index 0000000..eacf356 --- /dev/null +++ b/assignments/ass1/submission/18307130340/4.sql @@ -0,0 +1,5 @@ +#Query the name of all employees with age between 25 and 30 (inclusively, ordered by ID) +select name +from employee +where age between 25 and 30 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/5.sql b/assignments/ass1/submission/18307130340/5.sql new file mode 100644 index 0000000..7fc03b1 --- /dev/null +++ b/assignments/ass1/submission/18307130340/5.sql @@ -0,0 +1,5 @@ +#Qeury all fields for employees whose name started with J (ordered by age) +select * +from employee +where name like 'J%' +order by age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/6.sql b/assignments/ass1/submission/18307130340/6.sql new file mode 100644 index 0000000..278ef6a --- /dev/null +++ b/assignments/ass1/submission/18307130340/6.sql @@ -0,0 +1,4 @@ +#Query the names of all publishers, if one publisher has more than two books in the database, output the name of the publisher only once (ordered by name, ascii order) +select distinct publisher +from book +order by publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/7.sql b/assignments/ass1/submission/18307130340/7.sql new file mode 100644 index 0000000..4b933b9 --- /dev/null +++ b/assignments/ass1/submission/18307130340/7.sql @@ -0,0 +1,5 @@ +#Query the id of all books that is borrowed after 2016-10-31, also the IDs should be distinct (ordered by id) +select distinct book_id +from record +where time > '2016-10-31' +order by book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/8.sql b/assignments/ass1/submission/18307130340/8.sql new file mode 100644 index 0000000..a66405e --- /dev/null +++ b/assignments/ass1/submission/18307130340/8.sql @@ -0,0 +1,6 @@ +#Query for each employee who has borrowed book more than once, output the id, name, and number of borrow record (name the field num), ordered by num in descending order +select id, name, count(*) as num +from employee join record on id = employee_id +group by id + having count(*) > 1 +order by count(*) desc; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/create_table.sql b/assignments/ass1/submission/18307130340/create_table.sql new file mode 100644 index 0000000..b8802d6 --- /dev/null +++ b/assignments/ass1/submission/18307130340/create_table.sql @@ -0,0 +1,24 @@ +create table employee( + id integer not null, + name varchar(32), + office varchar(32), + age smallint, + primary key(id) +); + +create table book( + id integer not null, + name varchar(32), + author varchar(32), + publisher varchar(32), + primary key(id) +); + +create table record( + book_id integer, + employee_id integer, + time date, + foreign key(book_id) references book(id), + foreign key(employee_id) references employee(id), + primary key(book_id, employee_id) +); \ No newline at end of file From 1daadada2fdc7290eb1b068068ec3313c978a7d2 Mon Sep 17 00:00:00 2001 From: YinxuanH <18307130340@fudan.edu.cn> Date: Thu, 19 Mar 2020 08:42:24 +0800 Subject: [PATCH 049/189] del --- assignments/ass1/submission/18307130340/1.sql | 4 ---- assignments/ass1/submission/18307130340/2.sql | 4 ---- assignments/ass1/submission/18307130340/3.sql | 5 ---- assignments/ass1/submission/18307130340/4.sql | 5 ---- assignments/ass1/submission/18307130340/5.sql | 5 ---- assignments/ass1/submission/18307130340/6.sql | 4 ---- assignments/ass1/submission/18307130340/7.sql | 5 ---- assignments/ass1/submission/18307130340/8.sql | 6 ----- .../submission/18307130340/create_table.sql | 24 ------------------- 9 files changed, 62 deletions(-) delete mode 100644 assignments/ass1/submission/18307130340/1.sql delete mode 100644 assignments/ass1/submission/18307130340/2.sql delete mode 100644 assignments/ass1/submission/18307130340/3.sql delete mode 100644 assignments/ass1/submission/18307130340/4.sql delete mode 100644 assignments/ass1/submission/18307130340/5.sql delete mode 100644 assignments/ass1/submission/18307130340/6.sql delete mode 100644 assignments/ass1/submission/18307130340/7.sql delete mode 100644 assignments/ass1/submission/18307130340/8.sql delete mode 100644 assignments/ass1/submission/18307130340/create_table.sql diff --git a/assignments/ass1/submission/18307130340/1.sql b/assignments/ass1/submission/18307130340/1.sql deleted file mode 100644 index e06ea3d..0000000 --- a/assignments/ass1/submission/18307130340/1.sql +++ /dev/null @@ -1,4 +0,0 @@ -#Query all fields for employees named Jones -select * -from employee -where name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/2.sql b/assignments/ass1/submission/18307130340/2.sql deleted file mode 100644 index 489c051..0000000 --- a/assignments/ass1/submission/18307130340/2.sql +++ /dev/null @@ -1,4 +0,0 @@ -#Query the name of employees with ID equals to 1 or 2 (order dose not matter) -select name -from employee -where id = 1 or id = 2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/3.sql b/assignments/ass1/submission/18307130340/3.sql deleted file mode 100644 index cf9003b..0000000 --- a/assignments/ass1/submission/18307130340/3.sql +++ /dev/null @@ -1,5 +0,0 @@ -#Query the name of all employees except the one whose ID is 1 (ordered by ID) -select name -from employee -where id <> 1 -order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/4.sql b/assignments/ass1/submission/18307130340/4.sql deleted file mode 100644 index eacf356..0000000 --- a/assignments/ass1/submission/18307130340/4.sql +++ /dev/null @@ -1,5 +0,0 @@ -#Query the name of all employees with age between 25 and 30 (inclusively, ordered by ID) -select name -from employee -where age between 25 and 30 -order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/5.sql b/assignments/ass1/submission/18307130340/5.sql deleted file mode 100644 index 7fc03b1..0000000 --- a/assignments/ass1/submission/18307130340/5.sql +++ /dev/null @@ -1,5 +0,0 @@ -#Qeury all fields for employees whose name started with J (ordered by age) -select * -from employee -where name like 'J%' -order by age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/6.sql b/assignments/ass1/submission/18307130340/6.sql deleted file mode 100644 index 278ef6a..0000000 --- a/assignments/ass1/submission/18307130340/6.sql +++ /dev/null @@ -1,4 +0,0 @@ -#Query the names of all publishers, if one publisher has more than two books in the database, output the name of the publisher only once (ordered by name, ascii order) -select distinct publisher -from book -order by publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/7.sql b/assignments/ass1/submission/18307130340/7.sql deleted file mode 100644 index 4b933b9..0000000 --- a/assignments/ass1/submission/18307130340/7.sql +++ /dev/null @@ -1,5 +0,0 @@ -#Query the id of all books that is borrowed after 2016-10-31, also the IDs should be distinct (ordered by id) -select distinct book_id -from record -where time > '2016-10-31' -order by book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/8.sql b/assignments/ass1/submission/18307130340/8.sql deleted file mode 100644 index a66405e..0000000 --- a/assignments/ass1/submission/18307130340/8.sql +++ /dev/null @@ -1,6 +0,0 @@ -#Query for each employee who has borrowed book more than once, output the id, name, and number of borrow record (name the field num), ordered by num in descending order -select id, name, count(*) as num -from employee join record on id = employee_id -group by id - having count(*) > 1 -order by count(*) desc; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/create_table.sql b/assignments/ass1/submission/18307130340/create_table.sql deleted file mode 100644 index b8802d6..0000000 --- a/assignments/ass1/submission/18307130340/create_table.sql +++ /dev/null @@ -1,24 +0,0 @@ -create table employee( - id integer not null, - name varchar(32), - office varchar(32), - age smallint, - primary key(id) -); - -create table book( - id integer not null, - name varchar(32), - author varchar(32), - publisher varchar(32), - primary key(id) -); - -create table record( - book_id integer, - employee_id integer, - time date, - foreign key(book_id) references book(id), - foreign key(employee_id) references employee(id), - primary key(book_id, employee_id) -); \ No newline at end of file From 69d98665dfb94306024900acb909be754c86e859 Mon Sep 17 00:00:00 2001 From: YinxuanH <18307130340@fudan.edu.cn> Date: Thu, 19 Mar 2020 08:51:04 +0800 Subject: [PATCH 050/189] submission of 18307130340 for ass1 --- assignments/ass1/submission/18307130340/1.sql | 4 ++++ assignments/ass1/submission/18307130340/2.sql | 4 ++++ assignments/ass1/submission/18307130340/3.sql | 5 ++++ assignments/ass1/submission/18307130340/4.sql | 5 ++++ assignments/ass1/submission/18307130340/5.sql | 5 ++++ assignments/ass1/submission/18307130340/6.sql | 4 ++++ assignments/ass1/submission/18307130340/7.sql | 5 ++++ assignments/ass1/submission/18307130340/8.sql | 6 +++++ .../submission/18307130340/create_table.sql | 24 +++++++++++++++++++ 9 files changed, 62 insertions(+) create mode 100644 assignments/ass1/submission/18307130340/1.sql create mode 100644 assignments/ass1/submission/18307130340/2.sql create mode 100644 assignments/ass1/submission/18307130340/3.sql create mode 100644 assignments/ass1/submission/18307130340/4.sql create mode 100644 assignments/ass1/submission/18307130340/5.sql create mode 100644 assignments/ass1/submission/18307130340/6.sql create mode 100644 assignments/ass1/submission/18307130340/7.sql create mode 100644 assignments/ass1/submission/18307130340/8.sql create mode 100644 assignments/ass1/submission/18307130340/create_table.sql diff --git a/assignments/ass1/submission/18307130340/1.sql b/assignments/ass1/submission/18307130340/1.sql new file mode 100644 index 0000000..e06ea3d --- /dev/null +++ b/assignments/ass1/submission/18307130340/1.sql @@ -0,0 +1,4 @@ +#Query all fields for employees named Jones +select * +from employee +where name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/2.sql b/assignments/ass1/submission/18307130340/2.sql new file mode 100644 index 0000000..489c051 --- /dev/null +++ b/assignments/ass1/submission/18307130340/2.sql @@ -0,0 +1,4 @@ +#Query the name of employees with ID equals to 1 or 2 (order dose not matter) +select name +from employee +where id = 1 or id = 2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/3.sql b/assignments/ass1/submission/18307130340/3.sql new file mode 100644 index 0000000..cf9003b --- /dev/null +++ b/assignments/ass1/submission/18307130340/3.sql @@ -0,0 +1,5 @@ +#Query the name of all employees except the one whose ID is 1 (ordered by ID) +select name +from employee +where id <> 1 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/4.sql b/assignments/ass1/submission/18307130340/4.sql new file mode 100644 index 0000000..eacf356 --- /dev/null +++ b/assignments/ass1/submission/18307130340/4.sql @@ -0,0 +1,5 @@ +#Query the name of all employees with age between 25 and 30 (inclusively, ordered by ID) +select name +from employee +where age between 25 and 30 +order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/5.sql b/assignments/ass1/submission/18307130340/5.sql new file mode 100644 index 0000000..7fc03b1 --- /dev/null +++ b/assignments/ass1/submission/18307130340/5.sql @@ -0,0 +1,5 @@ +#Qeury all fields for employees whose name started with J (ordered by age) +select * +from employee +where name like 'J%' +order by age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/6.sql b/assignments/ass1/submission/18307130340/6.sql new file mode 100644 index 0000000..278ef6a --- /dev/null +++ b/assignments/ass1/submission/18307130340/6.sql @@ -0,0 +1,4 @@ +#Query the names of all publishers, if one publisher has more than two books in the database, output the name of the publisher only once (ordered by name, ascii order) +select distinct publisher +from book +order by publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/7.sql b/assignments/ass1/submission/18307130340/7.sql new file mode 100644 index 0000000..4b933b9 --- /dev/null +++ b/assignments/ass1/submission/18307130340/7.sql @@ -0,0 +1,5 @@ +#Query the id of all books that is borrowed after 2016-10-31, also the IDs should be distinct (ordered by id) +select distinct book_id +from record +where time > '2016-10-31' +order by book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/8.sql b/assignments/ass1/submission/18307130340/8.sql new file mode 100644 index 0000000..394596a --- /dev/null +++ b/assignments/ass1/submission/18307130340/8.sql @@ -0,0 +1,6 @@ +#Query for each employee who has borrowed book more than once, output the id, name, and number of borrow record (name the field num), ordered by num in descending order +select id, name, count(*) as num +from employee join record on id = employee_id +group by id + having num > 1 +order by num desc; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130340/create_table.sql b/assignments/ass1/submission/18307130340/create_table.sql new file mode 100644 index 0000000..b8802d6 --- /dev/null +++ b/assignments/ass1/submission/18307130340/create_table.sql @@ -0,0 +1,24 @@ +create table employee( + id integer not null, + name varchar(32), + office varchar(32), + age smallint, + primary key(id) +); + +create table book( + id integer not null, + name varchar(32), + author varchar(32), + publisher varchar(32), + primary key(id) +); + +create table record( + book_id integer, + employee_id integer, + time date, + foreign key(book_id) references book(id), + foreign key(employee_id) references employee(id), + primary key(book_id, employee_id) +); \ No newline at end of file From 868a7bc45d4c6c9fb82d4b0728028284b3bc952e Mon Sep 17 00:00:00 2001 From: obangw <18307130116@fudan.edu.cn> Date: Thu, 19 Mar 2020 02:44:33 -0700 Subject: [PATCH 051/189] submission of obangw for ass1 --- assignments/ass1/submission/18307130116/1.sql | 3 +++ assignments/ass1/submission/18307130116/2.sql | 3 +++ assignments/ass1/submission/18307130116/3.sql | 4 ++++ assignments/ass1/submission/18307130116/4.sql | 4 ++++ assignments/ass1/submission/18307130116/5.sql | 4 ++++ assignments/ass1/submission/18307130116/6.sql | 4 ++++ assignments/ass1/submission/18307130116/7.sql | 4 ++++ assignments/ass1/submission/18307130116/8.sql | 6 ++++++ .../submission/18307130116/create_table.sql | 19 +++++++++++++++++++ 9 files changed, 51 insertions(+) create mode 100644 assignments/ass1/submission/18307130116/1.sql create mode 100644 assignments/ass1/submission/18307130116/2.sql create mode 100644 assignments/ass1/submission/18307130116/3.sql create mode 100644 assignments/ass1/submission/18307130116/4.sql create mode 100644 assignments/ass1/submission/18307130116/5.sql create mode 100644 assignments/ass1/submission/18307130116/6.sql create mode 100644 assignments/ass1/submission/18307130116/7.sql create mode 100644 assignments/ass1/submission/18307130116/8.sql create mode 100644 assignments/ass1/submission/18307130116/create_table.sql diff --git a/assignments/ass1/submission/18307130116/1.sql b/assignments/ass1/submission/18307130116/1.sql new file mode 100644 index 0000000..b15e385 --- /dev/null +++ b/assignments/ass1/submission/18307130116/1.sql @@ -0,0 +1,3 @@ +SELECT id,name, office, age +FROM employee +WHERE name = 'Jones' diff --git a/assignments/ass1/submission/18307130116/2.sql b/assignments/ass1/submission/18307130116/2.sql new file mode 100644 index 0000000..7debd8a --- /dev/null +++ b/assignments/ass1/submission/18307130116/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id = '1' OR id = '2' diff --git a/assignments/ass1/submission/18307130116/3.sql b/assignments/ass1/submission/18307130116/3.sql new file mode 100644 index 0000000..18e49bd --- /dev/null +++ b/assignments/ass1/submission/18307130116/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id != '1' +ORDER BY id diff --git a/assignments/ass1/submission/18307130116/4.sql b/assignments/ass1/submission/18307130116/4.sql new file mode 100644 index 0000000..14bf836 --- /dev/null +++ b/assignments/ass1/submission/18307130116/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age >= 25 AND age <= 30 +ORDER BY id diff --git a/assignments/ass1/submission/18307130116/5.sql b/assignments/ass1/submission/18307130116/5.sql new file mode 100644 index 0000000..d100b6f --- /dev/null +++ b/assignments/ass1/submission/18307130116/5.sql @@ -0,0 +1,4 @@ +SELECT id, name, office, age +FROM employee +WHERE name LIKE 'J%' +ORDER BY age diff --git a/assignments/ass1/submission/18307130116/6.sql b/assignments/ass1/submission/18307130116/6.sql new file mode 100644 index 0000000..4a32c15 --- /dev/null +++ b/assignments/ass1/submission/18307130116/6.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher + diff --git a/assignments/ass1/submission/18307130116/7.sql b/assignments/ass1/submission/18307130116/7.sql new file mode 100644 index 0000000..aba7afe --- /dev/null +++ b/assignments/ass1/submission/18307130116/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT id +FROM book,record +WHERE book.id = record.book_id AND record.time > '2016-10-31' +ORDER BY id diff --git a/assignments/ass1/submission/18307130116/8.sql b/assignments/ass1/submission/18307130116/8.sql new file mode 100644 index 0000000..6b33025 --- /dev/null +++ b/assignments/ass1/submission/18307130116/8.sql @@ -0,0 +1,6 @@ +SELECT id, name, count(id) AS num +FROM employee, record +WHERE employee.id = record.employee_id +GROUP BY id + HAVING count(id) > 1 +ORDER BY num diff --git a/assignments/ass1/submission/18307130116/create_table.sql b/assignments/ass1/submission/18307130116/create_table.sql new file mode 100644 index 0000000..cbd038d --- /dev/null +++ b/assignments/ass1/submission/18307130116/create_table.sql @@ -0,0 +1,19 @@ +CREATE TABLE employee + (id INTEGER, + name VARCHAR(32) NOT NULL, + office VARCHAR(32) NOT NULL, + age SMALLINT, + PRIMARY KEY(id)); +CREATE TABLE book + (id INTEGER, + name VARCHAR(32) NOT NULL, + author VARCHAR(32) NOT NULL, + publisher VARCHAR(32) NOT NULL, + PRIMARY KEY(id)); +CREATE TABLE record + (book_id INTEGER, + employee_id INTEGER, + time DATE, + FOREIGN KEY(book_id) REFERENCES book(id), + FOREIGN KEY(employee_id) REFERENCES employee(id)); + From 78649f209fcf2e32c68f49eac63826881a712d50 Mon Sep 17 00:00:00 2001 From: Kimchuls Date: Thu, 19 Mar 2020 19:48:47 +0800 Subject: [PATCH 052/189] submission of 18307130112 for ass1 --- assignments/ass1/submission/18307130112/1.sql | 1 + assignments/ass1/submission/18307130112/2.sql | 1 + assignments/ass1/submission/18307130112/3.sql | 1 + assignments/ass1/submission/18307130112/4.sql | 1 + assignments/ass1/submission/18307130112/5.sql | 1 + assignments/ass1/submission/18307130112/6.sql | 3 +++ assignments/ass1/submission/18307130112/7.sql | 1 + assignments/ass1/submission/18307130112/8.sql | 5 +++++ .../submission/18307130112/create_table.sql | 18 ++++++++++++++++++ 9 files changed, 32 insertions(+) create mode 100644 assignments/ass1/submission/18307130112/1.sql create mode 100644 assignments/ass1/submission/18307130112/2.sql create mode 100644 assignments/ass1/submission/18307130112/3.sql create mode 100644 assignments/ass1/submission/18307130112/4.sql create mode 100644 assignments/ass1/submission/18307130112/5.sql create mode 100644 assignments/ass1/submission/18307130112/6.sql create mode 100644 assignments/ass1/submission/18307130112/7.sql create mode 100644 assignments/ass1/submission/18307130112/8.sql create mode 100644 assignments/ass1/submission/18307130112/create_table.sql diff --git a/assignments/ass1/submission/18307130112/1.sql b/assignments/ass1/submission/18307130112/1.sql new file mode 100644 index 0000000..448c408 --- /dev/null +++ b/assignments/ass1/submission/18307130112/1.sql @@ -0,0 +1 @@ +select * from employee where name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/2.sql b/assignments/ass1/submission/18307130112/2.sql new file mode 100644 index 0000000..0501dce --- /dev/null +++ b/assignments/ass1/submission/18307130112/2.sql @@ -0,0 +1 @@ +select name from employee where id = 1 or id = 2; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/3.sql b/assignments/ass1/submission/18307130112/3.sql new file mode 100644 index 0000000..b987bdf --- /dev/null +++ b/assignments/ass1/submission/18307130112/3.sql @@ -0,0 +1 @@ +select name from employee where id <> 1 order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/4.sql b/assignments/ass1/submission/18307130112/4.sql new file mode 100644 index 0000000..612b93b --- /dev/null +++ b/assignments/ass1/submission/18307130112/4.sql @@ -0,0 +1 @@ +select name from employee where age >= 25 and age <= 30 order by id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/5.sql b/assignments/ass1/submission/18307130112/5.sql new file mode 100644 index 0000000..9c661fa --- /dev/null +++ b/assignments/ass1/submission/18307130112/5.sql @@ -0,0 +1 @@ +select * from employee where name like 'J%' order by age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/6.sql b/assignments/ass1/submission/18307130112/6.sql new file mode 100644 index 0000000..b149fba --- /dev/null +++ b/assignments/ass1/submission/18307130112/6.sql @@ -0,0 +1,3 @@ +select distinct name +from (select author, count(name) from book group by author) as pubs(name, sumbook) +where sumbook >= 2 order by name; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/7.sql b/assignments/ass1/submission/18307130112/7.sql new file mode 100644 index 0000000..6bfefe3 --- /dev/null +++ b/assignments/ass1/submission/18307130112/7.sql @@ -0,0 +1 @@ +select distinct book_id from record where time > '2016-10-31' order by book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/8.sql b/assignments/ass1/submission/18307130112/8.sql new file mode 100644 index 0000000..e6980a4 --- /dev/null +++ b/assignments/ass1/submission/18307130112/8.sql @@ -0,0 +1,5 @@ +select id, name, sum from employee, +(select employee_id, count(employee_id) from record group by employee_id) +as borrows(employee_id, sum) +where sum > 0 and id = employee_id +order by sum desc; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130112/create_table.sql b/assignments/ass1/submission/18307130112/create_table.sql new file mode 100644 index 0000000..e38f19e --- /dev/null +++ b/assignments/ass1/submission/18307130112/create_table.sql @@ -0,0 +1,18 @@ +create table if not exists employee + (id int not null, + name varchar(32) not null, + office varchar(32) not null, + age int not null ,check(age>=0 and age<=100), + primary key(id)); +create table if not exists book + (id int not null, + name varchar(32) not null, + author varchar(32) not null, + publisher varchar(32) not null, + primary key(id)); +create table if not exists record + (book_id int not null, + employee_id int not null, + time date, + foreign key (book_id) references book(id), + foreign key (employee_id) references employee(id)); \ No newline at end of file From 7982ec8bcfea6ed66681fc0ca4a5bb18b46d382c Mon Sep 17 00:00:00 2001 From: xudinghuan <61900920+xudinghuan@users.noreply.github.com> Date: Thu, 19 Mar 2020 04:57:28 -0700 Subject: [PATCH 053/189] Delete 18307130031 --- assignments/ass1/submission/18307130031 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 assignments/ass1/submission/18307130031 diff --git a/assignments/ass1/submission/18307130031 b/assignments/ass1/submission/18307130031 deleted file mode 100644 index 8b13789..0000000 --- a/assignments/ass1/submission/18307130031 +++ /dev/null @@ -1 +0,0 @@ - From a4821f8fecb3138fbbe4e092b725915013eba6a7 Mon Sep 17 00:00:00 2001 From: xudinghuan <18307130031@fudan.edu.cn> Date: Thu, 19 Mar 2020 05:26:25 -0700 Subject: [PATCH 054/189] submission of 18307130031 for ass1 --- assignments/ass1/submission/18307130031/1.sql | 3 ++ assignments/ass1/submission/18307130031/2.sql | 3 ++ assignments/ass1/submission/18307130031/3.sql | 4 +++ assignments/ass1/submission/18307130031/4.sql | 4 +++ assignments/ass1/submission/18307130031/5.sql | 4 +++ assignments/ass1/submission/18307130031/6.sql | 4 +++ assignments/ass1/submission/18307130031/7.sql | 4 +++ assignments/ass1/submission/18307130031/8.sql | 6 ++++ .../submission/18307130031/create_table.sql | 21 ++++++++++++ .../submission/18307130031/insert_data.sql | 34 +++++++++++++++++++ 10 files changed, 87 insertions(+) create mode 100644 assignments/ass1/submission/18307130031/1.sql create mode 100644 assignments/ass1/submission/18307130031/2.sql create mode 100644 assignments/ass1/submission/18307130031/3.sql create mode 100644 assignments/ass1/submission/18307130031/4.sql create mode 100644 assignments/ass1/submission/18307130031/5.sql create mode 100644 assignments/ass1/submission/18307130031/6.sql create mode 100644 assignments/ass1/submission/18307130031/7.sql create mode 100644 assignments/ass1/submission/18307130031/8.sql create mode 100644 assignments/ass1/submission/18307130031/create_table.sql create mode 100644 assignments/ass1/submission/18307130031/insert_data.sql diff --git a/assignments/ass1/submission/18307130031/1.sql b/assignments/ass1/submission/18307130031/1.sql new file mode 100644 index 0000000..9a36fc2 --- /dev/null +++ b/assignments/ass1/submission/18307130031/1.sql @@ -0,0 +1,3 @@ +SELECT id, name, office, age +FROM employee +WHERE name = 'Jones'; diff --git a/assignments/ass1/submission/18307130031/2.sql b/assignments/ass1/submission/18307130031/2.sql new file mode 100644 index 0000000..d6c59ff --- /dev/null +++ b/assignments/ass1/submission/18307130031/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id = '1' OR id = '2'; diff --git a/assignments/ass1/submission/18307130031/3.sql b/assignments/ass1/submission/18307130031/3.sql new file mode 100644 index 0000000..0c2acaa --- /dev/null +++ b/assignments/ass1/submission/18307130031/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id != '1' +ORDER BY id ASC; diff --git a/assignments/ass1/submission/18307130031/4.sql b/assignments/ass1/submission/18307130031/4.sql new file mode 100644 index 0000000..5831010 --- /dev/null +++ b/assignments/ass1/submission/18307130031/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age >= '25' AND age <= '30' +ORDER BY id ASC; diff --git a/assignments/ass1/submission/18307130031/5.sql b/assignments/ass1/submission/18307130031/5.sql new file mode 100644 index 0000000..397f1ff --- /dev/null +++ b/assignments/ass1/submission/18307130031/5.sql @@ -0,0 +1,4 @@ +SELECT id, name, office, age +FROM employee +WHERE name LIKE 'J%' +ORDER BY age ASC; diff --git a/assignments/ass1/submission/18307130031/6.sql b/assignments/ass1/submission/18307130031/6.sql new file mode 100644 index 0000000..8a66884 --- /dev/null +++ b/assignments/ass1/submission/18307130031/6.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT X.publisher +FROM book AS X, book AS Y, book AS Z +WHERE X.publisher = Y.publisher AND X.publisher = Z.publisher AND X.name != Y.name AND Y.name != Z.name AND Z.name != X.name +ORDER BY X.publisher ASC; diff --git a/assignments/ass1/submission/18307130031/7.sql b/assignments/ass1/submission/18307130031/7.sql new file mode 100644 index 0000000..17b015b --- /dev/null +++ b/assignments/ass1/submission/18307130031/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT id +FROM book, record +WHERE id = book_id AND to_days(time) - to_days('2016-10-31') > 0 +ORDER BY id ASC; diff --git a/assignments/ass1/submission/18307130031/8.sql b/assignments/ass1/submission/18307130031/8.sql new file mode 100644 index 0000000..8f1c277 --- /dev/null +++ b/assignments/ass1/submission/18307130031/8.sql @@ -0,0 +1,6 @@ +SELECT DISTINCT id, name, COUNT(id) AS num +FROM employee, record +WHERE id = employee_id +GROUP BY employee_id + HAVING num >= '2' +ORDER BY num DESC; diff --git a/assignments/ass1/submission/18307130031/create_table.sql b/assignments/ass1/submission/18307130031/create_table.sql new file mode 100644 index 0000000..f606d26 --- /dev/null +++ b/assignments/ass1/submission/18307130031/create_table.sql @@ -0,0 +1,21 @@ +CREATE TABLE employee +(id INTEGER NOT NULL, + name VARCHAR(32) NOT NULL, + office VARCHAR(32) NOT NULL, + age INTEGER NOT NULL, + PRIMARY KEY(id)); + +CREATE TABLE book +(id INTEGER NOT NULL, + name VARCHAR(32) NOT NULL, + author VARCHAR(32) NOT NULL, + publisher VARCHAR(32) NOT NULL, + PRIMARY KEY(id)); + +CREATE TABLE record +(book_id INTEGER NOT NULL, + employee_id INTEGER NOT NULL, + time DATE NOT NULL, + FOREIGN KEY(book_id) REFERENCES book(id), + FOREIGN KEY(employee_id) REFERENCES employee(id)); + diff --git a/assignments/ass1/submission/18307130031/insert_data.sql b/assignments/ass1/submission/18307130031/insert_data.sql new file mode 100644 index 0000000..4c70fb8 --- /dev/null +++ b/assignments/ass1/submission/18307130031/insert_data.sql @@ -0,0 +1,34 @@ +INSERT INTO employee (id, name, office, age) VALUES + (1, 'Jones', 'CA', 30), + (2, 'Alice', 'SJ', 33), + (3, 'Bob', 'NY', 29), + (4, 'Jack', 'CN', 50); + +INSERT INTO book (id, name, author, publisher) VALUES + (1, 'T1', 'A1', 'McGraw-Hill'), + (2, 'T1', 'A1', 'McGraw-Hill'), + (3, 'T2', 'A2', 'McGraw-Hill'), + (4, 'T2', 'A2', 'McGraw-Hill'), + (5, 'T3', 'A3', 'McGraw-Hill'), + (6, 'T3', 'A3', 'McGraw-Hill'), + (11, 'T4', 'A4', 'Fudan'), + (12, 'T4', 'A4', 'Fudan'), + (13, 'T5', 'A5', 'Fudan'), + (14, 'T6', 'A6', 'Fudan'), + (15, 'T7', 'A7', 'Fudan'), + (16, 'T8', 'A8', 'Fudan'); + +INSERT INTO record (employee_id, book_id, time) VALUES + (1, 1, '2016-3-24'), + (2, 2, '2016-3-24'), + (2, 3, '2016-3-24'), + (1, 4, '2016-3-25'), + (3, 5, '2016-3-25'), + (1, 6, '2016-3-25'), + (1, 11, '2018-4-18'), + (4, 12, '2018-4-18'), + (4, 13, '2018-4-18'), + (1, 14, '2018-4-18'), + (1, 15, '2018-4-18'), + (2, 16, '2018-4-18'), + (2, 1, '2018-3-18'); From 1f861390edd00d05906501be1589f75432bd1f40 Mon Sep 17 00:00:00 2001 From: moyiii-ai <19307130296@fudan.edu.cn> Date: Thu, 19 Mar 2020 21:59:30 +0800 Subject: [PATCH 055/189] =?UTF-8?q?submission=20of=20=E5=AD=99=E8=8B=A5?= =?UTF-8?q?=E8=AF=97=20for=20ass1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assignments/ass1/submission/19307130296/1.sql | 3 +++ assignments/ass1/submission/19307130296/2.sql | 3 +++ assignments/ass1/submission/19307130296/3.sql | 4 ++++ assignments/ass1/submission/19307130296/4.sql | 4 ++++ assignments/ass1/submission/19307130296/5.sql | 4 ++++ assignments/ass1/submission/19307130296/6.sql | 3 +++ assignments/ass1/submission/19307130296/7.sql | 4 ++++ assignments/ass1/submission/19307130296/8.sql | 9 ++++++++ .../submission/19307130296/create_table.sql | 21 +++++++++++++++++++ 9 files changed, 55 insertions(+) create mode 100644 assignments/ass1/submission/19307130296/1.sql create mode 100644 assignments/ass1/submission/19307130296/2.sql create mode 100644 assignments/ass1/submission/19307130296/3.sql create mode 100644 assignments/ass1/submission/19307130296/4.sql create mode 100644 assignments/ass1/submission/19307130296/5.sql create mode 100644 assignments/ass1/submission/19307130296/6.sql create mode 100644 assignments/ass1/submission/19307130296/7.sql create mode 100644 assignments/ass1/submission/19307130296/8.sql create mode 100644 assignments/ass1/submission/19307130296/create_table.sql diff --git a/assignments/ass1/submission/19307130296/1.sql b/assignments/ass1/submission/19307130296/1.sql new file mode 100644 index 0000000..2192ce4 --- /dev/null +++ b/assignments/ass1/submission/19307130296/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name='Jones' diff --git a/assignments/ass1/submission/19307130296/2.sql b/assignments/ass1/submission/19307130296/2.sql new file mode 100644 index 0000000..0ceb873 --- /dev/null +++ b/assignments/ass1/submission/19307130296/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id=1 OR id=2 \ No newline at end of file diff --git a/assignments/ass1/submission/19307130296/3.sql b/assignments/ass1/submission/19307130296/3.sql new file mode 100644 index 0000000..6247e25 --- /dev/null +++ b/assignments/ass1/submission/19307130296/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id!=1 +ORDER BY id ASC \ No newline at end of file diff --git a/assignments/ass1/submission/19307130296/4.sql b/assignments/ass1/submission/19307130296/4.sql new file mode 100644 index 0000000..99a86da --- /dev/null +++ b/assignments/ass1/submission/19307130296/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age BETWEEN 25 AND 30 +ORDER BY id ASC \ No newline at end of file diff --git a/assignments/ass1/submission/19307130296/5.sql b/assignments/ass1/submission/19307130296/5.sql new file mode 100644 index 0000000..b427a19 --- /dev/null +++ b/assignments/ass1/submission/19307130296/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name='J%' +ORDER BY age ASC \ No newline at end of file diff --git a/assignments/ass1/submission/19307130296/6.sql b/assignments/ass1/submission/19307130296/6.sql new file mode 100644 index 0000000..d9cba79 --- /dev/null +++ b/assignments/ass1/submission/19307130296/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher ASC \ No newline at end of file diff --git a/assignments/ass1/submission/19307130296/7.sql b/assignments/ass1/submission/19307130296/7.sql new file mode 100644 index 0000000..81d3e7c --- /dev/null +++ b/assignments/ass1/submission/19307130296/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT book_id +FROM record +WHERE time>2016-10-31 +ORDER BY id ASC \ No newline at end of file diff --git a/assignments/ass1/submission/19307130296/8.sql b/assignments/ass1/submission/19307130296/8.sql new file mode 100644 index 0000000..49fea1d --- /dev/null +++ b/assignments/ass1/submission/19307130296/8.sql @@ -0,0 +1,9 @@ +SELECT id, name, num +FROM employee +GROUP BY id +HAVING COUNT( + SELECT * + FROM record + WHERE record.employee_id=employee.id +) AS num>1 +ORDER BY num \ No newline at end of file diff --git a/assignments/ass1/submission/19307130296/create_table.sql b/assignments/ass1/submission/19307130296/create_table.sql new file mode 100644 index 0000000..5adbb59 --- /dev/null +++ b/assignments/ass1/submission/19307130296/create_table.sql @@ -0,0 +1,21 @@ +CREATE TABLE employee( + id int(32) not null auto_increment primary key, + name varchar(32), + office varchar(32), + age int(3) +) + +CREATE TABLE book( + id int(32) not null auto_increment primary key, + name varchar(32), + author varchar(32), + publisher varchar(32) +) + +CREATE TABLE record( + time DATE, + book_id int(32) not null, + employee_id int(32) not null, + foreign key(book_id) references book(id), + foreign key(employee_id) references employee(id) +) \ No newline at end of file From 904141cd4e20833b69a96275b227040a9d1b0f2e Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:20:16 +0800 Subject: [PATCH 056/189] Create create_table.sql --- .../submission/19300290059/create_table.sql | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 assignments/ass1/submission/19300290059/create_table.sql diff --git a/assignments/ass1/submission/19300290059/create_table.sql b/assignments/ass1/submission/19300290059/create_table.sql new file mode 100644 index 0000000..6094650 --- /dev/null +++ b/assignments/ass1/submission/19300290059/create_table.sql @@ -0,0 +1,22 @@ +CREATE TABLE employee( +id INT NOT NULL, +name VARCHAR(32), +office VARCHAR(32), +age INT, +CHECK (age <= 100 AND age >= 0), +PRIMARY KEY(id) +); +CREATE TABLE book( +id INT NOT NULL, +name VARCHAR(32), +author VARCHAR(32), +publisher VARCHAR(32), +PRIMARY KEY (id) +); +CREATE TABLE record( +book_id INT, +employee_id INT, +time DATE, +FOREIGN KEY(book_id) REFERENCES book(id), +FOREIGN KEY(employee_id) REFERENCES employee(id) +) From a2983aee49f3a12da55a08610109f6a1a951d4b5 Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:21:02 +0800 Subject: [PATCH 057/189] Create 1.sql --- assignments/ass1/submission/19300290059/1.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/1.sql diff --git a/assignments/ass1/submission/19300290059/1.sql b/assignments/ass1/submission/19300290059/1.sql new file mode 100644 index 0000000..559dc23 --- /dev/null +++ b/assignments/ass1/submission/19300290059/1.sql @@ -0,0 +1 @@ +SELECT * FROM employee WHERE name='Jones'; From 292ee8afa134fefe02cb46697ba398653cc18ad2 Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:54:42 +0800 Subject: [PATCH 058/189] Create 2.sql --- assignments/ass1/submission/19300290059/2.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/2.sql diff --git a/assignments/ass1/submission/19300290059/2.sql b/assignments/ass1/submission/19300290059/2.sql new file mode 100644 index 0000000..caf833b --- /dev/null +++ b/assignments/ass1/submission/19300290059/2.sql @@ -0,0 +1 @@ +SELECT name FROM employee WHERE id=1 OR id=2; From ace7e196e63ddf1f912818088ce31db4768bc760 Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:55:12 +0800 Subject: [PATCH 059/189] Create 3.sql --- assignments/ass1/submission/19300290059/3.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/3.sql diff --git a/assignments/ass1/submission/19300290059/3.sql b/assignments/ass1/submission/19300290059/3.sql new file mode 100644 index 0000000..2f403ac --- /dev/null +++ b/assignments/ass1/submission/19300290059/3.sql @@ -0,0 +1 @@ +SELECT name FROM employee WHERE id <> 1 ORDER BY id; From e2842b3a443dd108ba44cbf3148e74ff1ed9ecdf Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:55:52 +0800 Subject: [PATCH 060/189] Create 4.sql --- assignments/ass1/submission/19300290059/4.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/4.sql diff --git a/assignments/ass1/submission/19300290059/4.sql b/assignments/ass1/submission/19300290059/4.sql new file mode 100644 index 0000000..e84f50f --- /dev/null +++ b/assignments/ass1/submission/19300290059/4.sql @@ -0,0 +1 @@ +SELECT name FROM employee WHERE age BETWEEN 25 AND 30 ORDER BY id; From a7e219c2336b76275d5a2ccd3e0763375ed88308 Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:56:14 +0800 Subject: [PATCH 061/189] Create 5.sql --- assignments/ass1/submission/19300290059/5.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/5.sql diff --git a/assignments/ass1/submission/19300290059/5.sql b/assignments/ass1/submission/19300290059/5.sql new file mode 100644 index 0000000..1ce1cce --- /dev/null +++ b/assignments/ass1/submission/19300290059/5.sql @@ -0,0 +1 @@ +SELECT * FROM employee WHERE name LIKE 'J%'; From fd3b98b286e2cdb4a9a53aa47859f0959257b738 Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:56:32 +0800 Subject: [PATCH 062/189] Create 6.sql --- assignments/ass1/submission/19300290059/6.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/6.sql diff --git a/assignments/ass1/submission/19300290059/6.sql b/assignments/ass1/submission/19300290059/6.sql new file mode 100644 index 0000000..e414422 --- /dev/null +++ b/assignments/ass1/submission/19300290059/6.sql @@ -0,0 +1 @@ +SELECT DISTINCT publisher FROM book ORDER BY ASCII(name); From 2c95fb6786ce90111b0519f2cdadf4719b70dce9 Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:56:49 +0800 Subject: [PATCH 063/189] Create 7.sql --- assignments/ass1/submission/19300290059/7.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/7.sql diff --git a/assignments/ass1/submission/19300290059/7.sql b/assignments/ass1/submission/19300290059/7.sql new file mode 100644 index 0000000..fc8c694 --- /dev/null +++ b/assignments/ass1/submission/19300290059/7.sql @@ -0,0 +1 @@ +SELECT DISTINCT book_id FROM record WHERE time >= '2016-10-31' ORDER BY book_id; From 168aeea9ac4b816b6cc7b27176a08a58d51498f3 Mon Sep 17 00:00:00 2001 From: Lorem796 <62368152+Lorem796@users.noreply.github.com> Date: Thu, 19 Mar 2020 22:57:07 +0800 Subject: [PATCH 064/189] Create 8.sql --- assignments/ass1/submission/19300290059/8.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignments/ass1/submission/19300290059/8.sql diff --git a/assignments/ass1/submission/19300290059/8.sql b/assignments/ass1/submission/19300290059/8.sql new file mode 100644 index 0000000..d29afe7 --- /dev/null +++ b/assignments/ass1/submission/19300290059/8.sql @@ -0,0 +1 @@ +SELECT id, name, COUNT(id) AS num FROM employee INNER JOIN record ON id=employee_id GROUP BY id HAVING num > 1 ORDER BY num DESC; From 428aea7994443cf18d0683b7022810373bacf05f Mon Sep 17 00:00:00 2001 From: daihuasheng <18307130123@fudan.edu.cn> Date: Thu, 19 Mar 2020 23:07:23 +0800 Subject: [PATCH 065/189] submission of 18307130123 for ass1 --- assignments/ass1/submission/18307130123/1.sql | 3 +++ assignments/ass1/submission/18307130123/2.sql | 3 +++ assignments/ass1/submission/18307130123/3.sql | 4 ++++ assignments/ass1/submission/18307130123/4.sql | 4 ++++ assignments/ass1/submission/18307130123/5.sql | 4 ++++ assignments/ass1/submission/18307130123/6.sql | 3 +++ assignments/ass1/submission/18307130123/7.sql | 4 ++++ assignments/ass1/submission/18307130123/8.sql | 5 +++++ .../submission/18307130123/create_table.sql | 19 +++++++++++++++++++ 9 files changed, 49 insertions(+) create mode 100644 assignments/ass1/submission/18307130123/1.sql create mode 100644 assignments/ass1/submission/18307130123/2.sql create mode 100644 assignments/ass1/submission/18307130123/3.sql create mode 100644 assignments/ass1/submission/18307130123/4.sql create mode 100644 assignments/ass1/submission/18307130123/5.sql create mode 100644 assignments/ass1/submission/18307130123/6.sql create mode 100644 assignments/ass1/submission/18307130123/7.sql create mode 100644 assignments/ass1/submission/18307130123/8.sql create mode 100644 assignments/ass1/submission/18307130123/create_table.sql diff --git a/assignments/ass1/submission/18307130123/1.sql b/assignments/ass1/submission/18307130123/1.sql new file mode 100644 index 0000000..3063bc3 --- /dev/null +++ b/assignments/ass1/submission/18307130123/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name = 'Jones'; diff --git a/assignments/ass1/submission/18307130123/2.sql b/assignments/ass1/submission/18307130123/2.sql new file mode 100644 index 0000000..8b96798 --- /dev/null +++ b/assignments/ass1/submission/18307130123/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id = 1 OR id = 2; diff --git a/assignments/ass1/submission/18307130123/3.sql b/assignments/ass1/submission/18307130123/3.sql new file mode 100644 index 0000000..cb1eb58 --- /dev/null +++ b/assignments/ass1/submission/18307130123/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id != 1 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130123/4.sql b/assignments/ass1/submission/18307130123/4.sql new file mode 100644 index 0000000..62cc442 --- /dev/null +++ b/assignments/ass1/submission/18307130123/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age BETWEEN 25 AND 30 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130123/5.sql b/assignments/ass1/submission/18307130123/5.sql new file mode 100644 index 0000000..b8a1f33 --- /dev/null +++ b/assignments/ass1/submission/18307130123/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name LIKE 'J%' +ORDER BY age; diff --git a/assignments/ass1/submission/18307130123/6.sql b/assignments/ass1/submission/18307130123/6.sql new file mode 100644 index 0000000..79f4172 --- /dev/null +++ b/assignments/ass1/submission/18307130123/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher; diff --git a/assignments/ass1/submission/18307130123/7.sql b/assignments/ass1/submission/18307130123/7.sql new file mode 100644 index 0000000..1932280 --- /dev/null +++ b/assignments/ass1/submission/18307130123/7.sql @@ -0,0 +1,4 @@ +SELECT book_id +FROM record +WHERE time > '2016-10-31' +ORDER BY book_id; diff --git a/assignments/ass1/submission/18307130123/8.sql b/assignments/ass1/submission/18307130123/8.sql new file mode 100644 index 0000000..a41270a --- /dev/null +++ b/assignments/ass1/submission/18307130123/8.sql @@ -0,0 +1,5 @@ +SELECT employee.id,name,count(*) AS num +FROM employee LEFT JOIN record ON employee.id = record.employee_id +GROUP BY employee.id + HAVING count(*) > 1 +ORDER BY num DESC; diff --git a/assignments/ass1/submission/18307130123/create_table.sql b/assignments/ass1/submission/18307130123/create_table.sql new file mode 100644 index 0000000..e930179 --- /dev/null +++ b/assignments/ass1/submission/18307130123/create_table.sql @@ -0,0 +1,19 @@ +CREATE TABLE employee + (id SMALLINT NOT NULL, + name VARCHAR(32), + office VARCHAR(32), + age SMALLINT, + PRIMARY KEY(id)); +CREATE TABLE book + (id SMALLINT NOT NULL, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32), + PRIMARY KEY(id)); +CREATE TABLE record + (book_id SMALLINT, + employee_id SMALLINT, + time DATE, + PRIMARY KEY(book_id,employee_id), + FOREIGN KEY(book_id)REFERENCES book(id), + FOREIGN KEY(employee_id)REFERENCES employee(id)); From 6b465fc3984b7a1f68be1900c2e725940fe03be1 Mon Sep 17 00:00:00 2001 From: xhs7700 Date: Thu, 19 Mar 2020 23:56:01 +0800 Subject: [PATCH 066/189] submission of 18307130090 for ass1 --- assignments/ass1/submission/18307130090/1.sql | 1 + assignments/ass1/submission/18307130090/2.sql | 2 ++ assignments/ass1/submission/18307130090/3.sql | 2 ++ assignments/ass1/submission/18307130090/4.sql | 3 +++ assignments/ass1/submission/18307130090/5.sql | 3 +++ assignments/ass1/submission/18307130090/6.sql | 5 ++++ assignments/ass1/submission/18307130090/7.sql | 2 ++ assignments/ass1/submission/18307130090/8.sql | 7 ++++++ .../submission/18307130090/create_table.sql | 23 +++++++++++++++++++ 9 files changed, 48 insertions(+) create mode 100644 assignments/ass1/submission/18307130090/1.sql create mode 100644 assignments/ass1/submission/18307130090/2.sql create mode 100644 assignments/ass1/submission/18307130090/3.sql create mode 100644 assignments/ass1/submission/18307130090/4.sql create mode 100644 assignments/ass1/submission/18307130090/5.sql create mode 100644 assignments/ass1/submission/18307130090/6.sql create mode 100644 assignments/ass1/submission/18307130090/7.sql create mode 100644 assignments/ass1/submission/18307130090/8.sql create mode 100644 assignments/ass1/submission/18307130090/create_table.sql diff --git a/assignments/ass1/submission/18307130090/1.sql b/assignments/ass1/submission/18307130090/1.sql new file mode 100644 index 0000000..f6b4b0a --- /dev/null +++ b/assignments/ass1/submission/18307130090/1.sql @@ -0,0 +1 @@ +select * from employee where name='Jones'; diff --git a/assignments/ass1/submission/18307130090/2.sql b/assignments/ass1/submission/18307130090/2.sql new file mode 100644 index 0000000..d826bb3 --- /dev/null +++ b/assignments/ass1/submission/18307130090/2.sql @@ -0,0 +1,2 @@ +select name from employee +where id=1 or id=2; diff --git a/assignments/ass1/submission/18307130090/3.sql b/assignments/ass1/submission/18307130090/3.sql new file mode 100644 index 0000000..12b5f46 --- /dev/null +++ b/assignments/ass1/submission/18307130090/3.sql @@ -0,0 +1,2 @@ +select name from employee +where id!=1 order by id; diff --git a/assignments/ass1/submission/18307130090/4.sql b/assignments/ass1/submission/18307130090/4.sql new file mode 100644 index 0000000..7577992 --- /dev/null +++ b/assignments/ass1/submission/18307130090/4.sql @@ -0,0 +1,3 @@ +select name from employee +where age between 25 and 30 +order by id; diff --git a/assignments/ass1/submission/18307130090/5.sql b/assignments/ass1/submission/18307130090/5.sql new file mode 100644 index 0000000..9229cc8 --- /dev/null +++ b/assignments/ass1/submission/18307130090/5.sql @@ -0,0 +1,3 @@ +select * from employee +where name like 'J%' +order by age; diff --git a/assignments/ass1/submission/18307130090/6.sql b/assignments/ass1/submission/18307130090/6.sql new file mode 100644 index 0000000..7ecd43f --- /dev/null +++ b/assignments/ass1/submission/18307130090/6.sql @@ -0,0 +1,5 @@ +with tmp(publisher,num)as( + select publisher,count(*) from book + group by publisher +) +select publisher from tmp where num>2 order by publisher; diff --git a/assignments/ass1/submission/18307130090/7.sql b/assignments/ass1/submission/18307130090/7.sql new file mode 100644 index 0000000..d0ae320 --- /dev/null +++ b/assignments/ass1/submission/18307130090/7.sql @@ -0,0 +1,2 @@ +select distinct book_id from record +where time>2016-10-31 order by book_id; diff --git a/assignments/ass1/submission/18307130090/8.sql b/assignments/ass1/submission/18307130090/8.sql new file mode 100644 index 0000000..7793cd5 --- /dev/null +++ b/assignments/ass1/submission/18307130090/8.sql @@ -0,0 +1,7 @@ +with tmp(id,num)as( + select employee_id,count(*) + from record group by employee_id +) +select id,name,num +from tmp natural inner join employee +order by num desc; diff --git a/assignments/ass1/submission/18307130090/create_table.sql b/assignments/ass1/submission/18307130090/create_table.sql new file mode 100644 index 0000000..3a33a25 --- /dev/null +++ b/assignments/ass1/submission/18307130090/create_table.sql @@ -0,0 +1,23 @@ +create table employee( + id int, + name char(32), + office char(32), + age int, + primary key(id), + check (id between 0 and 100) +); +create table book( + id int, + name char(32), + author char(32), + publisher char(32), + primary key(id) +); +create table record( + book_id int, + employee_id int, + time date, + primary key(book_id,employee_id), + foreign key(book_id)references book(id), + foreign key(employee_id)references employee(id) +); From e1a031a0a9c5101d82eba6fe9b0dcaacd6f72901 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Fri, 20 Mar 2020 04:07:21 +0800 Subject: [PATCH 067/189] Minor fix --- assignments/ass1/submission/18307130003/create_table.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/ass1/submission/18307130003/create_table.sql b/assignments/ass1/submission/18307130003/create_table.sql index 8f6c798..26d028f 100644 --- a/assignments/ass1/submission/18307130003/create_table.sql +++ b/assignments/ass1/submission/18307130003/create_table.sql @@ -15,7 +15,7 @@ CREATE TABLE book ( id INT NOT NULL, name VARCHAR(32) NOT NULL, author VARCHAR(32), - publisher VARCHAR(32), + publisher VARCHAR(32) ); CREATE TABLE record ( From 4e01eec658138ec8dad7c3fd05ea6fd8f20c6a80 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Fri, 20 Mar 2020 05:24:32 +0800 Subject: [PATCH 068/189] Done --- assignments/ass1/submission/18307130003/1.sql | 7 +++++++ assignments/ass1/submission/18307130003/2.sql | 7 +++++++ assignments/ass1/submission/18307130003/3.sql | 9 +++++++++ assignments/ass1/submission/18307130003/4.sql | 10 ++++++++++ assignments/ass1/submission/18307130003/5.sql | 9 +++++++++ assignments/ass1/submission/18307130003/6.sql | 9 +++++++++ assignments/ass1/submission/18307130003/7.sql | 10 ++++++++++ assignments/ass1/submission/18307130003/8.sql | 18 ++++++++++++++++++ .../submission/18307130003/create_table.sql | 3 +-- 9 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 assignments/ass1/submission/18307130003/1.sql create mode 100644 assignments/ass1/submission/18307130003/2.sql create mode 100644 assignments/ass1/submission/18307130003/3.sql create mode 100644 assignments/ass1/submission/18307130003/4.sql create mode 100644 assignments/ass1/submission/18307130003/5.sql create mode 100644 assignments/ass1/submission/18307130003/6.sql create mode 100644 assignments/ass1/submission/18307130003/7.sql create mode 100644 assignments/ass1/submission/18307130003/8.sql diff --git a/assignments/ass1/submission/18307130003/1.sql b/assignments/ass1/submission/18307130003/1.sql new file mode 100644 index 0000000..a6b4746 --- /dev/null +++ b/assignments/ass1/submission/18307130003/1.sql @@ -0,0 +1,7 @@ +-- Query all fields for employees named Jones +SELECT + * +FROM + employee +WHERE + name = 'Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/2.sql b/assignments/ass1/submission/18307130003/2.sql new file mode 100644 index 0000000..139d733 --- /dev/null +++ b/assignments/ass1/submission/18307130003/2.sql @@ -0,0 +1,7 @@ +-- Query the name of employees with ID equals to 1 or 2 (order does not matter) +SELECT + name +FROM + employee +WHERE + id IN (1, 2); \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/3.sql b/assignments/ass1/submission/18307130003/3.sql new file mode 100644 index 0000000..3e3a588 --- /dev/null +++ b/assignments/ass1/submission/18307130003/3.sql @@ -0,0 +1,9 @@ +-- Query the name of all employees except the one whose ID is 1 (ordered by ID) +SELECT + name +FROM + employee +WHERE + id <> 1 +ORDER BY + id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/4.sql b/assignments/ass1/submission/18307130003/4.sql new file mode 100644 index 0000000..ec25eff --- /dev/null +++ b/assignments/ass1/submission/18307130003/4.sql @@ -0,0 +1,10 @@ +-- Query the name of all employees with age between 25 and 30 (inclusively, +-- ordered by ID) +SELECT + name +FROM + employee +WHERE + age BETWEEN 25 AND 30 +ORDER BY + id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/5.sql b/assignments/ass1/submission/18307130003/5.sql new file mode 100644 index 0000000..e3d9f9e --- /dev/null +++ b/assignments/ass1/submission/18307130003/5.sql @@ -0,0 +1,9 @@ +-- Query all fields for employees whose name started with J (ordered by age) +SELECT + * +FROM + employee +WHERE + name LIKE 'J%' +ORDER BY + age; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/6.sql b/assignments/ass1/submission/18307130003/6.sql new file mode 100644 index 0000000..a4f406d --- /dev/null +++ b/assignments/ass1/submission/18307130003/6.sql @@ -0,0 +1,9 @@ +-- Query the names of all publishers, if one publisher has more than two books +-- in the database, output the name of the publisher only once (ordered by name, +-- ascii order) +SELECT + DISTINCT publisher +FROM + book +ORDER BY + publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/7.sql b/assignments/ass1/submission/18307130003/7.sql new file mode 100644 index 0000000..57fad7c --- /dev/null +++ b/assignments/ass1/submission/18307130003/7.sql @@ -0,0 +1,10 @@ +-- Query the id of all books that is borrowed after 2016-10-31, also the IDs +-- should be distinct (ordered by id) +SELECT + DISTINCT book_id +FROM + record +WHERE + time > '2016-10-31' +ORDER BY + book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/8.sql b/assignments/ass1/submission/18307130003/8.sql new file mode 100644 index 0000000..837fa9e --- /dev/null +++ b/assignments/ass1/submission/18307130003/8.sql @@ -0,0 +1,18 @@ +-- Query for each employee who has borrowed book more than once, output the id, +-- name, and number of borrow record (name the field num), ordered by num in +-- descending order. +SELECT + id, + name, + count(book_id) AS num +FROM + employee, + record +WHERE + id = employee_id +GROUP BY + employee_id +HAVING + num > 1 +ORDER BY + num DESC; \ No newline at end of file diff --git a/assignments/ass1/submission/18307130003/create_table.sql b/assignments/ass1/submission/18307130003/create_table.sql index 26d028f..fc2c2ec 100644 --- a/assignments/ass1/submission/18307130003/create_table.sql +++ b/assignments/ass1/submission/18307130003/create_table.sql @@ -5,8 +5,7 @@ CREATE TABLE employee ( office VARCHAR(32), age INT, CONSTRAINT age_range CHECK ( - age BETWEEN 0 - AND 100 + age BETWEEN 0 AND 100 ) ); From ed78b12c36c633b5550a0cf536772ff411eabb8d Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Fri, 20 Mar 2020 05:53:48 +0800 Subject: [PATCH 069/189] Fix typos --- content/assignment1/readme.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/content/assignment1/readme.md b/content/assignment1/readme.md index c3b5f62..0b11681 100644 --- a/content/assignment1/readme.md +++ b/content/assignment1/readme.md @@ -12,7 +12,7 @@ Basically you need to use * order by * having -to be able to finish the assginment. +to be able to finish the assignment. ## Working Directory Setup @@ -32,7 +32,7 @@ Once you've cloned the project in your local environment, get to `IDBS-Spring20- ## Table Creation -You need to create 3 tables under the database `ass1`, namely `employee`, `book` and `loan`. +You need to create 3 tables under the database `ass1`, namely `employee`, `book` and `record`. Create a file named `create_table.sql` under your working directory, and write the SQL to create the tables asked in that file. @@ -48,7 +48,7 @@ Once you finished the table creation SQLs, create a database in your MySQL named mysql -h localhost -u username ass1 -p < create_table.sql ``` -If `mysql` complaints about any error, try to fix it in `create_table.sql`. You could drop and recreate the database `ass1` if you've ruined the database with wrongly created tables. +If `mysql` complains about any error, try to fix it in `create_table.sql`. You could drop and recreate the database `ass1` if you've ruined the database with wrongly created tables. Once you've created the table, take a look at `assignments/ass1/insert_data.sql`, which inserts sample data into your newly created tables, run them through MySQL client as well: @@ -60,18 +60,18 @@ The data is meant for you to play with the database and test with your own SQLs. ## Query from the Database -In this part, you are going to write querys to play with the database you just created. +In this part, you are going to write queries to play with the database you just created. For each part, create a file in your working directory, for example `1.sql`, `2.sql` etc. 1. Query all fields for employees named `Jones` -2. Query the name of employees with ID equals to `1` or `2` (order dose not matter) +2. Query the name of employees with ID equals to `1` or `2` (order does not matter) 3. Query the name of all employees except the one whose ID is `1` (ordered by ID) 4. Query the name of all employees with age between 25 and 30 (inclusively, ordered by ID) -5. Qeury all fields for employees whose name started with `J` (ordered by age) +5. Query all fields for employees whose name started with `J` (ordered by age) 6. Query the names of all publishers, if one publisher has more than two books in the database, output the name of the publisher only once (ordered by name, ascii order) 7. Query the id of all books that is borrowed after `2016-10-31`, also the IDs should be distinct (ordered by id) -8. Query for each employee who has borrowed book more than once, output the `id`, `name`, and number of borrow record (name the field `num`), ordered by `num` in descending order. This one is kind of challenging, the TA's solution uses JOIN, GROUP BY, HAVING and ORDER BY, check them out if you don't know what does these key words mean for MySQL. +8. Query for each employee who has borrowed book more than once, output the `id`, `name`, and number of borrow record (name the field `num`), ordered by `num` in descending order. This one is kind of challenging, the TA's solution uses JOIN, GROUP BY, HAVING and ORDER BY, check them out if you don't know what these key words mean for MySQL. ## Submit Your Solution From adf37c02da899778fc9db23c39c6d7868fe6b56b Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Thu, 19 Mar 2020 09:34:10 +0800 Subject: [PATCH 070/189] mv wrongly placed submission to submission directory --- .gitignore | 3 ++- assignments/ass1/create_table.sql | 21 +++++++++++++++++++ .../ass1/{ => submission}/18307130172/1.sql | 0 .../ass1/{ => submission}/18307130172/2.sql | 0 .../ass1/{ => submission}/18307130172/3.sql | 0 .../ass1/{ => submission}/18307130172/4.sql | 0 .../ass1/{ => submission}/18307130172/5.sql | 0 .../ass1/{ => submission}/18307130172/6.sql | 0 .../ass1/{ => submission}/18307130172/7.sql | 0 .../ass1/{ => submission}/18307130172/8.sql | 0 .../18307130172/create_table.sql | 0 .../ass1/{ => submission}/18307130297/1.sql | 0 .../ass1/{ => submission}/18307130297/2.sql | 0 .../ass1/{ => submission}/18307130297/3.sql | 0 .../ass1/{ => submission}/18307130297/4.sql | 0 .../ass1/{ => submission}/18307130297/5.sql | 0 .../ass1/{ => submission}/18307130297/6.sql | 0 .../ass1/{ => submission}/18307130297/7.sql | 0 .../ass1/{ => submission}/18307130297/8.sql | 0 .../18307130297/create_table.sql | 0 20 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 assignments/ass1/create_table.sql rename assignments/ass1/{ => submission}/18307130172/1.sql (100%) rename assignments/ass1/{ => submission}/18307130172/2.sql (100%) rename assignments/ass1/{ => submission}/18307130172/3.sql (100%) rename assignments/ass1/{ => submission}/18307130172/4.sql (100%) rename assignments/ass1/{ => submission}/18307130172/5.sql (100%) rename assignments/ass1/{ => submission}/18307130172/6.sql (100%) rename assignments/ass1/{ => submission}/18307130172/7.sql (100%) rename assignments/ass1/{ => submission}/18307130172/8.sql (100%) rename assignments/ass1/{ => submission}/18307130172/create_table.sql (100%) rename assignments/ass1/{ => submission}/18307130297/1.sql (100%) rename assignments/ass1/{ => submission}/18307130297/2.sql (100%) rename assignments/ass1/{ => submission}/18307130297/3.sql (100%) rename assignments/ass1/{ => submission}/18307130297/4.sql (100%) rename assignments/ass1/{ => submission}/18307130297/5.sql (100%) rename assignments/ass1/{ => submission}/18307130297/6.sql (100%) rename assignments/ass1/{ => submission}/18307130297/7.sql (100%) rename assignments/ass1/{ => submission}/18307130297/8.sql (100%) rename assignments/ass1/{ => submission}/18307130297/create_table.sql (100%) diff --git a/.gitignore b/.gitignore index 96c0ecc..d4777df 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -docs/ \ No newline at end of file +assignments/evaluator +docs/ diff --git a/assignments/ass1/create_table.sql b/assignments/ass1/create_table.sql new file mode 100644 index 0000000..29db0b3 --- /dev/null +++ b/assignments/ass1/create_table.sql @@ -0,0 +1,21 @@ +CREATE TABLE employee ( + id INT PRIMARY KEY, + name VARCHAR(32), + office VARCHAR(32), + age INT +); + +CREATE TABLE book ( + id INT PRIMARY KEY, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32) +); + +CREATE TABLE record ( + book_id INT, + employee_id INT, + time DATE, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id) +); diff --git a/assignments/ass1/18307130172/1.sql b/assignments/ass1/submission/18307130172/1.sql similarity index 100% rename from assignments/ass1/18307130172/1.sql rename to assignments/ass1/submission/18307130172/1.sql diff --git a/assignments/ass1/18307130172/2.sql b/assignments/ass1/submission/18307130172/2.sql similarity index 100% rename from assignments/ass1/18307130172/2.sql rename to assignments/ass1/submission/18307130172/2.sql diff --git a/assignments/ass1/18307130172/3.sql b/assignments/ass1/submission/18307130172/3.sql similarity index 100% rename from assignments/ass1/18307130172/3.sql rename to assignments/ass1/submission/18307130172/3.sql diff --git a/assignments/ass1/18307130172/4.sql b/assignments/ass1/submission/18307130172/4.sql similarity index 100% rename from assignments/ass1/18307130172/4.sql rename to assignments/ass1/submission/18307130172/4.sql diff --git a/assignments/ass1/18307130172/5.sql b/assignments/ass1/submission/18307130172/5.sql similarity index 100% rename from assignments/ass1/18307130172/5.sql rename to assignments/ass1/submission/18307130172/5.sql diff --git a/assignments/ass1/18307130172/6.sql b/assignments/ass1/submission/18307130172/6.sql similarity index 100% rename from assignments/ass1/18307130172/6.sql rename to assignments/ass1/submission/18307130172/6.sql diff --git a/assignments/ass1/18307130172/7.sql b/assignments/ass1/submission/18307130172/7.sql similarity index 100% rename from assignments/ass1/18307130172/7.sql rename to assignments/ass1/submission/18307130172/7.sql diff --git a/assignments/ass1/18307130172/8.sql b/assignments/ass1/submission/18307130172/8.sql similarity index 100% rename from assignments/ass1/18307130172/8.sql rename to assignments/ass1/submission/18307130172/8.sql diff --git a/assignments/ass1/18307130172/create_table.sql b/assignments/ass1/submission/18307130172/create_table.sql similarity index 100% rename from assignments/ass1/18307130172/create_table.sql rename to assignments/ass1/submission/18307130172/create_table.sql diff --git a/assignments/ass1/18307130297/1.sql b/assignments/ass1/submission/18307130297/1.sql similarity index 100% rename from assignments/ass1/18307130297/1.sql rename to assignments/ass1/submission/18307130297/1.sql diff --git a/assignments/ass1/18307130297/2.sql b/assignments/ass1/submission/18307130297/2.sql similarity index 100% rename from assignments/ass1/18307130297/2.sql rename to assignments/ass1/submission/18307130297/2.sql diff --git a/assignments/ass1/18307130297/3.sql b/assignments/ass1/submission/18307130297/3.sql similarity index 100% rename from assignments/ass1/18307130297/3.sql rename to assignments/ass1/submission/18307130297/3.sql diff --git a/assignments/ass1/18307130297/4.sql b/assignments/ass1/submission/18307130297/4.sql similarity index 100% rename from assignments/ass1/18307130297/4.sql rename to assignments/ass1/submission/18307130297/4.sql diff --git a/assignments/ass1/18307130297/5.sql b/assignments/ass1/submission/18307130297/5.sql similarity index 100% rename from assignments/ass1/18307130297/5.sql rename to assignments/ass1/submission/18307130297/5.sql diff --git a/assignments/ass1/18307130297/6.sql b/assignments/ass1/submission/18307130297/6.sql similarity index 100% rename from assignments/ass1/18307130297/6.sql rename to assignments/ass1/submission/18307130297/6.sql diff --git a/assignments/ass1/18307130297/7.sql b/assignments/ass1/submission/18307130297/7.sql similarity index 100% rename from assignments/ass1/18307130297/7.sql rename to assignments/ass1/submission/18307130297/7.sql diff --git a/assignments/ass1/18307130297/8.sql b/assignments/ass1/submission/18307130297/8.sql similarity index 100% rename from assignments/ass1/18307130297/8.sql rename to assignments/ass1/submission/18307130297/8.sql diff --git a/assignments/ass1/18307130297/create_table.sql b/assignments/ass1/submission/18307130297/create_table.sql similarity index 100% rename from assignments/ass1/18307130297/create_table.sql rename to assignments/ass1/submission/18307130297/create_table.sql From 3fe4a6ea241c5c2ad1d63922d8ef4df36e94781d Mon Sep 17 00:00:00 2001 From: xudinghuan <18307130031@fudan.edu.cn> Date: Thu, 19 Mar 2020 20:59:18 -0700 Subject: [PATCH 071/189] 18307130031 for ass1 --- .../submission/18307130031/insert_data.sql | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 assignments/ass1/submission/18307130031/insert_data.sql diff --git a/assignments/ass1/submission/18307130031/insert_data.sql b/assignments/ass1/submission/18307130031/insert_data.sql deleted file mode 100644 index 4c70fb8..0000000 --- a/assignments/ass1/submission/18307130031/insert_data.sql +++ /dev/null @@ -1,34 +0,0 @@ -INSERT INTO employee (id, name, office, age) VALUES - (1, 'Jones', 'CA', 30), - (2, 'Alice', 'SJ', 33), - (3, 'Bob', 'NY', 29), - (4, 'Jack', 'CN', 50); - -INSERT INTO book (id, name, author, publisher) VALUES - (1, 'T1', 'A1', 'McGraw-Hill'), - (2, 'T1', 'A1', 'McGraw-Hill'), - (3, 'T2', 'A2', 'McGraw-Hill'), - (4, 'T2', 'A2', 'McGraw-Hill'), - (5, 'T3', 'A3', 'McGraw-Hill'), - (6, 'T3', 'A3', 'McGraw-Hill'), - (11, 'T4', 'A4', 'Fudan'), - (12, 'T4', 'A4', 'Fudan'), - (13, 'T5', 'A5', 'Fudan'), - (14, 'T6', 'A6', 'Fudan'), - (15, 'T7', 'A7', 'Fudan'), - (16, 'T8', 'A8', 'Fudan'); - -INSERT INTO record (employee_id, book_id, time) VALUES - (1, 1, '2016-3-24'), - (2, 2, '2016-3-24'), - (2, 3, '2016-3-24'), - (1, 4, '2016-3-25'), - (3, 5, '2016-3-25'), - (1, 6, '2016-3-25'), - (1, 11, '2018-4-18'), - (4, 12, '2018-4-18'), - (4, 13, '2018-4-18'), - (1, 14, '2018-4-18'), - (1, 15, '2018-4-18'), - (2, 16, '2018-4-18'), - (2, 1, '2018-3-18'); From a0bf81512090718bc3565f3b6ff233a50e35afac Mon Sep 17 00:00:00 2001 From: XuYipei <1449097870@qq.com> Date: Fri, 20 Mar 2020 13:24:36 +0800 Subject: [PATCH 072/189] submission of 18307130103 for ass1 --- assignments/ass1/submission/18307130103/1.sql | 3 +++ assignments/ass1/submission/18307130103/2.sql | 3 +++ assignments/ass1/submission/18307130103/3.sql | 4 ++++ assignments/ass1/submission/18307130103/4.sql | 4 ++++ assignments/ass1/submission/18307130103/5.sql | 4 ++++ assignments/ass1/submission/18307130103/6.sql | 6 +++++ assignments/ass1/submission/18307130103/7.sql | 5 ++++ assignments/ass1/submission/18307130103/8.sql | 9 ++++++++ .../submission/18307130103/create_table.sql | 23 +++++++++++++++++++ 9 files changed, 61 insertions(+) create mode 100644 assignments/ass1/submission/18307130103/1.sql create mode 100644 assignments/ass1/submission/18307130103/2.sql create mode 100644 assignments/ass1/submission/18307130103/3.sql create mode 100644 assignments/ass1/submission/18307130103/4.sql create mode 100644 assignments/ass1/submission/18307130103/5.sql create mode 100644 assignments/ass1/submission/18307130103/6.sql create mode 100644 assignments/ass1/submission/18307130103/7.sql create mode 100644 assignments/ass1/submission/18307130103/8.sql create mode 100644 assignments/ass1/submission/18307130103/create_table.sql diff --git a/assignments/ass1/submission/18307130103/1.sql b/assignments/ass1/submission/18307130103/1.sql new file mode 100644 index 0000000..44e39dc --- /dev/null +++ b/assignments/ass1/submission/18307130103/1.sql @@ -0,0 +1,3 @@ +SELECT * + FROM employee + WHERE employee.name='Jones'; diff --git a/assignments/ass1/submission/18307130103/2.sql b/assignments/ass1/submission/18307130103/2.sql new file mode 100644 index 0000000..40a5f05 --- /dev/null +++ b/assignments/ass1/submission/18307130103/2.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT employee.name + FROM employee + WHERE employee.id=1 OR employee.id=2; diff --git a/assignments/ass1/submission/18307130103/3.sql b/assignments/ass1/submission/18307130103/3.sql new file mode 100644 index 0000000..df2c298 --- /dev/null +++ b/assignments/ass1/submission/18307130103/3.sql @@ -0,0 +1,4 @@ +select employee.name + from employee + where employee.id<>1 + order by employee.id; diff --git a/assignments/ass1/submission/18307130103/4.sql b/assignments/ass1/submission/18307130103/4.sql new file mode 100644 index 0000000..361a140 --- /dev/null +++ b/assignments/ass1/submission/18307130103/4.sql @@ -0,0 +1,4 @@ +select employee.name + from employee + where 25<=employee.age and employee.age<=30 + order by employee.id; diff --git a/assignments/ass1/submission/18307130103/5.sql b/assignments/ass1/submission/18307130103/5.sql new file mode 100644 index 0000000..e213ef8 --- /dev/null +++ b/assignments/ass1/submission/18307130103/5.sql @@ -0,0 +1,4 @@ +select * + from employee + where employee.name like 'J%' + order by employee.age; diff --git a/assignments/ass1/submission/18307130103/6.sql b/assignments/ass1/submission/18307130103/6.sql new file mode 100644 index 0000000..c85b517 --- /dev/null +++ b/assignments/ass1/submission/18307130103/6.sql @@ -0,0 +1,6 @@ +select distinct X.publisher + from book as X + where 2<=(select count(*) + from book as Y + where X.publisher=Y.publisher) + order by X.publisher; diff --git a/assignments/ass1/submission/18307130103/7.sql b/assignments/ass1/submission/18307130103/7.sql new file mode 100644 index 0000000..7a01a39 --- /dev/null +++ b/assignments/ass1/submission/18307130103/7.sql @@ -0,0 +1,5 @@ +select employee.name + from employee,record + where record.time>'2016-10-31' and record.employee_id=employee.id + group by employee.name + order by max(employee.id); diff --git a/assignments/ass1/submission/18307130103/8.sql b/assignments/ass1/submission/18307130103/8.sql new file mode 100644 index 0000000..63f826e --- /dev/null +++ b/assignments/ass1/submission/18307130103/8.sql @@ -0,0 +1,9 @@ +select B.id,B.name,A.num +from (select record.employee_id,count(*) as num + from record + group by record.employee_id + having count(*)>1) as A + inner join + employee as B + on A.employee_id=B.id +order by num desc; diff --git a/assignments/ass1/submission/18307130103/create_table.sql b/assignments/ass1/submission/18307130103/create_table.sql new file mode 100644 index 0000000..3bffcf3 --- /dev/null +++ b/assignments/ass1/submission/18307130103/create_table.sql @@ -0,0 +1,23 @@ +CREATE TABLE employee( + id INT, + office CHAR(32), + name CHAR(32), + age INTEGER, + PRIMARY KEY (id) +); + +CREATE TABLE book( + id INT, + name CHAR(32), + author CHAR(32), + publisher CHAR(32), + PRIMARY KEY (id) +); + +CREATE TABLE record( + time DATE, + book_id INT, + employee_id INT, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id) +); From 3507a6e58c0f79ce1e7c55b58698453d4d0777c6 Mon Sep 17 00:00:00 2001 From: 18307130266-wangxinyi <18307130266@fudan.edu.cn> Date: Fri, 20 Mar 2020 16:02:49 +0800 Subject: [PATCH 073/189] submission of 18307130266 for ass1 --- assignments/ass1/submission/18307130266/1.sql | 3 +++ assignments/ass1/submission/18307130266/2.sql | 3 +++ assignments/ass1/submission/18307130266/3.sql | 3 +++ assignments/ass1/submission/18307130266/4.sql | 4 ++++ assignments/ass1/submission/18307130266/5.sql | 4 ++++ assignments/ass1/submission/18307130266/6.sql | 3 +++ assignments/ass1/submission/18307130266/7.sql | 4 ++++ assignments/ass1/submission/18307130266/8.sql | 7 ++++++ .../submission/18307130266/create_table.sql | 23 +++++++++++++++++++ 9 files changed, 54 insertions(+) create mode 100644 assignments/ass1/submission/18307130266/1.sql create mode 100644 assignments/ass1/submission/18307130266/2.sql create mode 100644 assignments/ass1/submission/18307130266/3.sql create mode 100644 assignments/ass1/submission/18307130266/4.sql create mode 100644 assignments/ass1/submission/18307130266/5.sql create mode 100644 assignments/ass1/submission/18307130266/6.sql create mode 100644 assignments/ass1/submission/18307130266/7.sql create mode 100644 assignments/ass1/submission/18307130266/8.sql create mode 100644 assignments/ass1/submission/18307130266/create_table.sql diff --git a/assignments/ass1/submission/18307130266/1.sql b/assignments/ass1/submission/18307130266/1.sql new file mode 100644 index 0000000..c11140a --- /dev/null +++ b/assignments/ass1/submission/18307130266/1.sql @@ -0,0 +1,3 @@ +select * +from employee +where name='Jones'; diff --git a/assignments/ass1/submission/18307130266/2.sql b/assignments/ass1/submission/18307130266/2.sql new file mode 100644 index 0000000..ce6b908 --- /dev/null +++ b/assignments/ass1/submission/18307130266/2.sql @@ -0,0 +1,3 @@ +select name +from employee +where id between 1 and 2; diff --git a/assignments/ass1/submission/18307130266/3.sql b/assignments/ass1/submission/18307130266/3.sql new file mode 100644 index 0000000..88f5ab9 --- /dev/null +++ b/assignments/ass1/submission/18307130266/3.sql @@ -0,0 +1,3 @@ +select name +from employee +where id!=1; diff --git a/assignments/ass1/submission/18307130266/4.sql b/assignments/ass1/submission/18307130266/4.sql new file mode 100644 index 0000000..c491265 --- /dev/null +++ b/assignments/ass1/submission/18307130266/4.sql @@ -0,0 +1,4 @@ +select name +from employee +where age between 25 and 30 +order by id; diff --git a/assignments/ass1/submission/18307130266/5.sql b/assignments/ass1/submission/18307130266/5.sql new file mode 100644 index 0000000..c2e8784 --- /dev/null +++ b/assignments/ass1/submission/18307130266/5.sql @@ -0,0 +1,4 @@ +select * +from employee +where name like 'J%' +order by age; diff --git a/assignments/ass1/submission/18307130266/6.sql b/assignments/ass1/submission/18307130266/6.sql new file mode 100644 index 0000000..c58b81e --- /dev/null +++ b/assignments/ass1/submission/18307130266/6.sql @@ -0,0 +1,3 @@ +select distinct publisher +from book +order by publisher; diff --git a/assignments/ass1/submission/18307130266/7.sql b/assignments/ass1/submission/18307130266/7.sql new file mode 100644 index 0000000..2f0b911 --- /dev/null +++ b/assignments/ass1/submission/18307130266/7.sql @@ -0,0 +1,4 @@ +select distinct book_id +from record +where time>'2016-10-31' +order by book_id; diff --git a/assignments/ass1/submission/18307130266/8.sql b/assignments/ass1/submission/18307130266/8.sql new file mode 100644 index 0000000..8b3b0c5 --- /dev/null +++ b/assignments/ass1/submission/18307130266/8.sql @@ -0,0 +1,7 @@ +select id,name,count(book_id) as num +from employee,record +where employee.id=record.employee_id +group by id +having num>1 +order by num desc; + diff --git a/assignments/ass1/submission/18307130266/create_table.sql b/assignments/ass1/submission/18307130266/create_table.sql new file mode 100644 index 0000000..6f98a00 --- /dev/null +++ b/assignments/ass1/submission/18307130266/create_table.sql @@ -0,0 +1,23 @@ +create table employee( + id int not null, + name varchar(32), + office varchar(32), + age int(8), + primary key(id) +); + +create table book( + id int not null, + name varchar(32), + author varchar(32), + publisher varchar(32), + primary key(id) +); + +create table record( + book_id int not null, + employee_id int not null, + time date, + foreign key(book_id) references book(id), + foreign key(employee_id) references employee(id) +); From 1584c29b0c606ec4383acbec7f40e765aad0044b Mon Sep 17 00:00:00 2001 From: 105gun Date: Fri, 20 Mar 2020 17:57:00 +0800 Subject: [PATCH 074/189] submission of 18300200009 for ass1 --- assignments/ass1/submission/18300200009/1.sql | 3 +++ assignments/ass1/submission/18300200009/2.sql | 3 +++ assignments/ass1/submission/18300200009/3.sql | 4 +++ assignments/ass1/submission/18300200009/4.sql | 4 +++ assignments/ass1/submission/18300200009/5.sql | 4 +++ assignments/ass1/submission/18300200009/6.sql | 3 +++ assignments/ass1/submission/18300200009/7.sql | 4 +++ assignments/ass1/submission/18300200009/8.sql | 6 +++++ .../submission/18300200009/create_table.sql | 25 +++++++++++++++++++ 9 files changed, 56 insertions(+) create mode 100644 assignments/ass1/submission/18300200009/1.sql create mode 100644 assignments/ass1/submission/18300200009/2.sql create mode 100644 assignments/ass1/submission/18300200009/3.sql create mode 100644 assignments/ass1/submission/18300200009/4.sql create mode 100644 assignments/ass1/submission/18300200009/5.sql create mode 100644 assignments/ass1/submission/18300200009/6.sql create mode 100644 assignments/ass1/submission/18300200009/7.sql create mode 100644 assignments/ass1/submission/18300200009/8.sql create mode 100644 assignments/ass1/submission/18300200009/create_table.sql diff --git a/assignments/ass1/submission/18300200009/1.sql b/assignments/ass1/submission/18300200009/1.sql new file mode 100644 index 0000000..459ec56 --- /dev/null +++ b/assignments/ass1/submission/18300200009/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name='Jones'; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/2.sql b/assignments/ass1/submission/18300200009/2.sql new file mode 100644 index 0000000..59d60b1 --- /dev/null +++ b/assignments/ass1/submission/18300200009/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id=1 OR id=2; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/3.sql b/assignments/ass1/submission/18300200009/3.sql new file mode 100644 index 0000000..2656945 --- /dev/null +++ b/assignments/ass1/submission/18300200009/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id!=1 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/4.sql b/assignments/ass1/submission/18300200009/4.sql new file mode 100644 index 0000000..1bf4a4b --- /dev/null +++ b/assignments/ass1/submission/18300200009/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age>=25 AND age<=30 +ORDER BY id; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/5.sql b/assignments/ass1/submission/18300200009/5.sql new file mode 100644 index 0000000..03088b7 --- /dev/null +++ b/assignments/ass1/submission/18300200009/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name LIKE 'J%' +ORDER BY age; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/6.sql b/assignments/ass1/submission/18300200009/6.sql new file mode 100644 index 0000000..534975f --- /dev/null +++ b/assignments/ass1/submission/18300200009/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/7.sql b/assignments/ass1/submission/18300200009/7.sql new file mode 100644 index 0000000..27220e9 --- /dev/null +++ b/assignments/ass1/submission/18300200009/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT book_id +FROM record +WHERE time > 2016-10-31 +ORDER BY book_id; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/8.sql b/assignments/ass1/submission/18300200009/8.sql new file mode 100644 index 0000000..03960db --- /dev/null +++ b/assignments/ass1/submission/18300200009/8.sql @@ -0,0 +1,6 @@ +SELECT id,name,count(book_id) AS num +FROM record,employee +WHERE id=employee_id +GROUP BY id + HAVING count(book_id)>1 +ORDER BY num; \ No newline at end of file diff --git a/assignments/ass1/submission/18300200009/create_table.sql b/assignments/ass1/submission/18300200009/create_table.sql new file mode 100644 index 0000000..3646053 --- /dev/null +++ b/assignments/ass1/submission/18300200009/create_table.sql @@ -0,0 +1,25 @@ +CREATE TABLE employee( + id INT NOT NULL, + name VARCHAR(32), + office VARCHAR(32), + age INT, + PRIMARY KEY(id), + CHECK (id>=0 AND id<=100) +); +CREATE TABLE book( + id INT NOT NULL, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32), + PRIMARY KEY(id) +); +CREATE TABLE record( + book_id INT NOT NULL, + employee_id INT NOT NULL, + time DATE, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id) +); + + + From 96d01c883df15eb3c38ee253905492ad2496b5ab Mon Sep 17 00:00:00 2001 From: 18307130163-fuerzheng <18307130163@fudan.edu.cn> Date: Fri, 20 Mar 2020 03:00:23 -0700 Subject: [PATCH 075/189] submission of 18307130163 for ass1 --- assignments/ass1/submission/18307130163/1.sql | 3 +++ assignments/ass1/submission/18307130163/2.sql | 3 +++ assignments/ass1/submission/18307130163/3.sql | 4 +++ assignments/ass1/submission/18307130163/4.sql | 4 +++ assignments/ass1/submission/18307130163/5.sql | 4 +++ assignments/ass1/submission/18307130163/6.sql | 3 +++ assignments/ass1/submission/18307130163/7.sql | 4 +++ assignments/ass1/submission/18307130163/8.sql | 6 +++++ .../submission/18307130163/create_table.sql | 26 +++++++++++++++++++ 9 files changed, 57 insertions(+) create mode 100644 assignments/ass1/submission/18307130163/1.sql create mode 100644 assignments/ass1/submission/18307130163/2.sql create mode 100644 assignments/ass1/submission/18307130163/3.sql create mode 100644 assignments/ass1/submission/18307130163/4.sql create mode 100644 assignments/ass1/submission/18307130163/5.sql create mode 100644 assignments/ass1/submission/18307130163/6.sql create mode 100644 assignments/ass1/submission/18307130163/7.sql create mode 100644 assignments/ass1/submission/18307130163/8.sql create mode 100644 assignments/ass1/submission/18307130163/create_table.sql diff --git a/assignments/ass1/submission/18307130163/1.sql b/assignments/ass1/submission/18307130163/1.sql new file mode 100644 index 0000000..3063bc3 --- /dev/null +++ b/assignments/ass1/submission/18307130163/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name = 'Jones'; diff --git a/assignments/ass1/submission/18307130163/2.sql b/assignments/ass1/submission/18307130163/2.sql new file mode 100644 index 0000000..4e71013 --- /dev/null +++ b/assignments/ass1/submission/18307130163/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id IN (1, 2); diff --git a/assignments/ass1/submission/18307130163/3.sql b/assignments/ass1/submission/18307130163/3.sql new file mode 100644 index 0000000..cb1eb58 --- /dev/null +++ b/assignments/ass1/submission/18307130163/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id != 1 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130163/4.sql b/assignments/ass1/submission/18307130163/4.sql new file mode 100644 index 0000000..62cc442 --- /dev/null +++ b/assignments/ass1/submission/18307130163/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age BETWEEN 25 AND 30 +ORDER BY id; diff --git a/assignments/ass1/submission/18307130163/5.sql b/assignments/ass1/submission/18307130163/5.sql new file mode 100644 index 0000000..b8a1f33 --- /dev/null +++ b/assignments/ass1/submission/18307130163/5.sql @@ -0,0 +1,4 @@ +SELECT * +FROM employee +WHERE name LIKE 'J%' +ORDER BY age; diff --git a/assignments/ass1/submission/18307130163/6.sql b/assignments/ass1/submission/18307130163/6.sql new file mode 100644 index 0000000..79f4172 --- /dev/null +++ b/assignments/ass1/submission/18307130163/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher; diff --git a/assignments/ass1/submission/18307130163/7.sql b/assignments/ass1/submission/18307130163/7.sql new file mode 100644 index 0000000..dc09a6f --- /dev/null +++ b/assignments/ass1/submission/18307130163/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT id +FROM book, record +WHERE id = book_id AND time > '2016-10-31' +ORDER BY id; diff --git a/assignments/ass1/submission/18307130163/8.sql b/assignments/ass1/submission/18307130163/8.sql new file mode 100644 index 0000000..2f75605 --- /dev/null +++ b/assignments/ass1/submission/18307130163/8.sql @@ -0,0 +1,6 @@ +SELECT id, name, COUNT(*) AS num +FROM employee, record +WHERE id = employee_id +GROUP BY id +HAVING num > 1 +ORDER BY num DESC; diff --git a/assignments/ass1/submission/18307130163/create_table.sql b/assignments/ass1/submission/18307130163/create_table.sql new file mode 100644 index 0000000..1c0a537 --- /dev/null +++ b/assignments/ass1/submission/18307130163/create_table.sql @@ -0,0 +1,26 @@ +use ass1; + +create table employee( + id int primary key, + name varchar(32), + office varchar(32), + age int +); + +create table book( + id int primary key, + name varchar(32), + author varchar(32), + publisher varchar(32) +); + +create table record( + book_id int, + employee_id int, + time date, + primary key (book_id, employee_id), + foreign key (book_id) + references book (id), + foreign key (employee_id) + references employee (id) +); From c3360cc66ffd014525a828f4a44818574da512a1 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 20 Mar 2020 11:52:10 +0800 Subject: [PATCH 076/189] update gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d4777df..2ebe8e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -assignments/evaluator +evaluator/ docs/ From bcf7b14815cc185b40d660d3477d1cef8970f399 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 20 Mar 2020 22:16:17 +0800 Subject: [PATCH 077/189] update ass2 --- assignments/ass2/submission/.gitignore | 4 + content/assignment2/readme.md | 110 +++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 assignments/ass2/submission/.gitignore create mode 100644 content/assignment2/readme.md diff --git a/assignments/ass2/submission/.gitignore b/assignments/ass2/submission/.gitignore new file mode 100644 index 0000000..f1eff2e --- /dev/null +++ b/assignments/ass2/submission/.gitignore @@ -0,0 +1,4 @@ +/* +!.gitignore +!/*/ +!/*/utils.go diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md new file mode 100644 index 0000000..eb7f2f0 --- /dev/null +++ b/content/assignment2/readme.md @@ -0,0 +1,110 @@ +# Assignment 2, Evaluator + +In the first assignment, you have written several SQLs to help you build basic experience playing with MySQL, in this assignment you are going to continue the journey, but this time, you will use a programming language to interact with MySQL, namely, golang. + +Golang, developed by Google, is a statically typed programming langauge (we'll refer to golang as Go in the following content). It is becomming more and more popular in the recent several years, companies like bilibili[^1] [^3] and zhihu[^2] and so many more are using Go to build the backend of their applications. And the idea of cloud native and microservice are built almost on top of Go, just to name a few softwares in Go, docker, kubernetes, and TiDB are built using Go. So it is very desirable and meaningful to start to learn this language. + +[^1]: https://github.com/bilibili/kratos +[^2]: https://zhuanlan.zhihu.com/p/48039838 +[^3]: https://www.bilibili.com/video/av29079011/ + +Go is also very simple, it is built with simplicity in mind, as long as you know how to write C code, it won't be hard +to learn Go. However, Go does introduce many ideas that perhaps you are not familiar with, most the the ideas are +related to concurrency, such as `channel` and `goroutine`, we will be using these features extensively in the course, +since database systems are built to allow (or welcome) concurrent accesses, and Go has a good fame of being a +concurrency friendly programing language. + +You might be frightened that you need to learn a new programming language, but it is a must for a good programmer to be +fluent in many programming languages, and it won't be too hard given you already know at least one programming +language. To make your learning experience less painful, follow the instructions below to learn it. + +* [Install Go compiler and setup the environment](https://golang.org/doc/install), we will be using the latest Go version, 1.14. +* Join [the tour of Go](https://tour.golang.org/), walk through the whole tutorial, and come back often when you have + problems writing Go in the future. This is an excellent tutorial, and your TA also learned Go from here. It would take at least 2 + days for you to fully understand the tutorial, so start early. Also, try some of the examples on your local machine, + which will help you better understand the toolchain of Go. Note, the most important thing for you to learn is the + concurrency part, you need to understand goroutine (kind of like a light-weighted thread) and `sync.Mutex`, since you + will need it in this assignment. As for the syntax of Go, it is quite similar with C, so do not worry, you could just + skim this part and come back when you need it. +* Read the provided code and make sure your understand every line of the code. If you don't, check the tutorial again. + And if you are still confused, do not hesitate to ask questions in the comment bellow. +* Try to use GoLand for development, it provides the best Go development environment, and it is free for educational + purpose. + +## Setup + +To setup the environment for this assignment, you have the following steps to finish. + +### Update Your Cloned Git Repository + +Your local repository only have your own code, in order to get the content for this assignment, you need to fetch data +from GitHub. Use the following command: + +```bash +$ git remote add upstream xxx # add your TA's repository to the romote +$ git fetch upstream # this command fetches the update in your TA's repository, it would take a while +$ git merge upstream/master # merge the updates into your master, you can also do `git rebase upstream/master` if you used another branch other than master previously for assignment 1 +``` + +### Copy Provided Code to Your Working Directory + +The code provided is under `assignments/ass2/evaluator/`. Similarly you have to create your working directory under +`assignments/ass2/submission/` + +Suppose your current directory is the root of the repository. + +```bash +$ mkdir assignments/ass2/submission/YOURSTUDENTID # put your student id here +$ cp assignments/ass2/evaluator/* assignments/ass2/submission/YOURSTUDENTID/ # copy provided code into your working directory +``` + +You can only modify the files in your own working directory, any attempts to modify files outside your working directory +will make your submission invalid. + +Especially, only `utils.go` in your working directory will be considered in this assginment (other files will be ignored, see +`assignments/ass2/submission/.gitignore`). With this said, you could actually modify other provided files like +`main.go` if it helps you with understanding the code or debugging your own code, but your modification will not be +considered when we evaluate your submission, and you should make sure your code in `utils.go` can work with the original +codebase. + +### Create a New Branch for Development + +It is your TA's fault that he didn't tell you this in assignment 1. It would be better that you don't work on the master +branch, because that will make the git history messy. Create a new branch and develop your code in the new branch, you +could name the branch `ass2`. + +``` +$ git checkout -b ass2 # create and checkout to a new branch ass2 +$ git add . && git commit -m "update from upstream, start ass2" # commit your modification (only `utils.go` will be tracked) and start working +``` + +### Modify Configuration + +Now edit `utils.go`, in the first `YOUR CODE` block, put your student id in `EvaluateID`, `../../../ass1/submission/` +for `SubmissionDir`, and the user name and password to connect your MySQL server. + + +## Concurrent Comparision Result Insert + + + +The single thread version provided in the provided code takes almost 1 minutes on your TA's laptop to insert 7200 +records in the the database. This is too slow! The QPS (query per second) is about 7200 / 60 = 120. + +Make it concurrent and improve the QPS. + +## Evaluate the Score + +We evaluate the submission using the following rule. For each SQL file you write, there will be a score of 0 or 1. + +For table creation, the rule is, if the table can be created and the `insert_data.sql` could successfully insert data, +then the score is 1, otherwise the score will be 0. The evaluation is already done in the provided code. + +For the rest 8 queries, we take a voting approach. For each of the query, we compare every submission's query result +against each other, and if the result is the same, the submission will earn 1 point. For example, when we are evaluating +the submission of `18307130154` on query `1`, we take all submission's result on query `1`, and compare the result of the submission of `18307130154` against +them (including the submission `18307130154` itself), and the count of equal result will be the vote of `18307130154`. +And if submission `18307130154` has the highest vote on query `1`, the score will be 1, otherwise the score is 0. + +## Get the Score + From baa70b55e0fb164609ff9a1063da75c7093d1335 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 20 Mar 2020 22:32:14 +0800 Subject: [PATCH 078/189] update mkdocs --- content/assignment2/readme.md | 18 ++++++++++++++++++ content/index.md | 4 +++- mkdocs.yml | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index eb7f2f0..6524f75 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -83,6 +83,24 @@ $ git add . && git commit -m "update from upstream, start ass2" # commit your mo Now edit `utils.go`, in the first `YOUR CODE` block, put your student id in `EvaluateID`, `../../../ass1/submission/` for `SubmissionDir`, and the user name and password to connect your MySQL server. +You could then run + +```bash +$ go run main.go utils.go +``` + +at your working directory, you should see + +```text +submission created +``` + +in the output if the configuration is correct. You could ignore the printed error message above, these messages are for you to know if there +are any problems with the submissions of assignment 1. They are only relevant if you found your solution for assignment 1 is not compliant with +the evaluator, then these error messages tell you why. + +If you want to argue about your submission for assignment 1, create another pull request with your modified submission for assignment 1 (only modify files in your working directory for assignment 1) and explain why you think you +deserve a higher score in the pull request, mistakes like creating tables using all UPPERCASE names sound like possible to have a second chance. ## Concurrent Comparision Result Insert diff --git a/content/index.md b/content/index.md index e2a51a4..10460a3 100644 --- a/content/index.md +++ b/content/index.md @@ -18,7 +18,9 @@ This course is an introductory course to database systems. In this course, you w |Week No.|Date|Content|Additional Materials| |--------|----|-------|-------------------| |3|2020-03-13|Assignment 1 Released

|| -|4|2020-03-20|
Assignment 1 Due|| +|4|2020-03-20|Assignment 1 Due
Assignment 2 Released

|| +|5|2020-03-27||| +|6|2020-04-03|
Assignment 2 Due|| ## Assignment Guidance diff --git a/mkdocs.yml b/mkdocs.yml index e86711a..646e8fd 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -72,3 +72,5 @@ nav: - Welcome: index.md - Assignment 1: - Instruction: assignment1/readme.md + - Assignment 2: + - Instruction: assignment2/readme.md From 47f1fb63c08f86517ded1a114ec3158278ac2247 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Sat, 21 Mar 2020 08:34:12 +0800 Subject: [PATCH 079/189] add evaluator --- .gitignore | 1 - assignments/ass2/evaluator/go.mod | 8 + assignments/ass2/evaluator/go.sum | 7 + assignments/ass2/evaluator/main.go | 244 ++++++++++++++++++++++++++++ assignments/ass2/evaluator/utils.go | 67 ++++++++ content/assignment2/readme.md | 110 +++++++++++-- 6 files changed, 420 insertions(+), 17 deletions(-) create mode 100644 assignments/ass2/evaluator/go.mod create mode 100644 assignments/ass2/evaluator/go.sum create mode 100644 assignments/ass2/evaluator/main.go create mode 100644 assignments/ass2/evaluator/utils.go diff --git a/.gitignore b/.gitignore index 2ebe8e5..77f12ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -evaluator/ docs/ diff --git a/assignments/ass2/evaluator/go.mod b/assignments/ass2/evaluator/go.mod new file mode 100644 index 0000000..a6f77f7 --- /dev/null +++ b/assignments/ass2/evaluator/go.mod @@ -0,0 +1,8 @@ +module github.com/ichn-hu/IDBS-Spring20-Fudan/assignments/evaluator + +go 1.14 + +require ( + github.com/go-sql-driver/mysql v1.5.0 + github.com/jmoiron/sqlx v1.2.0 +) diff --git a/assignments/ass2/evaluator/go.sum b/assignments/ass2/evaluator/go.sum new file mode 100644 index 0000000..5c23552 --- /dev/null +++ b/assignments/ass2/evaluator/go.sum @@ -0,0 +1,7 @@ +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= +github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= diff --git a/assignments/ass2/evaluator/main.go b/assignments/ass2/evaluator/main.go new file mode 100644 index 0000000..0bebb97 --- /dev/null +++ b/assignments/ass2/evaluator/main.go @@ -0,0 +1,244 @@ +package main + +import ( + "fmt" + "io/ioutil" + "path/filepath" + "reflect" + "strings" + "sync" + "time" + + _ "github.com/go-sql-driver/mysql" // this is the driver for mysql + sql "github.com/jmoiron/sqlx" // this is the connector, both package are external packages that you need to use `go install` to install before use +) + +const ( + NumSQL = 8 +) + +type Submission struct { + db *sql.DB + submitter string + workingDir string + score []int + sqls []string + sqlResults [][]map[string]interface{} +} + +func mustExecute(db *sql.DB, SQLs []string) { + for _, s := range SQLs { + _, err := db.Exec(s) + if err != nil { + panic(err) + } + } +} + +func newSubmission(submitter string) (sub *Submission, err error) { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/", User, Password)) + if err != nil { + return + } + sub = &Submission{ + db: db, + submitter: submitter, + workingDir: filepath.Join(SubmissionDir, submitter), + score: make([]int, NumSQL + 1), + sqls: make([]string, NumSQL), + sqlResults: make([][]map[string]interface{}, NumSQL), + } + mustExecute(db, []string{ + fmt.Sprintf("DROP DATABASE IF EXISTS ass1_%s", submitter), + fmt.Sprintf("CREATE DATABASE ass1_%s", submitter), + fmt.Sprintf("USE ass1_%s", submitter), + }) + return +} + +func executeSQLsFromFile(filePath string, db *sql.DB) error { + binData, err := ioutil.ReadFile(filePath) + if err != nil { + return err + } + SQLs := string(binData) + for _, s := range strings.Split(SQLs, ";") { + if len(strings.TrimSpace(s)) == 0 { + continue + } + _, err := db.Exec(s) + if err != nil { + return err + } + } + return nil +} + +func (sub *Submission) close() { + _, _ = sub.db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS ass1_%s", sub.submitter)) +} + +func (sub *Submission) testCreateTable() { + var err error + err = executeSQLsFromFile(filepath.Join(sub.workingDir, "create_table.sql"), sub.db) + if err != nil || executeSQLsFromFile(filepath.Join(sub.workingDir, "../../insert_data.sql"), sub.db) != nil { + if err == nil { + err = executeSQLsFromFile(filepath.Join(sub.workingDir, "../../insert_data.sql"), sub.db) + } + fmt.Println(sub.submitter, " ", 0, " ", err) + tmp, _ := newSubmission(sub.submitter) + *sub = *tmp + err = executeSQLsFromFile(filepath.Join(sub.workingDir, "../../create_table.sql"), sub.db) + if err != nil { + panic(err) + } + err = executeSQLsFromFile(filepath.Join(sub.workingDir, "../../insert_data.sql"), sub.db) + if err != nil { + panic(err) + } + sub.score[0] = 0 + } else { + sub.score[0] = 1 + } +} + +func createSubmissions() map[string]*Submission { + dirs, err := ioutil.ReadDir(SubmissionDir) + if err != nil { + panic(err) + } + subs := make(map[string]*Submission) + wg := sync.WaitGroup{} + for _, di := range dirs { + if di.IsDir() { + sub, err := newSubmission(di.Name()) + if err == nil { + subs[di.Name()] = sub + wg.Add(1) + go func() { + sub.testCreateTable() + sub.querySQLs() + sub.close() + wg.Done() + }() + } else { + fmt.Println(err) + } + } + } + wg.Wait() + fmt.Println("submission created") + return subs +} + +func (sub *Submission) querySQLs() { + for i := 0; i < NumSQL; i++ { + file := filepath.Join(sub.workingDir, fmt.Sprintf("%d.sql", i+1)) + binData, err := ioutil.ReadFile(file) + if err == nil { + sub.sqls[i] = string(binData) + s := string(binData) + rows, err := sub.db.Queryx(s) + if err == nil { + results := make([]map[string]interface{}, 0) + for rows.Next() { + dest := make(map[string]interface{}) + _ = rows.MapScan(dest) + results = append(results, dest) + } + sub.sqlResults[i] = results + } else { + fmt.Println(sub.submitter, " ", i + 1, " ", err) + } + } else { + fmt.Println(sub.submitter, " ", i + 1, " ", err) + } + } +} + +func compareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + fmt.Println("CompareAndInsert takes ", time.Since(start)) + }() + + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + } +} + +func insertComparisonResult(subs map[string]*Submission) { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/", User, Password)) + if err != nil { + panic(err) + } + mustExecute(db, []string{ + fmt.Sprintf("DROP DATABASE IF EXISTS ass1_result_evaluated_by_%s", EvaluatorID), + fmt.Sprintf("CREATE DATABASE ass1_result_evaluated_by_%s", EvaluatorID), + fmt.Sprintf("USE ass1_result_evaluated_by_%s", EvaluatorID), + "CREATE TABLE comparision_result (submitter CHAR(11), comparer CHAR(11), item INT, is_equal INT)", + }) + ConcurrentCompareAndInsert(subs) + // uncomment the following line to see how slow the single-thread insert is + // compareAndInsert(subs) +} + + +func createScoreTable(subs map[string]*Submission) { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + mustExecute(db, []string{ + "CREATE TABLE score (submitter CHAR(11), item int, score int, vote int)", + GetScoreSQL(), + }) + rows, err := db.Query("SELECT COUNT(*) FROM score") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("GetScoreSQL Not Implemented") + } + fmt.Printf("GetScoreSQL inserted %d records into score\n", cnt) + + GetScore(db, subs) + for _, sub := range subs { + fmt.Print(sub.submitter, " ", sub.score[0]) + for i := 1; i <= NumSQL; i++ { + fmt.Print(" ", sub.score[i]) + } + fmt.Println() + } +} + +func main() { + subs := createSubmissions() + insertComparisonResult(subs) + createScoreTable(subs) +} diff --git a/assignments/ass2/evaluator/utils.go b/assignments/ass2/evaluator/utils.go new file mode 100644 index 0000000..c2da626 --- /dev/null +++ b/assignments/ass2/evaluator/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + "sync" + "reflect" + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparision_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} + diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index 6524f75..ac8e3b9 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -2,15 +2,15 @@ In the first assignment, you have written several SQLs to help you build basic experience playing with MySQL, in this assignment you are going to continue the journey, but this time, you will use a programming language to interact with MySQL, namely, golang. -Golang, developed by Google, is a statically typed programming langauge (we'll refer to golang as Go in the following content). It is becomming more and more popular in the recent several years, companies like bilibili[^1] [^3] and zhihu[^2] and so many more are using Go to build the backend of their applications. And the idea of cloud native and microservice are built almost on top of Go, just to name a few softwares in Go, docker, kubernetes, and TiDB are built using Go. So it is very desirable and meaningful to start to learn this language. +Golang, developed by Google, is a statically typed programming langauge (we'll refer to golang as Go in the following content). It is becomming more and more popular in the recent several years, companies like bilibili[^1] [^3] and zhihu[^2] and so many more are using Go to build the backend of their applications. And the idea of cloud native and microservice are built almost on top of Go, just to name a few softwares in Go, docker, kubernetes, and TiDB (a distributed database compatible with MySQL, we probabily will also play with it in the future). So it is very desirable and meaningful to start to learn this language. [^1]: https://github.com/bilibili/kratos [^2]: https://zhuanlan.zhihu.com/p/48039838 [^3]: https://www.bilibili.com/video/av29079011/ Go is also very simple, it is built with simplicity in mind, as long as you know how to write C code, it won't be hard -to learn Go. However, Go does introduce many ideas that perhaps you are not familiar with, most the the ideas are -related to concurrency, such as `channel` and `goroutine`, we will be using these features extensively in the course, +to learn Go. However, Go does introduce many ideas that perhaps you are not familiar with, most of the the ideas are +related to concurrency, such as `channel` and `goroutine`, we will be using these features extensively in the assignments, since database systems are built to allow (or welcome) concurrent accesses, and Go has a good fame of being a concurrency friendly programing language. @@ -28,8 +28,8 @@ language. To make your learning experience less painful, follow the instructions skim this part and come back when you need it. * Read the provided code and make sure your understand every line of the code. If you don't, check the tutorial again. And if you are still confused, do not hesitate to ask questions in the comment bellow. -* Try to use GoLand for development, it provides the best Go development environment, and it is free for educational - purpose. +* Try to use GoLand for development, it provides the best Go development environment in your TA's opinion, and it is free for educational + purpose. You could connect GoLand with your MySQL server and GoLand will be able to help you write your SQL. ## Setup @@ -38,7 +38,7 @@ To setup the environment for this assignment, you have the following steps to fi ### Update Your Cloned Git Repository Your local repository only have your own code, in order to get the content for this assignment, you need to fetch data -from GitHub. Use the following command: +from GitHub. Use the following commands: ```bash $ git remote add upstream xxx # add your TA's repository to the romote @@ -67,6 +67,8 @@ Especially, only `utils.go` in your working directory will be considered in this considered when we evaluate your submission, and you should make sure your code in `utils.go` can work with the original codebase. +You should generally only put your code between `YOUR CODE BEGIN` and `YOUR CODE END`. The evaluation of assignment 2 will be based on the three functions you filled in in `utils.go`. + ### Create a New Branch for Development It is your TA's fault that he didn't tell you this in assignment 1. It would be better that you don't work on the master @@ -95,34 +97,110 @@ at your working directory, you should see submission created ``` -in the output if the configuration is correct. You could ignore the printed error message above, these messages are for you to know if there +in the output if the configuration is correct. If you did not see this line, check the error message and search online, and try to fix it. + +You could ignore the printed error message above this line, these messages are for you to know if there are any problems with the submissions of assignment 1. They are only relevant if you found your solution for assignment 1 is not compliant with the evaluator, then these error messages tell you why. If you want to argue about your submission for assignment 1, create another pull request with your modified submission for assignment 1 (only modify files in your working directory for assignment 1) and explain why you think you deserve a higher score in the pull request, mistakes like creating tables using all UPPERCASE names sound like possible to have a second chance. +Each submission created will have an integer array `score`, and `score[0]` is 0 if the submission's `create_table.sql` is wrong, otherwise it will be 1. `score[1]` to `score[8]` stands for the score for query 1 to query 8 in assignment 1, and they are obtained in the following manner. + ## Concurrent Comparision Result Insert +Take a look at `compareAndInsert`, which compares each submissions with all the submissions on each query, and insert a record for the comparison in the table `comparison_result`. +The problem of this function is that it is single-threaded. As you might know, access database is IO-bounded, the CPU might wait for a lot of time for the response of the database, so it makes sense to make the insert concurrent so that the CPU could get more busy and making the insert faster. The single thread version provided in the provided code takes almost 1 minutes on your TA's laptop to insert 7200 records in the the database. This is too slow! The QPS (query per second) is about 7200 / 60 = 120. -Make it concurrent and improve the QPS. +With the help of goroutine, it can be easily made concurrent, so please make it concurrent and improve the QPS in `ConcurrentCompareAndInsert`. As a reference, it takes less than 4 seconds with your TA's simple concurrent version, a speed up of 15x. + +You could also do batch insert, which could be even faster, but you won't be able to play with concurrency. If you are interested, you could write a `CompareAndBatchedInsert` function in `utils.go` and test how faster it could be, however this part is unrated. + +Also as a reference, your kind TA provided you a concurrent `createSubmissions` in `main.go`, take a look if you don't know how to start. + +Also as a kind note, `sql.DB` is not thread-safe, you need multiple `sql.DB` if you want concurrent access of the database, and figuring out (by search it online) what is closure, and how to pass variable to a closure might be helpful. + +Run + +```bash +$ go run main.go utils.go +``` + +again, and you will see + +```text +ConcurrentCompareAndInsert takes xxxs +``` + +instead of + +```text +ConcurrentCompareAndInsert Not Implemented +``` ## Evaluate the Score -We evaluate the submission using the following rule. For each SQL file you write, there will be a score of 0 or 1. +Once you get all the comparision result, it is time to get the score for each submission on each query. + +We evaluate the submission using the following rule. In `comparision_result`, for each query, each +submission has record of `is_equal` to every submissions, and the sum of `is_equal` is the vote of +the submission for the query, if the submission has the highest vote, i.e. most of submissions agreed with this submission's result on the query, the score of the submission on this query will be 1, otherwise 0. + +You need to use **a single query** to insert the score result in the table `score` created in `createScoreTable`, where `submitter` is the ID of the submitter of the submission, item ranges from 1 to 8 and stands for each query, score being 0 or 1 means the score of `submitter` on query `item`, and `vote` is the vote mentioned above for sanity check. + +You need to finish `GetScoreSQL` in `utils.go`, which only returns a single string containing the query sent to MySQL that reads from `comparision_result` and inserts into `score`. -For table creation, the rule is, if the table can be created and the `insert_data.sql` could successfully insert data, -then the score is 1, otherwise the score will be 0. The evaluation is already done in the provided code. +This query can be rather complex and challenging, here are some hints that might be helpful -For the rest 8 queries, we take a voting approach. For each of the query, we compare every submission's query result -against each other, and if the result is the same, the submission will earn 1 point. For example, when we are evaluating -the submission of `18307130154` on query `1`, we take all submission's result on query `1`, and compare the result of the submission of `18307130154` against -them (including the submission `18307130154` itself), and the count of equal result will be the vote of `18307130154`. -And if submission `18307130154` has the highest vote on query `1`, the score will be 1, otherwise the score is 0. +* UNION is a good wait to combine result of multiple queries +* Common Table Expression (CTE) can be helpful if you want to reuse the result of a subquery +* `order by` can be used with multiple column +* You can insert with values replaced by a select query +* Window functions might be helpful, check it out if you are interested, but you can finish this query without using it + +You are free to hack around using any features of MySQL you want (version 8.0), there are many possible ways, as long as you can make it with the `GetScoreSQL` function, you will get the score. + +Run + +```bash +$ go run main.go utils.go +``` + +again, and you will see + +```text +GetScoreSQL inserted xxx records into score +``` + +instead of + +```text +GetScoreSQL Not Implemented +``` ## Get the Score +Finally, you need to fill in each submission's `score` (i.e. `Submission.score`) with the data in table `score`. Finish `GetScore` and you will get output like + +```text +... +18307130252 1 1 1 1 1 1 1 1 0 +18300200015 1 1 1 1 1 1 1 1 0 +18307130031 1 1 1 1 1 1 1 0 1 +18307130112 1 1 1 1 1 1 0 1 0 +... +``` + +if you run `go run main.go utils.go`. + +## Submit your solution + +As you have done for assignment 1, commit your change for `utils.go` and create a pull request to submit it. + +Also do not look at other's submission before your submission get merged. + From f4582f6b981070a9adee3c41941791a7e88bfdb3 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Sat, 21 Mar 2020 08:35:40 +0800 Subject: [PATCH 080/189] add 1 --- assignments/ass2/submission/.gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/assignments/ass2/submission/.gitignore b/assignments/ass2/submission/.gitignore index f1eff2e..82e30a3 100644 --- a/assignments/ass2/submission/.gitignore +++ b/assignments/ass2/submission/.gitignore @@ -1,4 +1,3 @@ /* !.gitignore -!/*/ !/*/utils.go From 7832ab7e5e544108cddc977c3856a80276fcaf09 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Sat, 21 Mar 2020 08:46:52 +0800 Subject: [PATCH 081/189] update evaluator --- assignments/ass2/evaluator/utils.go | 2 ++ assignments/ass2/submission/.gitignore | 2 ++ 2 files changed, 4 insertions(+) diff --git a/assignments/ass2/evaluator/utils.go b/assignments/ass2/evaluator/utils.go index c2da626..a689bff 100644 --- a/assignments/ass2/evaluator/utils.go +++ b/assignments/ass2/evaluator/utils.go @@ -3,8 +3,10 @@ package main import ( "fmt" "time" + // YOUR CODE BEGIN remove the follow packages if you don't need them "sync" "reflect" + // YOUR CODE END _ "github.com/go-sql-driver/mysql" sql "github.com/jmoiron/sqlx" diff --git a/assignments/ass2/submission/.gitignore b/assignments/ass2/submission/.gitignore index 82e30a3..026b520 100644 --- a/assignments/ass2/submission/.gitignore +++ b/assignments/ass2/submission/.gitignore @@ -1,3 +1,5 @@ /* !.gitignore +!/*/ +/*/* !/*/utils.go From a2dec423ea812bcd9a3584149aa0353c2a7d1167 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Sat, 21 Mar 2020 10:17:36 +0800 Subject: [PATCH 082/189] fin ass2 --- assignments/ass2/evaluator/go.mod | 2 +- assignments/ass2/evaluator/main.go | 15 +++++++-------- assignments/ass2/evaluator/utils.go | 18 ++++++++---------- content/assignment2/readme.md | 25 +++++++++++++++++-------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/assignments/ass2/evaluator/go.mod b/assignments/ass2/evaluator/go.mod index a6f77f7..785608f 100644 --- a/assignments/ass2/evaluator/go.mod +++ b/assignments/ass2/evaluator/go.mod @@ -1,4 +1,4 @@ -module github.com/ichn-hu/IDBS-Spring20-Fudan/assignments/evaluator +module github.com/ichn-hu/IDBS-Spring20-Fudan/assignments/ass2/evaluator go 1.14 diff --git a/assignments/ass2/evaluator/main.go b/assignments/ass2/evaluator/main.go index 0bebb97..9d9af93 100644 --- a/assignments/ass2/evaluator/main.go +++ b/assignments/ass2/evaluator/main.go @@ -10,11 +10,11 @@ import ( "time" _ "github.com/go-sql-driver/mysql" // this is the driver for mysql - sql "github.com/jmoiron/sqlx" // this is the connector, both package are external packages that you need to use `go install` to install before use + sql "github.com/jmoiron/sqlx" // this is the connector, both package are external packages that you need to use `go install` to install before use ) const ( - NumSQL = 8 + NumSQL = 8 ) type Submission struct { @@ -44,7 +44,7 @@ func newSubmission(submitter string) (sub *Submission, err error) { db: db, submitter: submitter, workingDir: filepath.Join(SubmissionDir, submitter), - score: make([]int, NumSQL + 1), + score: make([]int, NumSQL+1), sqls: make([]string, NumSQL), sqlResults: make([][]map[string]interface{}, NumSQL), } @@ -148,10 +148,10 @@ func (sub *Submission) querySQLs() { } sub.sqlResults[i] = results } else { - fmt.Println(sub.submitter, " ", i + 1, " ", err) + fmt.Println(sub.submitter, " ", i+1, " ", err) } } else { - fmt.Println(sub.submitter, " ", i + 1, " ", err) + fmt.Println(sub.submitter, " ", i+1, " ", err) } } } @@ -175,7 +175,7 @@ func compareAndInsert(subs map[string]*Submission) { } else { equal = 0 } - s := fmt.Sprintf("INSERT INTO result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) _, err := db.Exec(s) if err != nil { fmt.Println(s) @@ -195,14 +195,13 @@ func insertComparisonResult(subs map[string]*Submission) { fmt.Sprintf("DROP DATABASE IF EXISTS ass1_result_evaluated_by_%s", EvaluatorID), fmt.Sprintf("CREATE DATABASE ass1_result_evaluated_by_%s", EvaluatorID), fmt.Sprintf("USE ass1_result_evaluated_by_%s", EvaluatorID), - "CREATE TABLE comparision_result (submitter CHAR(11), comparer CHAR(11), item INT, is_equal INT)", + "CREATE TABLE comparison_result (submitter CHAR(11), comparer CHAR(11), item INT, is_equal INT)", }) ConcurrentCompareAndInsert(subs) // uncomment the following line to see how slow the single-thread insert is // compareAndInsert(subs) } - func createScoreTable(subs map[string]*Submission) { db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) if err != nil { diff --git a/assignments/ass2/evaluator/utils.go b/assignments/ass2/evaluator/utils.go index a689bff..7b8b5b9 100644 --- a/assignments/ass2/evaluator/utils.go +++ b/assignments/ass2/evaluator/utils.go @@ -3,10 +3,10 @@ package main import ( "fmt" "time" - // YOUR CODE BEGIN remove the follow packages if you don't need them - "sync" - "reflect" - // YOUR CODE END + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END _ "github.com/go-sql-driver/mysql" sql "github.com/jmoiron/sqlx" @@ -14,10 +14,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 + EvaluatorID = "" // your student id, e.g. 18307130177 SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -29,7 +29,7 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { if err != nil { panic(nil) } - rows, err := db.Query("SELECT COUNT(*) FROM comparision_result") + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") if err != nil { panic(err) } @@ -49,7 +49,6 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { // YOUR CODE END } - // GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table // `comparision_result` and inserts the score of each submitter on each query into table `score` func GetScoreSQL() string { @@ -66,4 +65,3 @@ func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE END } - diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index ac8e3b9..9d28131 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -2,17 +2,17 @@ In the first assignment, you have written several SQLs to help you build basic experience playing with MySQL, in this assignment you are going to continue the journey, but this time, you will use a programming language to interact with MySQL, namely, golang. -Golang, developed by Google, is a statically typed programming langauge (we'll refer to golang as Go in the following content). It is becomming more and more popular in the recent several years, companies like bilibili[^1] [^3] and zhihu[^2] and so many more are using Go to build the backend of their applications. And the idea of cloud native and microservice are built almost on top of Go, just to name a few softwares in Go, docker, kubernetes, and TiDB (a distributed database compatible with MySQL, we probabily will also play with it in the future). So it is very desirable and meaningful to start to learn this language. +Golang, developed by Google, is a statically typed programming language (we'll refer to golang as Go in the following content). It is becoming more and more popular in the recent several years, companies like bilibili[^1] [^3] and zhihu[^2] and so many more are using Go to build the backend of their applications. And the idea of cloud native and microservice are built almost on top of Go, just to name a few softwares in Go, docker, kubernetes, and TiDB (a distributed database compatible with MySQL, we probably will also play with it in the future). So it is very desirable and meaningful to start to learn this language. [^1]: https://github.com/bilibili/kratos [^2]: https://zhuanlan.zhihu.com/p/48039838 [^3]: https://www.bilibili.com/video/av29079011/ Go is also very simple, it is built with simplicity in mind, as long as you know how to write C code, it won't be hard -to learn Go. However, Go does introduce many ideas that perhaps you are not familiar with, most of the the ideas are +to learn Go. However, Go does introduce many ideas that perhaps you are not familiar with, most of the ideas are related to concurrency, such as `channel` and `goroutine`, we will be using these features extensively in the assignments, since database systems are built to allow (or welcome) concurrent accesses, and Go has a good fame of being a -concurrency friendly programing language. +concurrency friendly programming language. You might be frightened that you need to learn a new programming language, but it is a must for a good programmer to be fluent in many programming languages, and it won't be too hard given you already know at least one programming @@ -61,7 +61,7 @@ $ cp assignments/ass2/evaluator/* assignments/ass2/submission/YOURSTUDENTID/ # c You can only modify the files in your own working directory, any attempts to modify files outside your working directory will make your submission invalid. -Especially, only `utils.go` in your working directory will be considered in this assginment (other files will be ignored, see +Especially, only `utils.go` in your working directory will be considered in this assignment (other files will be ignored, see `assignments/ass2/submission/.gitignore`). With this said, you could actually modify other provided files like `main.go` if it helps you with understanding the code or debugging your own code, but your modification will not be considered when we evaluate your submission, and you should make sure your code in `utils.go` can work with the original @@ -69,6 +69,8 @@ codebase. You should generally only put your code between `YOUR CODE BEGIN` and `YOUR CODE END`. The evaluation of assignment 2 will be based on the three functions you filled in in `utils.go`. +As for the packages, you can not introduce any other external packages (the `go.mod` file will be ignored for your submission, even if you do, we will not be able to run it). You are free to use other internal packages, as a reference the TA's solution only uses `sync` and `reflect`. + ### Create a New Branch for Development It is your TA's fault that he didn't tell you this in assignment 1. It would be better that you don't work on the master @@ -108,14 +110,14 @@ deserve a higher score in the pull request, mistakes like creating tables using Each submission created will have an integer array `score`, and `score[0]` is 0 if the submission's `create_table.sql` is wrong, otherwise it will be 1. `score[1]` to `score[8]` stands for the score for query 1 to query 8 in assignment 1, and they are obtained in the following manner. -## Concurrent Comparision Result Insert +## Concurrent Comparison Result Insert Take a look at `compareAndInsert`, which compares each submissions with all the submissions on each query, and insert a record for the comparison in the table `comparison_result`. The problem of this function is that it is single-threaded. As you might know, access database is IO-bounded, the CPU might wait for a lot of time for the response of the database, so it makes sense to make the insert concurrent so that the CPU could get more busy and making the insert faster. The single thread version provided in the provided code takes almost 1 minutes on your TA's laptop to insert 7200 -records in the the database. This is too slow! The QPS (query per second) is about 7200 / 60 = 120. +records in the database. This is too slow! The QPS (query per second) is about 7200 / 60 = 120. With the help of goroutine, it can be easily made concurrent, so please make it concurrent and improve the QPS in `ConcurrentCompareAndInsert`. As a reference, it takes less than 4 seconds with your TA's simple concurrent version, a speed up of 15x. @@ -145,7 +147,7 @@ ConcurrentCompareAndInsert Not Implemented ## Evaluate the Score -Once you get all the comparision result, it is time to get the score for each submission on each query. +Once you get all the comparison result, it is time to get the score for each submission on each query. We evaluate the submission using the following rule. In `comparision_result`, for each query, each submission has record of `is_equal` to every submissions, and the sum of `is_equal` is the vote of @@ -185,7 +187,7 @@ GetScoreSQL Not Implemented ## Get the Score -Finally, you need to fill in each submission's `score` (i.e. `Submission.score`) with the data in table `score`. Finish `GetScore` and you will get output like +Finally, you need to fill in each submission's `score` (i.e. `Submission.score`) with the data in table `score`. Finish `GetScore` and read score from table `score` and you will get output like ```text ... @@ -202,5 +204,12 @@ if you run `go run main.go utils.go`. As you have done for assignment 1, commit your change for `utils.go` and create a pull request to submit it. +Since you used another branch (`ass2` as your TA told you above), do the following to push your code to your +repository + +```bash +$ git push --set-upstream origin ass2 +``` + Also do not look at other's submission before your submission get merged. From 74f7412dcf78a4b2880f2a1ced88c68f56412737 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Sat, 21 Mar 2020 10:54:52 +0800 Subject: [PATCH 083/189] fix typo --- content/assignment2/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index 9d28131..ecf3f31 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -149,13 +149,13 @@ ConcurrentCompareAndInsert Not Implemented Once you get all the comparison result, it is time to get the score for each submission on each query. -We evaluate the submission using the following rule. In `comparision_result`, for each query, each +We evaluate the submission using the following rule. In `comparison_result`, for each query, each submission has record of `is_equal` to every submissions, and the sum of `is_equal` is the vote of the submission for the query, if the submission has the highest vote, i.e. most of submissions agreed with this submission's result on the query, the score of the submission on this query will be 1, otherwise 0. You need to use **a single query** to insert the score result in the table `score` created in `createScoreTable`, where `submitter` is the ID of the submitter of the submission, item ranges from 1 to 8 and stands for each query, score being 0 or 1 means the score of `submitter` on query `item`, and `vote` is the vote mentioned above for sanity check. -You need to finish `GetScoreSQL` in `utils.go`, which only returns a single string containing the query sent to MySQL that reads from `comparision_result` and inserts into `score`. +You need to finish `GetScoreSQL` in `utils.go`, which only returns a single string containing the query sent to MySQL that reads from `comparison_result` and inserts into `score`. This query can be rather complex and challenging, here are some hints that might be helpful From 27013c52273a1769f5d4bc3378defe727a84c2c5 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Sat, 21 Mar 2020 11:00:00 +0800 Subject: [PATCH 084/189] update from upstream, start ass2 --- .../ass2/submission/18307130024/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130024/utils.go diff --git a/assignments/ass2/submission/18307130024/utils.go b/assignments/ass2/submission/18307130024/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130024/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 38cb61fdb57d6132a4c3afe9224259474b30d947 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Sat, 21 Mar 2020 11:29:48 +0800 Subject: [PATCH 085/189] add sample output --- content/assignment2/readme.md | 129 ++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index ecf3f31..a9fd218 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -153,6 +153,8 @@ We evaluate the submission using the following rule. In `comparison_result`, for submission has record of `is_equal` to every submissions, and the sum of `is_equal` is the vote of the submission for the query, if the submission has the highest vote, i.e. most of submissions agreed with this submission's result on the query, the score of the submission on this query will be 1, otherwise 0. +Look at the [output bellow in hints](#hints) if you are still not sure how the rule works. + You need to use **a single query** to insert the score result in the table `score` created in `createScoreTable`, where `submitter` is the ID of the submitter of the submission, item ranges from 1 to 8 and stands for each query, score being 0 or 1 means the score of `submitter` on query `item`, and `vote` is the vote mentioned above for sanity check. You need to finish `GetScoreSQL` in `utils.go`, which only returns a single string containing the query sent to MySQL that reads from `comparison_result` and inserts into `score`. @@ -200,6 +202,133 @@ Finally, you need to fill in each submission's `score` (i.e. `Submission.score`) if you run `go run main.go utils.go`. +## Hints + +The sample output from your TA is + +??? note "sample output" + ```text + ╰─$ go run main.go utils.go + 18307130154 0 Error 1146: Table 'ass1_18307130154.employee' doesn't exist + 18307130163 0 Error 1049: Unknown database 'ass1' + 19307130296 0 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE book( + id int(32) not null auto_increment primary key, + name var' at line 8 + 18307130071 1 Error 1054: Unknown column 'jones' in 'where clause' + 18307130071 2 Error 1146: Table 'ass1_18307130071.empolyee' doesn't exist + 18307130071 7 Error 1630: FUNCTION time.AFTER does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual + 18307130071 8 Error 1054: Unknown column 'id' in 'field list' + 18307130102 7 Error 1305: FUNCTION ass1_18307130102.to_date does not exist + 19307130296 7 Error 1054: Unknown column 'id' in 'order clause' + 19307130296 8 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * + FROM record + WHERE record.employee_id=employee.id + ) AS num>1 + ORD' at line 5 + 18307130213 0 Error 1146: Table 'ass1_18307130213.employee' doesn't exist + 18307130297 7 Error 1054: Unknown column 'id' in 'field list' + 18307130252 8 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') + on employee.id = X.id + where X.num > 1 + order by X.num desc' at line 4 + 18307130213 1 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 2 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 3 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 4 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 5 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 6 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist + 18307130213 7 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist + 18307130252 8 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') + on employee.id = X.id + where X.num > 1 + order by X.num desc' at line 4 + 18307130213 1 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 2 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 3 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 4 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 5 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + 18307130213 6 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist + 18307130213 7 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist + 18307130213 8 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist + submission created + ConcurrentCompareAndInsert takes 4.491039717s + GetScoreSQL inserted 264 records into score + 18307130017 1 1 1 1 1 1 1 1 0 + 18307130122 1 1 1 1 1 1 1 1 0 + 18307130213 0 0 0 0 0 0 0 0 0 + 18300750006 1 1 1 1 1 1 1 1 1 + 19307130296 0 1 1 1 1 0 1 0 0 + 18307130024 1 1 1 1 1 1 1 1 1 + 18307130027 1 1 1 1 1 0 1 1 1 + 18307130102 1 1 1 1 1 1 1 0 1 + 18307130103 1 1 1 1 1 1 1 0 1 + 18307130112 1 1 1 1 1 1 0 1 0 + 18307130154 0 1 1 1 1 1 1 0 1 + 18307130297 1 1 1 1 1 1 1 0 0 + 15307130201 1 1 1 1 1 1 1 1 1 + 18307130128 1 1 1 1 1 1 1 1 0 + 18307130252 1 1 1 1 1 1 1 1 0 + 18307130266 1 1 1 1 1 1 1 1 1 + 18307130003 1 1 1 1 1 1 1 1 1 + 18307130182 1 1 1 1 1 1 1 1 1 + 19300290059 1 1 1 1 1 1 0 1 1 + 18307130071 1 0 0 0 0 1 0 0 0 + 18300200015 1 1 1 1 1 1 1 1 0 + 18307130031 1 1 1 1 1 1 1 0 1 + 18307130090 1 1 1 1 1 1 1 0 0 + 18307130116 1 1 1 1 1 1 1 0 0 + 18307130126 1 1 1 1 1 1 1 1 1 + 18307130172 1 1 1 1 1 1 1 0 1 + 18307130341 1 1 1 1 1 1 1 1 1 + 18300200009 1 1 1 1 1 1 1 0 0 + 18307130104 1 1 1 1 1 1 1 0 1 + 18307130123 1 1 1 1 1 1 1 1 1 + 18307130163 0 1 1 1 1 1 1 0 1 + 18307130340 1 1 1 1 1 1 1 1 1 + 18300200012 1 1 1 1 1 1 1 0 1 + ``` + +And some sample from table `score` + +??? note "sample from `score`" + ```text + ass1_result_evaluated_by_16307130177> select * from score limit 30; + +-------------+------+-------+------+ + | submitter | item | score | vote | + +-------------+------+-------+------+ + | 15307130201 | 1 | 1 | 31 | + | 15307130201 | 2 | 1 | 31 | + | 15307130201 | 3 | 1 | 31 | + | 15307130201 | 4 | 1 | 31 | + | 15307130201 | 5 | 1 | 30 | + | 15307130201 | 6 | 1 | 29 | + | 15307130201 | 7 | 1 | 18 | + | 15307130201 | 8 | 1 | 20 | + | 18300200009 | 1 | 1 | 31 | + | 18300200009 | 2 | 1 | 31 | + | 18300200009 | 3 | 1 | 31 | + | 18300200009 | 4 | 1 | 31 | + | 18300200009 | 5 | 1 | 30 | + | 18300200009 | 6 | 1 | 29 | + | 18300200009 | 7 | 0 | 2 | + | 18300200009 | 8 | 0 | 4 | + | 18300200012 | 1 | 1 | 31 | + | 18300200012 | 2 | 1 | 31 | + | 18300200012 | 3 | 1 | 31 | + | 18300200012 | 4 | 1 | 31 | + | 18300200012 | 5 | 1 | 30 | + | 18300200012 | 6 | 1 | 29 | + | 18300200012 | 7 | 0 | 5 | + | 18300200012 | 8 | 1 | 20 | + | 18300200015 | 1 | 1 | 31 | + | 18300200015 | 2 | 1 | 31 | + | 18300200015 | 3 | 1 | 31 | + | 18300200015 | 4 | 1 | 31 | + | 18300200015 | 5 | 1 | 30 | + | 18300200015 | 6 | 1 | 29 | + +-------------+------+-------+------+ + ``` + ## Submit your solution As you have done for assignment 1, commit your change for `utils.go` and create a pull request to submit it. From 4771997bb4c90bf9cec459a4a496e962e6c02fb5 Mon Sep 17 00:00:00 2001 From: Serena-cell <18307130367@fudan.edu.cn> Date: Sat, 21 Mar 2020 14:39:32 +0800 Subject: [PATCH 086/189] submission of 18307130367 for ass1 --- assignments/ass1/submission/18307130367/1.sql | 5 +++++ assignments/ass1/submission/18307130367/2.sql | 5 +++++ assignments/ass1/submission/18307130367/3.sql | 7 +++++++ assignments/ass1/submission/18307130367/4.sql | 7 +++++++ assignments/ass1/submission/18307130367/5.sql | 7 +++++++ assignments/ass1/submission/18307130367/6.sql | 5 +++++ assignments/ass1/submission/18307130367/7.sql | 13 ++++++++++++ assignments/ass1/submission/18307130367/8.sql | 9 ++++++++ .../submission/18307130367/create_table.sql | 21 +++++++++++++++++++ 9 files changed, 79 insertions(+) create mode 100644 assignments/ass1/submission/18307130367/1.sql create mode 100644 assignments/ass1/submission/18307130367/2.sql create mode 100644 assignments/ass1/submission/18307130367/3.sql create mode 100644 assignments/ass1/submission/18307130367/4.sql create mode 100644 assignments/ass1/submission/18307130367/5.sql create mode 100644 assignments/ass1/submission/18307130367/6.sql create mode 100644 assignments/ass1/submission/18307130367/7.sql create mode 100644 assignments/ass1/submission/18307130367/8.sql create mode 100644 assignments/ass1/submission/18307130367/create_table.sql diff --git a/assignments/ass1/submission/18307130367/1.sql b/assignments/ass1/submission/18307130367/1.sql new file mode 100644 index 0000000..f6808fc --- /dev/null +++ b/assignments/ass1/submission/18307130367/1.sql @@ -0,0 +1,5 @@ +SELECT * + +FROM employee + +WHERE name='Jones'; diff --git a/assignments/ass1/submission/18307130367/2.sql b/assignments/ass1/submission/18307130367/2.sql new file mode 100644 index 0000000..9d7f25b --- /dev/null +++ b/assignments/ass1/submission/18307130367/2.sql @@ -0,0 +1,5 @@ +select * + +from employee + +where id=1 or id=2; diff --git a/assignments/ass1/submission/18307130367/3.sql b/assignments/ass1/submission/18307130367/3.sql new file mode 100644 index 0000000..2754c6e --- /dev/null +++ b/assignments/ass1/submission/18307130367/3.sql @@ -0,0 +1,7 @@ +select name + +from employee + +where id<>1; + +order by id diff --git a/assignments/ass1/submission/18307130367/4.sql b/assignments/ass1/submission/18307130367/4.sql new file mode 100644 index 0000000..d7b4b8a --- /dev/null +++ b/assignments/ass1/submission/18307130367/4.sql @@ -0,0 +1,7 @@ +select name,id + +from employee + +where age between 25 and 30; + +order by id diff --git a/assignments/ass1/submission/18307130367/5.sql b/assignments/ass1/submission/18307130367/5.sql new file mode 100644 index 0000000..8d86595 --- /dev/null +++ b/assignments/ass1/submission/18307130367/5.sql @@ -0,0 +1,7 @@ +select * + +from employee + +where name like 'J%'; + +order by age diff --git a/assignments/ass1/submission/18307130367/6.sql b/assignments/ass1/submission/18307130367/6.sql new file mode 100644 index 0000000..bca0591 --- /dev/null +++ b/assignments/ass1/submission/18307130367/6.sql @@ -0,0 +1,5 @@ +select distinct publisher + +from book + +order by publisher diff --git a/assignments/ass1/submission/18307130367/7.sql b/assignments/ass1/submission/18307130367/7.sql new file mode 100644 index 0000000..b1e07f1 --- /dev/null +++ b/assignments/ass1/submission/18307130367/7.sql @@ -0,0 +1,13 @@ +select id + +from book + +where id in(select book_id + +from record + +where time>2016-10-31 + +); + +order by id diff --git a/assignments/ass1/submission/18307130367/8.sql b/assignments/ass1/submission/18307130367/8.sql new file mode 100644 index 0000000..490c400 --- /dev/null +++ b/assignments/ass1/submission/18307130367/8.sql @@ -0,0 +1,9 @@ +select id,name,count(*) as num + +from employee join record on employee.id=record.employee_id + +group by id + + having num>1 + +order by num DESC; diff --git a/assignments/ass1/submission/18307130367/create_table.sql b/assignments/ass1/submission/18307130367/create_table.sql new file mode 100644 index 0000000..9921d9c --- /dev/null +++ b/assignments/ass1/submission/18307130367/create_table.sql @@ -0,0 +1,21 @@ +CREATE TABLE if not exists employee + ( id int , + name CHAR(32) NOT NULL, + office CHAR(32) NOT NULL, + age INT NOT NULL CHECK(age >= 0 AND age <= 100), + primary key(id) +); + +CREATE TABLE if not exists book + ( id int not null, + name CHAR(32) NOT NULL, + author CHAR(32) NOT NULL, + publisher CHAR(32) NOT NULL, + primary key(id)); + +CREATE TABLE if not exists record + ( book_id VARCHAR(32) NOT NULL, + employee_id CHAR(32) NOT NULL, + time DATE NOT NULL, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id)); From 614329fbecb748c797015454dbd50d561992363f Mon Sep 17 00:00:00 2001 From: NoSW Date: Sat, 21 Mar 2020 01:52:13 -0700 Subject: [PATCH 087/189] update from upstream,start ass2 --- .../ass2/submission/18300200012/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18300200012/utils.go diff --git a/assignments/ass2/submission/18300200012/utils.go b/assignments/ass2/submission/18300200012/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18300200012/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 080493baf9b9f32e653bb1d83cb72942a9f64cae Mon Sep 17 00:00:00 2001 From: HatsuneHan <61576872@qq.com> Date: Sat, 21 Mar 2020 19:54:30 +0800 Subject: [PATCH 088/189] update from upstream, start ass2 --- .../ass2/submission/18300750006/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18300750006/utils.go diff --git a/assignments/ass2/submission/18300750006/utils.go b/assignments/ass2/submission/18300750006/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18300750006/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From a4bba750da5db9fbdcc876ebc4e044e571a0b7dc Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Sat, 21 Mar 2020 20:27:27 +0800 Subject: [PATCH 089/189] commit on 'ass2' --- assignments/ass2/submission/18307130024/utils.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assignments/ass2/submission/18307130024/utils.go b/assignments/ass2/submission/18307130024/utils.go index 7b8b5b9..83a086b 100644 --- a/assignments/ass2/submission/18307130024/utils.go +++ b/assignments/ass2/submission/18307130024/utils.go @@ -14,10 +14,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130024" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "xxx" // the password for the user name, e.g. xxx // YOUR CODE END ) From abe0dc45bb0e11537a151b0c4e58eb7c6ececeb0 Mon Sep 17 00:00:00 2001 From: cbshnrh <15307130192@fudan.edu.cn> Date: Sat, 21 Mar 2020 23:41:03 -0700 Subject: [PATCH 090/189] submission of 15307130192 for ass1 --- assignments/ass1/submission/15307130192/1.sql | 2 ++ assignments/ass1/submission/15307130192/2.sql | 2 ++ assignments/ass1/submission/15307130192/3.sql | 3 +++ assignments/ass1/submission/15307130192/4.sql | 3 +++ assignments/ass1/submission/15307130192/5.sql | 3 +++ assignments/ass1/submission/15307130192/6.sql | 3 +++ assignments/ass1/submission/15307130192/7.sql | 4 ++++ assignments/ass1/submission/15307130192/8.sql | 6 +++++ .../submission/15307130192/create_table.sql | 22 +++++++++++++++++++ 9 files changed, 48 insertions(+) create mode 100644 assignments/ass1/submission/15307130192/1.sql create mode 100644 assignments/ass1/submission/15307130192/2.sql create mode 100644 assignments/ass1/submission/15307130192/3.sql create mode 100644 assignments/ass1/submission/15307130192/4.sql create mode 100644 assignments/ass1/submission/15307130192/5.sql create mode 100644 assignments/ass1/submission/15307130192/6.sql create mode 100644 assignments/ass1/submission/15307130192/7.sql create mode 100644 assignments/ass1/submission/15307130192/8.sql create mode 100644 assignments/ass1/submission/15307130192/create_table.sql diff --git a/assignments/ass1/submission/15307130192/1.sql b/assignments/ass1/submission/15307130192/1.sql new file mode 100644 index 0000000..128f8d9 --- /dev/null +++ b/assignments/ass1/submission/15307130192/1.sql @@ -0,0 +1,2 @@ +select * from employee +where name = 'Jones'; diff --git a/assignments/ass1/submission/15307130192/2.sql b/assignments/ass1/submission/15307130192/2.sql new file mode 100644 index 0000000..ff8a549 --- /dev/null +++ b/assignments/ass1/submission/15307130192/2.sql @@ -0,0 +1,2 @@ +select name from employee +where id = 1 or id = 2; diff --git a/assignments/ass1/submission/15307130192/3.sql b/assignments/ass1/submission/15307130192/3.sql new file mode 100644 index 0000000..6f1b216 --- /dev/null +++ b/assignments/ass1/submission/15307130192/3.sql @@ -0,0 +1,3 @@ +select name from employee +where id != 1 +order by id asc; diff --git a/assignments/ass1/submission/15307130192/4.sql b/assignments/ass1/submission/15307130192/4.sql new file mode 100644 index 0000000..7577992 --- /dev/null +++ b/assignments/ass1/submission/15307130192/4.sql @@ -0,0 +1,3 @@ +select name from employee +where age between 25 and 30 +order by id; diff --git a/assignments/ass1/submission/15307130192/5.sql b/assignments/ass1/submission/15307130192/5.sql new file mode 100644 index 0000000..511efaa --- /dev/null +++ b/assignments/ass1/submission/15307130192/5.sql @@ -0,0 +1,3 @@ +select * from employee +where name like 'J%' +order by age diff --git a/assignments/ass1/submission/15307130192/6.sql b/assignments/ass1/submission/15307130192/6.sql new file mode 100644 index 0000000..11e7fe0 --- /dev/null +++ b/assignments/ass1/submission/15307130192/6.sql @@ -0,0 +1,3 @@ +select distinct publisher from book +order by publisher; + diff --git a/assignments/ass1/submission/15307130192/7.sql b/assignments/ass1/submission/15307130192/7.sql new file mode 100644 index 0000000..23bd92b --- /dev/null +++ b/assignments/ass1/submission/15307130192/7.sql @@ -0,0 +1,4 @@ +select distinct book_id from record +where time > '2016-10-31' +order by book_id + diff --git a/assignments/ass1/submission/15307130192/8.sql b/assignments/ass1/submission/15307130192/8.sql new file mode 100644 index 0000000..d032ec7 --- /dev/null +++ b/assignments/ass1/submission/15307130192/8.sql @@ -0,0 +1,6 @@ +select employee.id, name, count(*) as num +from record join employee +on record.employee_id = employee.id +group by employee.id + having count(*) > 1 +order by num desc diff --git a/assignments/ass1/submission/15307130192/create_table.sql b/assignments/ass1/submission/15307130192/create_table.sql new file mode 100644 index 0000000..29aae97 --- /dev/null +++ b/assignments/ass1/submission/15307130192/create_table.sql @@ -0,0 +1,22 @@ +CREATE TABLE employee( + id INT NOT NULL PRIMARY KEY, + name VARCHAR(32), + office VARCHAR(32), + age INT, + CHECK (0 < age AND age < 100) +); + +CREATE TABLE book( + id INT NOT NULL PRIMARY KEY, + name VARCHAR(32), + author VARCHAR(32), + publisher VARCHAR(32) +); + +CREATE TABLE record( + book_id INT NOT NULL, + employee_id INT NOT NULL, + time DATE, + FOREIGN KEY (book_id) REFERENCES book(id), + FOREIGN KEY (employee_id) REFERENCES employee(id) +); From a1cfa9fa63531619fe4adb279bb5a62af981ff65 Mon Sep 17 00:00:00 2001 From: Fan Date: Sun, 22 Mar 2020 19:43:30 +0800 Subject: [PATCH 091/189] update from upstream, start ass2 --- .../ass2/submission/18307130182/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130182/utils.go diff --git a/assignments/ass2/submission/18307130182/utils.go b/assignments/ass2/submission/18307130182/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130182/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 15a476336406aed1e2a0a55493a42995e14f2fe0 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Mon, 23 Mar 2020 10:30:19 +0800 Subject: [PATCH 092/189] submission of 18307130024 for ass2 --- .../ass2/submission/18307130024/utils.go | 86 +++++++++++++++++-- 1 file changed, 80 insertions(+), 6 deletions(-) diff --git a/assignments/ass2/submission/18307130024/utils.go b/assignments/ass2/submission/18307130024/utils.go index 83a086b..bffd12b 100644 --- a/assignments/ass2/submission/18307130024/utils.go +++ b/assignments/ass2/submission/18307130024/utils.go @@ -1,7 +1,10 @@ package main +import "C" import ( "fmt" + "reflect" + "sync" "time" // YOUR CODE BEGIN remove the follow packages if you don't need them @@ -14,10 +17,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "18307130024" // your student id, e.g. 18307130177 + EvaluatorID = "18307130024" // your student id, e.g. 18307130177 SubmissionDir = "../../../ass1/submission" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "root" // the user name to connect the database, e.g. root - Password = "xxx" // the password for the user name, e.g. xxx + User = "root" // the user name to connect the database, e.g. root + Password = "xxx" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -27,7 +30,7 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { defer func() { db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) if err != nil { - panic(nil) + panic(err) } rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") if err != nil { @@ -45,6 +48,35 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + wg.Add(len(subs)) + for submitter, sub := range subs { + go func(submitter string, sub *Submission) { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + wg.Done() + }(submitter, sub) + + } + wg.Wait() // YOUR CODE END } @@ -55,13 +87,55 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = `insert into score +select * +from (select A.submitter, A.item, 1 as score, count(A.item) as vote + from ass1_result_evaluated_by_18307130024.comparison_result as A + where A.is_equal = 1 + group by A.submitter, A.item + having vote >= all (select count(cr.item) as vote + from ass1_result_evaluated_by_18307130024.comparison_result as cr + where cr.is_equal = 1 + and cr.item = A.item + group by cr.submitter, cr.item + order by cr.submitter, cr.item) + order by A.submitter, A.item) as X +union + (select A.submitter, A.item, 0 as score, count(A.item) as vote + from ass1_result_evaluated_by_18307130024.comparison_result as A + where A.is_equal = 1 + group by A.submitter, A.item + having vote < some (select count(cr.item) as vote + from ass1_result_evaluated_by_18307130024.comparison_result as cr + where cr.is_equal = 1 + and cr.item = A.item + group by cr.submitter, cr.item + order by cr.submitter, cr.item) + order by A.submitter, A.item) +order by submitter, item +;` // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + for _, sub := range subs { + for i := 1; i <= NumSQL; i++ { + s := fmt.Sprintf("select score from score where submitter = %s and item = %d", sub.submitter, i) + rows, err := db.Queryx(s) + if err != nil { + panic(err) + } + for rows.Next() { + j := 0 + err := rows.Scan(&j) + if err != nil { + panic(err) + } + sub.score[i] = j + } + } + } // YOUR CODE END } From 8b65050432a6e6c9b68ec6b070d695189f665fff Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Mon, 23 Mar 2020 16:01:15 +0800 Subject: [PATCH 093/189] submission of 18307130024 for ass2 --- assignments/ass2/submission/18307130024/utils.go | 8 ++++---- content/assignment2/readme.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/assignments/ass2/submission/18307130024/utils.go b/assignments/ass2/submission/18307130024/utils.go index bffd12b..246a899 100644 --- a/assignments/ass2/submission/18307130024/utils.go +++ b/assignments/ass2/submission/18307130024/utils.go @@ -90,11 +90,11 @@ func GetScoreSQL() string { SQL = `insert into score select * from (select A.submitter, A.item, 1 as score, count(A.item) as vote - from ass1_result_evaluated_by_18307130024.comparison_result as A + from comparison_result as A where A.is_equal = 1 group by A.submitter, A.item having vote >= all (select count(cr.item) as vote - from ass1_result_evaluated_by_18307130024.comparison_result as cr + from comparison_result as cr where cr.is_equal = 1 and cr.item = A.item group by cr.submitter, cr.item @@ -102,11 +102,11 @@ from (select A.submitter, A.item, 1 as score, count(A.item) as vote order by A.submitter, A.item) as X union (select A.submitter, A.item, 0 as score, count(A.item) as vote - from ass1_result_evaluated_by_18307130024.comparison_result as A + from comparison_result as A where A.is_equal = 1 group by A.submitter, A.item having vote < some (select count(cr.item) as vote - from ass1_result_evaluated_by_18307130024.comparison_result as cr + from comparison_result as cr where cr.is_equal = 1 and cr.item = A.item group by cr.submitter, cr.item diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index a9fd218..ee1ae92 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -41,7 +41,7 @@ Your local repository only have your own code, in order to get the content for t from GitHub. Use the following commands: ```bash -$ git remote add upstream xxx # add your TA's repository to the romote +$ git remote add upstream git://github.com/ichn-hu/IDBS-Spring20-Fudan.git # add your TA's repository to the romote $ git fetch upstream # this command fetches the update in your TA's repository, it would take a while $ git merge upstream/master # merge the updates into your master, you can also do `git rebase upstream/master` if you used another branch other than master previously for assignment 1 ``` From e963ee781f1398efb1979ab51a874ef06b0b1b2e Mon Sep 17 00:00:00 2001 From: HatsuneHan <61576872@qq.com> Date: Mon, 23 Mar 2020 17:32:21 +0800 Subject: [PATCH 094/189] submission of hxy for ass2 --- .../ass2/submission/18300750006/utils.go | 83 +++++++++++++++++-- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/assignments/ass2/submission/18300750006/utils.go b/assignments/ass2/submission/18300750006/utils.go index 7b8b5b9..ae30992 100644 --- a/assignments/ass2/submission/18300750006/utils.go +++ b/assignments/ass2/submission/18300750006/utils.go @@ -3,9 +3,10 @@ package main import ( "fmt" "time" - + // YOUR CODE BEGIN remove the follow packages if you don't need them - + "reflect" + "sync" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18300750006" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "fryj5306" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,51 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + + if err != nil { + panic(err) + } + var wg sync.WaitGroup + wg.Add(len(subs)) + + for submitter, sub := range subs { + //var lock sync.Mutex + go func(submitter string , sub *Submission){ + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + + var equal int + + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + + if err != nil { + fmt.Println(s) + panic(err) + } + + //wg.Add(1) + //go func(p int){ + //lock.Lock() + //defer lock.Unlock() + //wg.Done() + //}(i) + //wg.Wait() + } + } + wg.Done() + }(submitter,sub) + + } + wg.Wait() + + // YOUR CODE END } @@ -55,6 +100,16 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL = "INSERT INTO score(submitter,item,score,vote)" + + "(SELECT A.submitter,A.item,1 AS score,vote FROM " + + "(SELECT submitter,item,SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter,item) as A " + + "WHERE vote >= all(select sum(B.is_equal) AS vote FROM comparison_result as B " + + "WHERE A.item = B.item GROUP BY B.submitter,B.item) ORDER BY A.submitter,A.item )" + + " union " + + "(SELECT C.submitter,C.item,0 AS score,vote FROM " + + "(SELECT submitter,item,SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter,item) as C " + + "WHERE vote < some(select sum(D.is_equal) AS vote FROM comparison_result as D " + + "WHERE C.item = D.item GROUP BY D.submitter,D.item) ORDER BY C.submitter,C.item) " // YOUR CODE END return SQL @@ -62,6 +117,20 @@ func GetScoreSQL() string { func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + var score int + + for _,sub := range subs { + + for i := 1; i < 9; i++ { + + errTables := db.QueryRow("SELECT score FROM score WHERE submitter = ? AND item = ?", sub.submitter,i).Scan(&score) + sub.score[i] = score + if errTables != nil { + } + + + } + } // YOUR CODE END } From 838428a92c33971018121003c094efb167ef50cb Mon Sep 17 00:00:00 2001 From: unicornt Date: Mon, 23 Mar 2020 20:49:45 +0800 Subject: [PATCH 095/189] update from upstream, start ass2 --- .../ass2/submission/18307130104/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130104/utils.go diff --git a/assignments/ass2/submission/18307130104/utils.go b/assignments/ass2/submission/18307130104/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130104/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From f32e8078d67e36cfa174c8211baf3105c7386a81 Mon Sep 17 00:00:00 2001 From: HatsuneHan <61576872@qq.com> Date: Tue, 24 Mar 2020 10:31:02 +0800 Subject: [PATCH 096/189] submission of hxy for ass2 --- assignments/ass2/submission/18300750006/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/ass2/submission/18300750006/utils.go b/assignments/ass2/submission/18300750006/utils.go index ae30992..331f3dd 100644 --- a/assignments/ass2/submission/18300750006/utils.go +++ b/assignments/ass2/submission/18300750006/utils.go @@ -18,7 +18,7 @@ var ( EvaluatorID = "18300750006" // your student id, e.g. 18307130177 SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" User = "root" // the user name to connect the database, e.g. root - Password = "fryj5306" // the password for the user name, e.g. xxx + Password = ""//omit // the password for the user name, e.g. xxx // YOUR CODE END ) From 31d43ce22f1b4a41252d340e94911ede631c44d6 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Wed, 25 Mar 2020 10:47:46 +0800 Subject: [PATCH 097/189] update upstream --- content/assignment2/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index a9fd218..2a0bfc0 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -41,7 +41,7 @@ Your local repository only have your own code, in order to get the content for t from GitHub. Use the following commands: ```bash -$ git remote add upstream xxx # add your TA's repository to the romote +$ git remote add upstream https://github.com/ichn-hu/IDBS-Spring20-Fudan.git # add your TA's repository to the romote $ git fetch upstream # this command fetches the update in your TA's repository, it would take a while $ git merge upstream/master # merge the updates into your master, you can also do `git rebase upstream/master` if you used another branch other than master previously for assignment 1 ``` From e884614ddf6947a9bcb50b33b879a439aeda9b12 Mon Sep 17 00:00:00 2001 From: flock <863813609.qq.com> Date: Thu, 26 Mar 2020 10:49:19 +0800 Subject: [PATCH 098/189] modified submission of 18307130130 for ass1 --- assignments/ass1/submission/18307130130/3.sql | 2 +- assignments/ass1/submission/18307130130/4.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assignments/ass1/submission/18307130130/3.sql b/assignments/ass1/submission/18307130130/3.sql index 3a66f20..a94fa44 100644 --- a/assignments/ass1/submission/18307130130/3.sql +++ b/assignments/ass1/submission/18307130130/3.sql @@ -1,4 +1,4 @@ SELECT name FROM employee WHERE employee.id!='1' -ORDER BY id DESC; +ORDER BY id; diff --git a/assignments/ass1/submission/18307130130/4.sql b/assignments/ass1/submission/18307130130/4.sql index 417734f..b0a5b30 100644 --- a/assignments/ass1/submission/18307130130/4.sql +++ b/assignments/ass1/submission/18307130130/4.sql @@ -1,4 +1,4 @@ SELECT name FROM employee WHERE employee.age>=25 AND age<=30 -ORDER BY id DESC; +ORDER BY id; From 734a1a8a2901c2bc4d0ba911a10ab90f17e3db82 Mon Sep 17 00:00:00 2001 From: flock <863813609.qq.com> Date: Thu, 26 Mar 2020 11:12:45 +0800 Subject: [PATCH 099/189] update from upstream, start ass2 --- .../ass2/submission/18307130130/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130130/utils.go diff --git a/assignments/ass2/submission/18307130130/utils.go b/assignments/ass2/submission/18307130130/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130130/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From c002a8d28ca5e2fdf6b95060773a926059965a6b Mon Sep 17 00:00:00 2001 From: flock <863813609.qq.com> Date: Thu, 26 Mar 2020 12:06:00 +0800 Subject: [PATCH 100/189] submission of 18307130130 for ass2 --- .../ass2/submission/18307130130/utils.go | 80 +++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/assignments/ass2/submission/18307130130/utils.go b/assignments/ass2/submission/18307130130/utils.go index 7b8b5b9..351eaac 100644 --- a/assignments/ass2/submission/18307130130/utils.go +++ b/assignments/ass2/submission/18307130130/utils.go @@ -5,19 +5,22 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" sql "github.com/jmoiron/sqlx" ) + + var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130130" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "lrc2521686" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +48,42 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + //fmt.Println("1") + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + submitter := submitter + comparer := comparer + sub := sub + sub2 := sub2 + go func(){ + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }() + } + wg.Wait() + } + //fmt.Println("2") + // YOUR CODE END } @@ -55,13 +93,39 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL = fmt.Sprintf( "INSERT INTO score (submitter,item,score,vote) "+ + "SELECT submitter,item,is_equal,RESULT.VOTE "+ + "FROM comparison_result, "+ + "(SELECT comparer as com,item as ite,COUNT(*) as VOTE "+ + "FROM comparison_result "+ + "WHERE is_equal=1 "+ + "GROUP BY comparer,item) AS RESULT WHERE comparer=%s AND comparison_result.submitter=RESULT.com AND comparison_result.item=RESULT.ite;",EvaluatorID) + // YOUR CODE END return SQL } - func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + for suber,sub := range subs{ + var s string + suber := suber + s = fmt.Sprintf("SELECT item,score FROM score WHERE submitter=%s",suber) + rows,err := db.Query(s) + if err != nil { + panic(err) + } + var value int + var flag int + for rows.Next(){ + err = rows.Scan(&flag,&value) + if err != nil { + panic(err) + } + sub.score[flag] = value + } + + } // YOUR CODE END } + From b870842c394d856e5f805c508dc0535c721d5c5e Mon Sep 17 00:00:00 2001 From: vincy233 <644255997@qq.com> Date: Thu, 26 Mar 2020 13:26:40 +0800 Subject: [PATCH 101/189] update from upstream, start ass2 --- .../ass2/submission/18307130341/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130341/utils.go diff --git a/assignments/ass2/submission/18307130341/utils.go b/assignments/ass2/submission/18307130341/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130341/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 3d3b9a9b96a8b30778f47d47a8ad73b4065f28eb Mon Sep 17 00:00:00 2001 From: YinxuanH <18307130340@fudan.edu.cn> Date: Thu, 26 Mar 2020 17:49:04 +0800 Subject: [PATCH 102/189] update from upstream, start ass2 --- .../ass2/submission/18307130340/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130340/utils.go diff --git a/assignments/ass2/submission/18307130340/utils.go b/assignments/ass2/submission/18307130340/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130340/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 86148869734a1b0f57d4eb18bec4ca5186d53b52 Mon Sep 17 00:00:00 2001 From: Pryest <495945214@qq.com> Date: Fri, 27 Mar 2020 01:24:39 -0700 Subject: [PATCH 103/189] update from upstream, start ass2 --- .../ass2/submission/18307130213/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130213/utils.go diff --git a/assignments/ass2/submission/18307130213/utils.go b/assignments/ass2/submission/18307130213/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130213/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From e365165387ae49797c6eade27bacbf352d80d7b4 Mon Sep 17 00:00:00 2001 From: Pryest <495945214@qq.com> Date: Fri, 27 Mar 2020 02:42:23 -0700 Subject: [PATCH 104/189] submission of Runyu Peng for ass1 --- assignments/ass1/submission/18307130213/1.sql | 4 +-- assignments/ass1/submission/18307130213/2.sql | 6 ++-- assignments/ass1/submission/18307130213/3.sql | 8 ++--- assignments/ass1/submission/18307130213/4.sql | 8 ++--- assignments/ass1/submission/18307130213/5.sql | 4 +-- assignments/ass1/submission/18307130213/6.sql | 6 ++-- assignments/ass1/submission/18307130213/7.sql | 8 ++--- assignments/ass1/submission/18307130213/8.sql | 12 +++---- .../submission/18307130213/create_table.sql | 32 +++++++++---------- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/assignments/ass1/submission/18307130213/1.sql b/assignments/ass1/submission/18307130213/1.sql index b3b7af1..6f073ee 100644 --- a/assignments/ass1/submission/18307130213/1.sql +++ b/assignments/ass1/submission/18307130213/1.sql @@ -1,3 +1,3 @@ SELECT * -FROM EMPLOYEE -WHERE NAME='Jones'; \ No newline at end of file +FROM employee +WHERE name='Jones'; diff --git a/assignments/ass1/submission/18307130213/2.sql b/assignments/ass1/submission/18307130213/2.sql index 5ee7f95..02b2d99 100644 --- a/assignments/ass1/submission/18307130213/2.sql +++ b/assignments/ass1/submission/18307130213/2.sql @@ -1,3 +1,3 @@ -SELECT NAME -FROM EMPLOYEE -WHERE ID=1 OR ID=2; \ No newline at end of file +SELECT name +FROM employee +WHERE id=1 OR id=2; diff --git a/assignments/ass1/submission/18307130213/3.sql b/assignments/ass1/submission/18307130213/3.sql index c2a8703..21e9699 100644 --- a/assignments/ass1/submission/18307130213/3.sql +++ b/assignments/ass1/submission/18307130213/3.sql @@ -1,4 +1,4 @@ -SELECT NAME -FROM EMPLOYEE -WHERE ID<>1 -ORDER BY ID ASC; +SELECT name +FROM employee +WHERE id<>1 +ORDER BY id ASC; diff --git a/assignments/ass1/submission/18307130213/4.sql b/assignments/ass1/submission/18307130213/4.sql index be2bee3..862f031 100644 --- a/assignments/ass1/submission/18307130213/4.sql +++ b/assignments/ass1/submission/18307130213/4.sql @@ -1,4 +1,4 @@ -SELECT NAME -FROM EMPLOYEE -WHERE AGE BETWEEN 25 AND 30 -ORDER BY ID ASC; \ No newline at end of file +SELECT name +FROM employee +WHERE age BETWEEN 25 AND 30 +ORDER BY id ASC; diff --git a/assignments/ass1/submission/18307130213/5.sql b/assignments/ass1/submission/18307130213/5.sql index 18706b6..248afdb 100644 --- a/assignments/ass1/submission/18307130213/5.sql +++ b/assignments/ass1/submission/18307130213/5.sql @@ -1,3 +1,3 @@ SELECT * -FROM EMPLOYEE -WHERE NAME LIKE 'J%'; \ No newline at end of file +FROM employee +WHERE name LIKE 'J%'; diff --git a/assignments/ass1/submission/18307130213/6.sql b/assignments/ass1/submission/18307130213/6.sql index 27b805a..79f4172 100644 --- a/assignments/ass1/submission/18307130213/6.sql +++ b/assignments/ass1/submission/18307130213/6.sql @@ -1,3 +1,3 @@ -SELECT DISTINCT PUBLISHER -FROM BOOK -ORDER BY PUBLISHER; +SELECT DISTINCT publisher +FROM book +ORDER BY publisher; diff --git a/assignments/ass1/submission/18307130213/7.sql b/assignments/ass1/submission/18307130213/7.sql index a8e3db9..d7f737b 100644 --- a/assignments/ass1/submission/18307130213/7.sql +++ b/assignments/ass1/submission/18307130213/7.sql @@ -1,4 +1,4 @@ -SELECT DISTINCT ID -FROM BOOK,RECORD -WHERE BOOK.ID = RECORD.BOOK_ID AND RECORD.TIME > 2016-10-31 -ORDER BY ID ASC; +SELECT DISTINCT id +FROM book,record +WHERE book.id = record.book_id AND record.time > 2016-10-31 +ORDER BY id ASC; diff --git a/assignments/ass1/submission/18307130213/8.sql b/assignments/ass1/submission/18307130213/8.sql index 38465aa..dd8aefe 100644 --- a/assignments/ass1/submission/18307130213/8.sql +++ b/assignments/ass1/submission/18307130213/8.sql @@ -1,6 +1,6 @@ -SELECT DISTINCT ID,NAME,COUNT(*) AS NUM -FROM EMPLOYEE,RECORD -WHERE EMPLOYEE.ID=RECORD.EMPLOYEE_ID -GROUP BY ID - HAVING NUM > 1 -ORDER BY NUM DESC; +SELECT DISTINCT id,name,COUNT(*) AS num +FROM employee,record +WHERE employee.id=record.employee_id +GROUP BY id + HAVING num > 1 +ORDER BY num DESC; diff --git a/assignments/ass1/submission/18307130213/create_table.sql b/assignments/ass1/submission/18307130213/create_table.sql index 8032571..90a4fc0 100644 --- a/assignments/ass1/submission/18307130213/create_table.sql +++ b/assignments/ass1/submission/18307130213/create_table.sql @@ -1,19 +1,19 @@ -CREATE TABLE EMPLOYEE ( ID INT NOT NULL, - NAME VARCHAR(32) NOT NULL, - OFFICE VARCHAR(32) NOT NULL, - AGE SMALLINT NOT NULL, - PRIMARY KEY(ID), - CHECK(AGE BETWEEN 0 AND 100)); +CREATE TABLE employee ( id INT NOT NULL, + name VARCHAR(32) NOT NULL, + office VARCHAR(32) NOT NULL, + age SMALLINT NOT NULL, + PRIMARY KEY(id), + CHECK(age BETWEEN 0 AND 100)); -CREATE TABLE BOOK ( ID INT NOT NULL, - NAME VARCHAR(32) NOT NULL, - AUTHOR VARCHAR(32) NOT NULL, - PUBLISHER VARCHAR(32) NOT NULL, +CREATE TABLE book ( id INT NOT NULL, + name VARCHAR(32) NOT NULL, + author VARCHAR(32) NOT NULL, + publisher VARCHAR(32) NOT NULL, PRIMARY KEY(ID)); -CREATE TABLE RECORD ( BOOK_ID INT NOT NULL, - EMPLOYEE_ID INT NOT NULL, - TIME DATE NOT NULL, - FOREIGN KEY(BOOK_ID) REFERENCES BOOK(ID), - FOREIGN KEY(EMPLOYEE_ID) REFERENCES EMPLOYEE(ID), - PRIMARY KEY(BOOK_ID,EMPLOYEE_ID)); +CREATE TABLE record ( book_id INT NOT NULL, + employee_id INT NOT NULL, + time DATE NOT NULL, + FOREIGN KEY(book_id) REFERENCES book(id), + FOREIGN KEY(employee_id) REFERENCES employee(id), + PRIMARY KEY(book_id,employee_id)); From 9de16acd0cf69e14a3b97c915c2c7a84a47fc8d3 Mon Sep 17 00:00:00 2001 From: riteme <1412803389@qq.com> Date: Fri, 27 Mar 2020 23:52:41 +0800 Subject: [PATCH 105/189] submission of 18307130172 for ass2 --- .../ass2/submission/18307130172/utils.go | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 assignments/ass2/submission/18307130172/utils.go diff --git a/assignments/ass2/submission/18307130172/utils.go b/assignments/ass2/submission/18307130172/utils.go new file mode 100644 index 0000000..6e8a3a3 --- /dev/null +++ b/assignments/ass2/submission/18307130172/utils.go @@ -0,0 +1,172 @@ +package main + +import ( + "fmt" + "reflect" + "sync" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130172" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "whofucksit" // the user name to connect the database, e.g. root + Password = "19260817" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + fmt.Println("(error) in database connection") + panic(err) + } + + stmt, stmtErr := db.Preparex("INSERT INTO comparison_result VALUES (?,?,?,?)") + if stmtErr != nil { + fmt.Println("(error) in statement preparation") + panic(stmtErr) + } + + type result struct { + uid string + vid string + caseId int + result int + } + + const numWorkers = 32 + jobs := make(chan result, numWorkers) + var w sync.WaitGroup + worker := func() { + defer w.Done() + + tx, err := db.Beginx() + if err != nil { + fmt.Println("(error) in transaction initialization") + panic(err) + } + + defer func() { + err := tx.Commit() + if err != nil { + fmt.Println("(error) in transaction commit") + panic(err) + } + }() + + exec := tx.Stmtx(stmt) + defer exec.Close() + + for ret := range jobs { + _, execErr := exec.Exec(ret.uid, ret.vid, ret.caseId, ret.result) + if execErr != nil { + fmt.Println("(error) in performing insertions") + panic(execErr) + } + } + } + + for i := 0; i < numWorkers; i++ { + w.Add(1) + go worker() + } + + for uid, u := range subs { + for vid, v := range subs { + for i := 0; i < NumSQL; i++ { + var ret int + if reflect.DeepEqual(u.sqlResults[i], v.sqlResults[i]) { + ret = 1 + } else { + ret = 0 + } + + jobs <- result{uid, vid, i + 1, ret} + } + } + } + + close(jobs) + w.Wait() + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL = `INSERT INTO score + WITH Results AS ( + SELECT submitter, item, COUNT(comparer) AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter, item + ), Standing AS ( + SELECT item, MAX(vote) AS highest + FROM Results + GROUP BY item + ) + SELECT + submitter, item, + IF(vote = highest, 1, 0) AS score, + vote + FROM Results JOIN Standing USING(item)` + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + rows, rowsErr := db.Query("SELECT submitter, item, score FROM score") + if rowsErr != nil { + panic(rowsErr) + } + + for { + ok := rows.Next() + if !ok { + break + } + + var uid string + var item, score int + rows.Scan(&uid, &item, &score) + subs[uid].score[item] = score + } + // YOUR CODE END +} From 5bb16f6be06888d8240b97587d5a1093055e1fc0 Mon Sep 17 00:00:00 2001 From: 18307130128-yanghang <18307130128@fudan.edu.cn> Date: Sat, 28 Mar 2020 13:20:04 +0800 Subject: [PATCH 106/189] update from upstream, start ass2 --- .../ass2/submission/18307130128/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130128/utils.go diff --git a/assignments/ass2/submission/18307130128/utils.go b/assignments/ass2/submission/18307130128/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130128/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From d45b00982f70ece0af7ebc21419b30b562abf6fc Mon Sep 17 00:00:00 2001 From: xudinghuan <18307130031@fudan.edu.cn> Date: Sat, 28 Mar 2020 01:03:34 -0700 Subject: [PATCH 107/189] update from upstream, start ass2 --- .../ass2/submission/18307130031/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130031/utils.go diff --git a/assignments/ass2/submission/18307130031/utils.go b/assignments/ass2/submission/18307130031/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130031/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 477538d8b3092b97a9bf54a7461791dcacfb8628 Mon Sep 17 00:00:00 2001 From: 18300200015-cty <18300200015@fudan.edu.cn> Date: Sun, 29 Mar 2020 11:30:03 +0800 Subject: [PATCH 108/189] update from upstream, start ass2 --- .../ass2/submission/18300200015/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18300200015/utils.go diff --git a/assignments/ass2/submission/18300200015/utils.go b/assignments/ass2/submission/18300200015/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18300200015/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 528a79b0f61a1d7d50bfba503140fabeb9118b6d Mon Sep 17 00:00:00 2001 From: CAGeng <18307130154@fudan.edu.cn> Date: Sun, 29 Mar 2020 01:53:33 -0700 Subject: [PATCH 109/189] update from upstream, start ass2 --- .../ass2/submission/18307130154/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130154/utils.go diff --git a/assignments/ass2/submission/18307130154/utils.go b/assignments/ass2/submission/18307130154/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130154/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 7f3be07d564ec03182c5edc3e695d440b5347181 Mon Sep 17 00:00:00 2001 From: Kimchuls <49985540+Kimchuls@users.noreply.github.com> Date: Sun, 29 Mar 2020 20:43:49 +0800 Subject: [PATCH 110/189] Add files via upload --- assignments/ass2/submission/utils.go | 151 +++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 assignments/ass2/submission/utils.go diff --git a/assignments/ass2/submission/utils.go b/assignments/ass2/submission/utils.go new file mode 100644 index 0000000..405b34a --- /dev/null +++ b/assignments/ass2/submission/utils.go @@ -0,0 +1,151 @@ +package main + +import ( + "fmt" + //"go/ast" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "reflect" + "sync" + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130112" // your student id, e.g. 18307130177 + SubmissionDir = "F:/Github_Clone/assignments/ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + //init + type answer struct{ + submitters string + comparers string + ids int + equals int + } + const channalSize = 40 + channal := make(chan answer, channalSize) + var wg sync.WaitGroup + memNum := 0 + for range subs{ + memNum ++ + } + //fileopen + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + defer db.Close() + if err != nil{ + panic(err) + } + //insert goroutine + functions := func() { + defer wg.Done() + Tx, err := db.Begin() + if err != nil{ + panic(err) + } + defer func(){ + err := Tx.Commit() + if err != nil{ + panic(err) + } + }() + stmt, err := Tx.Prepare("insert into comparison_result values (?,?,?,?)") + defer stmt.Close() + if err != nil{ + panic(err) + } + for ans := range channal{ + _, err := stmt.Exec(ans.submitters, ans.comparers, ans.ids, ans.equals) + if err != nil{ + panic(err) + } + } + } + //run goroutine & compare & pass value + for i := 1; i <= memNum; i++{ + wg.Add(1) + go functions() + } + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + channal <- answer{submitter, comparer, i+1, equal} + } + } + } + close(channal) + wg.Wait() + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL = + "insert into score(submitter, item, score, vote) with " + + "submission as (select submitter, item, sum(is_equal) as vote from comparison_result group by submitter, item), " + + "standard as (select item, max(vote) as maximum from submission group by item) " + + "select submitter, submission.item, if(submission.vote = standard.maximum, 1, 0) as score, vote from submission, standard where submission.item = standard.item" + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + row, err := db.Query("select submitter, item, score from score") + if err != nil{ + panic(err) + } + defer row.Close() + for { + flag := row.Next() + if(!flag){ + break + } + var submitters string + var items, scores int + row.Scan(&submitters, &items, &scores) + subs[submitters].score[items] = scores + } + // YOUR CODE END +} From 157e999a009bb36a364d20ab5af93c604d12d5a1 Mon Sep 17 00:00:00 2001 From: Kimchuls <49985540+Kimchuls@users.noreply.github.com> Date: Sun, 29 Mar 2020 20:45:35 +0800 Subject: [PATCH 111/189] Delete utils.go --- assignments/ass2/submission/utils.go | 151 --------------------------- 1 file changed, 151 deletions(-) delete mode 100644 assignments/ass2/submission/utils.go diff --git a/assignments/ass2/submission/utils.go b/assignments/ass2/submission/utils.go deleted file mode 100644 index 405b34a..0000000 --- a/assignments/ass2/submission/utils.go +++ /dev/null @@ -1,151 +0,0 @@ -package main - -import ( - "fmt" - //"go/ast" - "time" - - // YOUR CODE BEGIN remove the follow packages if you don't need them - "reflect" - "sync" - // YOUR CODE END - - _ "github.com/go-sql-driver/mysql" - sql "github.com/jmoiron/sqlx" -) - -var ( - // YOUR CODE BELOW - EvaluatorID = "18307130112" // your student id, e.g. 18307130177 - SubmissionDir = "F:/Github_Clone/assignments/ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "root" // the user name to connect the database, e.g. root - Password = "123456" // the password for the user name, e.g. xxx - // YOUR CODE END -) - -// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! -func ConcurrentCompareAndInsert(subs map[string]*Submission) { - start := time.Now() - defer func() { - db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) - if err != nil { - panic(nil) - } - rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") - if err != nil { - panic(err) - } - rows.Next() - var cnt int - err = rows.Scan(&cnt) - if err != nil { - panic(err) - } - if cnt == 0 { - panic("ConcurrentCompareAndInsert Not Implemented") - } - fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) - }() - // YOUR CODE BEGIN - //init - type answer struct{ - submitters string - comparers string - ids int - equals int - } - const channalSize = 40 - channal := make(chan answer, channalSize) - var wg sync.WaitGroup - memNum := 0 - for range subs{ - memNum ++ - } - //fileopen - db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) - defer db.Close() - if err != nil{ - panic(err) - } - //insert goroutine - functions := func() { - defer wg.Done() - Tx, err := db.Begin() - if err != nil{ - panic(err) - } - defer func(){ - err := Tx.Commit() - if err != nil{ - panic(err) - } - }() - stmt, err := Tx.Prepare("insert into comparison_result values (?,?,?,?)") - defer stmt.Close() - if err != nil{ - panic(err) - } - for ans := range channal{ - _, err := stmt.Exec(ans.submitters, ans.comparers, ans.ids, ans.equals) - if err != nil{ - panic(err) - } - } - } - //run goroutine & compare & pass value - for i := 1; i <= memNum; i++{ - wg.Add(1) - go functions() - } - for submitter, sub := range subs { - for comparer, sub2 := range subs { - for i := 0; i < NumSQL; i++ { - var equal int - if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { - equal = 1 - } else { - equal = 0 - } - channal <- answer{submitter, comparer, i+1, equal} - } - } - } - close(channal) - wg.Wait() - // YOUR CODE END -} - -// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table -// `comparision_result` and inserts the score of each submitter on each query into table `score` -func GetScoreSQL() string { - var SQL string - SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. - // YOUR CODE BEGIN - SQL = - "insert into score(submitter, item, score, vote) with " + - "submission as (select submitter, item, sum(is_equal) as vote from comparison_result group by submitter, item), " + - "standard as (select item, max(vote) as maximum from submission group by item) " + - "select submitter, submission.item, if(submission.vote = standard.maximum, 1, 0) as score, vote from submission, standard where submission.item = standard.item" - // YOUR CODE END - return SQL -} - -func GetScore(db *sql.DB, subs map[string]*Submission) { - // YOUR CODE BEGIN - row, err := db.Query("select submitter, item, score from score") - if err != nil{ - panic(err) - } - defer row.Close() - for { - flag := row.Next() - if(!flag){ - break - } - var submitters string - var items, scores int - row.Scan(&submitters, &items, &scores) - subs[submitters].score[items] = scores - } - // YOUR CODE END -} From 55a1493cf612ee0ea35512b45085a3b87dc26a62 Mon Sep 17 00:00:00 2001 From: Kimchuls <49985540+Kimchuls@users.noreply.github.com> Date: Sun, 29 Mar 2020 20:47:24 +0800 Subject: [PATCH 112/189] Add files via upload --- .../ass2/submission/18307130112/utils.go | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 assignments/ass2/submission/18307130112/utils.go diff --git a/assignments/ass2/submission/18307130112/utils.go b/assignments/ass2/submission/18307130112/utils.go new file mode 100644 index 0000000..405b34a --- /dev/null +++ b/assignments/ass2/submission/18307130112/utils.go @@ -0,0 +1,151 @@ +package main + +import ( + "fmt" + //"go/ast" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "reflect" + "sync" + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130112" // your student id, e.g. 18307130177 + SubmissionDir = "F:/Github_Clone/assignments/ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + //init + type answer struct{ + submitters string + comparers string + ids int + equals int + } + const channalSize = 40 + channal := make(chan answer, channalSize) + var wg sync.WaitGroup + memNum := 0 + for range subs{ + memNum ++ + } + //fileopen + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + defer db.Close() + if err != nil{ + panic(err) + } + //insert goroutine + functions := func() { + defer wg.Done() + Tx, err := db.Begin() + if err != nil{ + panic(err) + } + defer func(){ + err := Tx.Commit() + if err != nil{ + panic(err) + } + }() + stmt, err := Tx.Prepare("insert into comparison_result values (?,?,?,?)") + defer stmt.Close() + if err != nil{ + panic(err) + } + for ans := range channal{ + _, err := stmt.Exec(ans.submitters, ans.comparers, ans.ids, ans.equals) + if err != nil{ + panic(err) + } + } + } + //run goroutine & compare & pass value + for i := 1; i <= memNum; i++{ + wg.Add(1) + go functions() + } + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + channal <- answer{submitter, comparer, i+1, equal} + } + } + } + close(channal) + wg.Wait() + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL = + "insert into score(submitter, item, score, vote) with " + + "submission as (select submitter, item, sum(is_equal) as vote from comparison_result group by submitter, item), " + + "standard as (select item, max(vote) as maximum from submission group by item) " + + "select submitter, submission.item, if(submission.vote = standard.maximum, 1, 0) as score, vote from submission, standard where submission.item = standard.item" + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + row, err := db.Query("select submitter, item, score from score") + if err != nil{ + panic(err) + } + defer row.Close() + for { + flag := row.Next() + if(!flag){ + break + } + var submitters string + var items, scores int + row.Scan(&submitters, &items, &scores) + subs[submitters].score[items] = scores + } + // YOUR CODE END +} From 69c59fd78b876ce9347c8d6d1a88d6e7b6d36580 Mon Sep 17 00:00:00 2001 From: chenyue <535727512@qq.com> Date: Mon, 30 Mar 2020 00:12:23 +0800 Subject: [PATCH 113/189] update from upstream,start ass2 --- .../ass2/submission/18307130122/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130122/utils.go diff --git a/assignments/ass2/submission/18307130122/utils.go b/assignments/ass2/submission/18307130122/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130122/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 5a9a1c7cb77592fd4bd5686182baa52f88e94a2c Mon Sep 17 00:00:00 2001 From: lilili2000 <18307130297@fudan.edu.cn> Date: Mon, 30 Mar 2020 09:07:17 +0800 Subject: [PATCH 114/189] update from upstream, start ass2 --- assignments/ass2/evaluator/utils.go | 8 +-- .../ass2/submission/18307130297/utils.go | 67 +++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 assignments/ass2/submission/18307130297/utils.go diff --git a/assignments/ass2/evaluator/utils.go b/assignments/ass2/evaluator/utils.go index 7b8b5b9..b8412f4 100644 --- a/assignments/ass2/evaluator/utils.go +++ b/assignments/ass2/evaluator/utils.go @@ -14,10 +14,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130297" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) diff --git a/assignments/ass2/submission/18307130297/utils.go b/assignments/ass2/submission/18307130297/utils.go new file mode 100644 index 0000000..b8412f4 --- /dev/null +++ b/assignments/ass2/submission/18307130297/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130297" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 34e6ec3ad51280012ef6976233f99dcccbd2d1fc Mon Sep 17 00:00:00 2001 From: EZlzh <1127598375@qq.com> Date: Tue, 31 Mar 2020 00:07:34 +0800 Subject: [PATCH 115/189] update from upstream, start ass2 --- .../ass2/submission/18307130126/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130126/utils.go diff --git a/assignments/ass2/submission/18307130126/utils.go b/assignments/ass2/submission/18307130126/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130126/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From f1a9f40ac68d90d6cf415ff2978532ef1cd6c179 Mon Sep 17 00:00:00 2001 From: 18300200015-cty <18300200015@fudan.edu.cn> Date: Tue, 31 Mar 2020 02:42:01 +0800 Subject: [PATCH 116/189] submission of 18300200015 for ass2 --- .../ass2/submission/18300200015/utils.go | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/assignments/ass2/submission/18300200015/utils.go b/assignments/ass2/submission/18300200015/utils.go index 7b8b5b9..a18f8eb 100644 --- a/assignments/ass2/submission/18300200015/utils.go +++ b/assignments/ass2/submission/18300200015/utils.go @@ -1,11 +1,11 @@ package main - import ( "fmt" "time" - + // YOUR CODE BEGIN remove the follow packages if you don't need them - + "reflect" + "sync" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +14,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18300200015" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "v8k2s6d5n1c3g@"//omit // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +45,37 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + fmt.Println("error1") + panic(nil) + } + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + wg.Add(1) + go func(i int,submitter string,comparer string,sub *Submission,sub2 *Submission){ + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + wg.Done() + }(i,submitter,comparer,sub,sub2) + } + wg.Wait() + } +} + + // YOUR CODE END } @@ -55,6 +85,22 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL=`INSERT INTO score(submitter,item,score,vote) +(SELECT result.submitter,result.item,1 AS score,vote + FROM (SELECT submitter,item,count(*)AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter, item) AS result + WHERE vote >= ALL(SELECT count(*) FROM comparison_result AS other + WHERE is_equal=1 AND result.item=other.item GROUP BY other.submitter,other.item)) +UNION +(SELECT result2.submitter,result2.item,0 AS score,vote + FROM (SELECT submitter,item,count(*)AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter, item) AS result2 + WHERE vote < some(SELECT count(*) FROM comparison_result AS other2 + WHERE is_equal=1 AND result2.item=other2.item GROUP BY other2.submitter,other2.item));` // YOUR CODE END return SQL @@ -62,6 +108,18 @@ func GetScoreSQL() string { func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + rows,err:=db.Query("SELECT submitter,item,score from score") + if err != nil { + fmt.Println(err) + } + var id string + var item,score int + for rows.Next(){ + rows.Scan(&id,&item,&score) + subs[id].score[item]=score + } + // YOUR CODE END } + From 2ed07f323437be3a7aaab72761afe65f6773b7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=8E?= Date: Tue, 31 Mar 2020 11:13:58 +0800 Subject: [PATCH 117/189] Update readme.md --- content/assignment2/readme.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index 2a0bfc0..3d56037 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -125,7 +125,11 @@ You could also do batch insert, which could be even faster, but you won't be abl Also as a reference, your kind TA provided you a concurrent `createSubmissions` in `main.go`, take a look if you don't know how to start. -Also as a kind note, `sql.DB` is not thread-safe, you need multiple `sql.DB` if you want concurrent access of the database, and figuring out (by search it online) what is closure, and how to pass variable to a closure might be helpful. +~~Also as a kind note, `sql.DB` is not thread-safe, you need multiple `sql.DB` if you want concurrent access of the database, and figuring out (by search it online) what is closure, and how to pass variable to a closure might be helpful.~~ + +`sql.DB` is thread-safe[^4], if you had trouble with too many connections error, see [here](https://jmoiron.github.io/sqlx/#connectionPool). Thanks [TwistsOfFate](https://github.com/TwistsOfFate) for pointing this out. + +[^4]: https://github.com/ichn-hu/IDBS-Spring20-Fudan/issues/45#issuecomment-606323923 Run From d175eeaf705599e8e85ea95512d43db7ddd8a51e Mon Sep 17 00:00:00 2001 From: 18300200015-cty <18300200015@fudan.edu.cn> Date: Tue, 31 Mar 2020 19:04:49 +0800 Subject: [PATCH 118/189] submission of cty2 for ass2 --- assignments/ass2/submission/18300200015/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/ass2/submission/18300200015/utils.go b/assignments/ass2/submission/18300200015/utils.go index a18f8eb..dc652be 100644 --- a/assignments/ass2/submission/18300200015/utils.go +++ b/assignments/ass2/submission/18300200015/utils.go @@ -17,7 +17,7 @@ var ( EvaluatorID = "18300200015" // your student id, e.g. 18307130177 SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" User = "root" // the user name to connect the database, e.g. root - Password = "v8k2s6d5n1c3g@"//omit // the password for the user name, e.g. xxx + Password = ""//omit // the password for the user name, e.g. xxx // YOUR CODE END ) From ed96d17a3aad2cc04b4c5eaa9bb228755566605e Mon Sep 17 00:00:00 2001 From: Fan Date: Tue, 31 Mar 2020 20:40:52 +0800 Subject: [PATCH 119/189] submission of 18307130182 for ass2 --- .../ass2/submission/18307130182/utils.go | 83 ++++++++++++++++++- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/assignments/ass2/submission/18307130182/utils.go b/assignments/ass2/submission/18307130182/utils.go index 7b8b5b9..1f4ea69 100644 --- a/assignments/ass2/submission/18307130182/utils.go +++ b/assignments/ass2/submission/18307130182/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,9 +15,9 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root + EvaluatorID = "18307130182" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "fan" // the user name to connect the database, e.g. root Password = "" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -46,6 +47,42 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + defer db.Close() + //db.SetMaxIdleConns(15) + db.SetMaxOpenConns(80) + + wg := sync.WaitGroup{} + for sbt, sb := range subs { + for cmp, sb2 := range subs { + submitter, sub := sbt, sb + comparer, sub2 := cmp, sb2 + wg.Add(1) + go func() { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }() + + } + } + wg.Wait() + // YOUR CODE END } @@ -56,6 +93,20 @@ func GetScoreSQL() string { SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL = `INSERT INTO score + WITH init_vote AS ( + SELECT submitter, item, SUM(is_equal) AS vote + FROM comparison_result + GROUP BY submitter, item + ), + item_maxvote AS ( + SELECT item, MAX(vote) AS maxvote + FROM init_vote + GROUP BY item + ) + SELECT submitter, item, CASE WHEN vote=maxvote THEN 1 ELSE 0 END AS score, vote + FROM init_vote NATURAL JOIN item_maxvote;` + // YOUR CODE END return SQL } @@ -63,5 +114,29 @@ func GetScoreSQL() string { func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + var ( + submitter string + item, score int + ) + + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + defer db.Close() + + rows, err := db.Query("SELECT submitter, item, score FROM score") + if (err != nil) { + panic(err) + } + defer rows.Close() + for rows.Next() { + err := rows.Scan(&submitter, &item, &score) + if err != nil { + panic(err) + } + subs[submitter].score[item] = score + } + // YOUR CODE END } From aba6123fc40416401089e310dc53fdb2e027f3e2 Mon Sep 17 00:00:00 2001 From: chenyue <535727512@qq.com> Date: Tue, 31 Mar 2020 22:00:23 +0800 Subject: [PATCH 120/189] submission of 18307130122 for ass2 --- .../ass2/submission/18307130122/utils.go | 69 ++++++++++++++++--- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/assignments/ass2/submission/18307130122/utils.go b/assignments/ass2/submission/18307130122/utils.go index 7b8b5b9..3d9c30c 100644 --- a/assignments/ass2/submission/18307130122/utils.go +++ b/assignments/ass2/submission/18307130122/utils.go @@ -3,9 +3,9 @@ package main import ( "fmt" "time" - // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +14,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130122" // your student id, e.g. 18307130177 + SubmissionDir = "/home/chenyue/IDBS-Spring20-Fudan/assignments/ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -40,12 +40,39 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { panic(err) } if cnt == 0 { - panic("ConcurrentCompareAndInsert Not Implemented") + panic("ConcurrentCompareAndInsert Not Implemented") } fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + wg.Add(36) + for submitter, sub := range subs { + go func(submitter string,sub *Submission){ + for comparer, sub2 := range subs { + for i := 0; i < NumSQL ; i++{ + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + wg.Done() + }(submitter,sub) + } + wg.Wait() // YOUR CODE END } @@ -55,13 +82,35 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = `INSERT INTO score + WITH Choose1 AS ( + SELECT submitter,item,COUNT(*) vote + FROM comparison_result + GROUP BY submitter,item,is_equal + HAVING SUM(is_equal)>0), + Choose2 AS( + SELECT item,MAX(vote) maxvote + FROM Choose1 + GROUP BY item) + SELECT submitter,Choose1.item,(CASE WHEN vote=maxvote THEN 1 ELSE 0 END) AS score,vote + FROM Choose2,Choose1 + WHERE Choose2.item=Choose1.item` // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + rows,err := db.Query("SELECT submitter,item,score FROM score") + if err != nil { + panic(err) + } + var a string + var b int + var c int + for rows.Next(){ + rows.Scan(&a,&b,&c) + subs[a].score[b]=c + } // YOUR CODE END } From 64899dce48f164e9c9dbb1a818225d3a5927d811 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Wed, 1 Apr 2020 05:02:52 +0800 Subject: [PATCH 121/189] Init --- .../ass2/submission/18307130003/utils.go | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 assignments/ass2/submission/18307130003/utils.go diff --git a/assignments/ass2/submission/18307130003/utils.go b/assignments/ass2/submission/18307130003/utils.go new file mode 100644 index 0000000..4de7e8a --- /dev/null +++ b/assignments/ass2/submission/18307130003/utils.go @@ -0,0 +1,70 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // EvaluatorID is your student ID + EvaluatorID = "18307130003" + // SubmissionDir is the relative path of the submission directory of assignment 1 + SubmissionDir = "../../../ass1/submission/" + // User is the user name to connect the database + User = "root" + // Password is the password for the user name + Password = "Hakula" +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +// GetScore reads your score from table `score` +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 0e03577c450ef464a6fcdd16e7f8a35e6f82af58 Mon Sep 17 00:00:00 2001 From: Fan Date: Wed, 1 Apr 2020 06:04:09 +0800 Subject: [PATCH 122/189] added CompareAndBatchedInsert --- .../ass2/submission/18307130182/utils.go | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/assignments/ass2/submission/18307130182/utils.go b/assignments/ass2/submission/18307130182/utils.go index 1f4ea69..5049610 100644 --- a/assignments/ass2/submission/18307130182/utils.go +++ b/assignments/ass2/submission/18307130182/utils.go @@ -7,6 +7,7 @@ import ( // YOUR CODE BEGIN remove the follow packages if you don't need them "sync" "reflect" + "strings" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -78,7 +79,6 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { } wg.Done() }() - } } wg.Wait() @@ -86,6 +86,60 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { // YOUR CODE END } +// CompareAndBatchedInsert is similar with ConcurrentCompareAndInsert, but it is even faster despite not being concurrent! +func CompareAndBatchedInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("CompareAndBatchedInsert Not Implemented") + } + fmt.Println("CompareAndBatchedInsert takes ", time.Since(start)) + }() + + valueStrings := make([]string, 0, len(subs)*len(subs)) + valueArgs := make([]interface{}, 0, len(valueStrings)*4) + + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + valueStrings = append(valueStrings, "(?, ?, ?, ?)") + valueArgs = append(valueArgs, submitter, comparer, i+1, equal) + } + } + } + + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + defer db.Close() + s := fmt.Sprintf("INSERT INTO comparison_result VALUES %s", strings.Join(valueStrings, ",")) + _, err = db.Exec(s, valueArgs...) + if err != nil { + panic(err) + } +} + // GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table // `comparision_result` and inserts the score of each submitter on each query into table `score` func GetScoreSQL() string { From 850a0cf31df0dd38819c6810b1636bb24b40a790 Mon Sep 17 00:00:00 2001 From: 18307130071_YuhengZhao <18307130071@fudan.edu.cn> Date: Wed, 1 Apr 2020 10:10:50 +0800 Subject: [PATCH 123/189] update from upstream, start ass2 --- .../ass2/submission/18307130071/utils.go | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 assignments/ass2/submission/18307130071/utils.go diff --git a/assignments/ass2/submission/18307130071/utils.go b/assignments/ass2/submission/18307130071/utils.go new file mode 100644 index 0000000..5b613ac --- /dev/null +++ b/assignments/ass2/submission/18307130071/utils.go @@ -0,0 +1,113 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "sync" + "reflect" + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130071" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "xiong67301072" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + var wg sync.WaitGroup + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + go func() { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }() + } + wg.Wait() + } + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL = "insert into score(submitter, item, score, vote) " + + "with sub as (select submitter, item, sum(is_equal) as vote " + + "from comparison_result " + + "group by submitter, item), " + + "std as (select item, max(vote) as most " + + "from sub " + + "group by item) " + + "select submitter, sub.item, if(vote = most, 1, 0) as score, vote " + + "from sub, std " + + "where sub.item = std.item " + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + row, err := db.Query("select submitter, item, score from score") + if err != nil { + panic(err) + } + var subid string + var item, score int + for row.Next() { + row.Scan(&subid, &item, &score) + subs[subid].score[item]=score + } + // YOUR CODE END +} From 339ad14a65b6dc88db9fddad97ddde0707b5fffd Mon Sep 17 00:00:00 2001 From: vincy233 <644255997@qq.com> Date: Wed, 1 Apr 2020 18:29:44 +0800 Subject: [PATCH 124/189] update from upstream, start ass2 --- .../ass2/submission/18307130341/utils.go | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/assignments/ass2/submission/18307130341/utils.go b/assignments/ass2/submission/18307130341/utils.go index 7b8b5b9..17d3edf 100644 --- a/assignments/ass2/submission/18307130341/utils.go +++ b/assignments/ass2/submission/18307130341/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "reflect" + "sync" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130341" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,34 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + var wg sync.WaitGroup + for submitter, sub := range subs { + wg.Add(1) + go func(submitter string,sub *Submission){ + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + wg.Done() + }(submitter,sub) + } + wg.Wait() // YOUR CODE END } @@ -55,13 +83,30 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL="INSERT INTO score(submitter,item,score,vote) "+ + "WITH votetable(submitter,item,vote) AS (SELECT submitter,item,SUM(is_equal) FROM comparison_result GROUP BY submitter,item), "+ + "maxtable(item,maxvote) AS (select item,MAX(vote) FROM votetable GROUP BY item) "+ + "SELECT submitter,votetable.item,if(vote=maxvote,1,0) AS score,vote FROM votetable,maxtable "+ + "WHERE votetable.item=maxtable.item"; // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + rows,err:= db.Query("SELECT submitter,item,score FROM score") + if err != nil{ + panic(err) + } + for rows.Next() { + var submitter string + var item,score int + err = rows.Scan(&submitter,&item,&score) + if err != nil { + panic(err) + } + subs[submitter].score[item] = score + } + rows.Close(); // YOUR CODE END } From 3fc59d8090f5127e36427c6520a3bb099ab30ea5 Mon Sep 17 00:00:00 2001 From: NoSW Date: Wed, 1 Apr 2020 04:50:38 -0700 Subject: [PATCH 125/189] submission of 18300200012 for ass2 --- .../ass2/submission/18300200012/utils.go | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/assignments/ass2/submission/18300200012/utils.go b/assignments/ass2/submission/18300200012/utils.go index 7b8b5b9..09bd5db 100644 --- a/assignments/ass2/submission/18300200012/utils.go +++ b/assignments/ass2/submission/18300200012/utils.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "reflect" "time" // YOUR CODE BEGIN remove the follow packages if you don't need them @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18300200012" // your student id, e.g. 18307130177 + SubmissionDir = "/home/l1q/git_reps/IDBS-Spring20-Fudan/assignments/ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "llq0215llq" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,40 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + ch := make(chan int, NumSQL) + quit := make(chan int) + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for j := 0; j < NumSQL; j++ { + ch <- j + go func() { + i := <-ch + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + + if i == NumSQL-1 { + quit <- 0 + } + }() + } + <-quit + } + } // YOUR CODE END } @@ -56,12 +90,24 @@ func GetScoreSQL() string { SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL = "INSERT INTO score SELECT X.submitter,X.item,IF(X.vote >= Y.highest,1,0),X.vote FROM (SELECT submitter,item,count(is_equal) AS vote FROM comparison_result WHERE is_equal = 1 GROUP BY 1,2) AS X,(SELECT item,max(vote) AS highest FROM (SELECT submitter,item,count(is_equal) AS vote FROM comparison_result WHERE is_equal = 1 GROUP BY 1,2) AS Z GROUP BY 1) AS Y WHERE X.item = Y.item;" + // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + for _, sub := range subs { + for i := 1; i <= NumSQL; i++ { + row, err := db.Query(fmt.Sprintf("SELECT score FROM score WHERE submitter = '%s' AND item = %d", sub.submitter, i)) + if err != nil { + panic(err) + } + for row.Next() { + _ = row.Scan(&sub.score[i]) + } + } + } // YOUR CODE END } From d9ce7cee64d94e2cb47986575f0f69fd8e709107 Mon Sep 17 00:00:00 2001 From: vincy233 <644255997@qq.com> Date: Wed, 1 Apr 2020 21:05:15 +0800 Subject: [PATCH 126/189] submission of 18307130341 for ass2 --- assignments/ass2/submission/18307130341/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/ass2/submission/18307130341/utils.go b/assignments/ass2/submission/18307130341/utils.go index 17d3edf..f4d23c0 100644 --- a/assignments/ass2/submission/18307130341/utils.go +++ b/assignments/ass2/submission/18307130341/utils.go @@ -90,7 +90,7 @@ func GetScoreSQL() string { "WHERE votetable.item=maxtable.item"; // YOUR CODE END return SQL -} +} func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN From 8e233f8cea3c6ffe1f8ab795512193c117e0e63d Mon Sep 17 00:00:00 2001 From: Jimmy Tan <42105405+15711657500@users.noreply.github.com> Date: Wed, 1 Apr 2020 21:52:18 +0800 Subject: [PATCH 127/189] Delete readme.md --- content/assignment2/readme.md | 344 ---------------------------------- 1 file changed, 344 deletions(-) delete mode 100644 content/assignment2/readme.md diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md deleted file mode 100644 index ee1ae92..0000000 --- a/content/assignment2/readme.md +++ /dev/null @@ -1,344 +0,0 @@ -# Assignment 2, Evaluator - -In the first assignment, you have written several SQLs to help you build basic experience playing with MySQL, in this assignment you are going to continue the journey, but this time, you will use a programming language to interact with MySQL, namely, golang. - -Golang, developed by Google, is a statically typed programming language (we'll refer to golang as Go in the following content). It is becoming more and more popular in the recent several years, companies like bilibili[^1] [^3] and zhihu[^2] and so many more are using Go to build the backend of their applications. And the idea of cloud native and microservice are built almost on top of Go, just to name a few softwares in Go, docker, kubernetes, and TiDB (a distributed database compatible with MySQL, we probably will also play with it in the future). So it is very desirable and meaningful to start to learn this language. - -[^1]: https://github.com/bilibili/kratos -[^2]: https://zhuanlan.zhihu.com/p/48039838 -[^3]: https://www.bilibili.com/video/av29079011/ - -Go is also very simple, it is built with simplicity in mind, as long as you know how to write C code, it won't be hard -to learn Go. However, Go does introduce many ideas that perhaps you are not familiar with, most of the ideas are -related to concurrency, such as `channel` and `goroutine`, we will be using these features extensively in the assignments, -since database systems are built to allow (or welcome) concurrent accesses, and Go has a good fame of being a -concurrency friendly programming language. - -You might be frightened that you need to learn a new programming language, but it is a must for a good programmer to be -fluent in many programming languages, and it won't be too hard given you already know at least one programming -language. To make your learning experience less painful, follow the instructions below to learn it. - -* [Install Go compiler and setup the environment](https://golang.org/doc/install), we will be using the latest Go version, 1.14. -* Join [the tour of Go](https://tour.golang.org/), walk through the whole tutorial, and come back often when you have - problems writing Go in the future. This is an excellent tutorial, and your TA also learned Go from here. It would take at least 2 - days for you to fully understand the tutorial, so start early. Also, try some of the examples on your local machine, - which will help you better understand the toolchain of Go. Note, the most important thing for you to learn is the - concurrency part, you need to understand goroutine (kind of like a light-weighted thread) and `sync.Mutex`, since you - will need it in this assignment. As for the syntax of Go, it is quite similar with C, so do not worry, you could just - skim this part and come back when you need it. -* Read the provided code and make sure your understand every line of the code. If you don't, check the tutorial again. - And if you are still confused, do not hesitate to ask questions in the comment bellow. -* Try to use GoLand for development, it provides the best Go development environment in your TA's opinion, and it is free for educational - purpose. You could connect GoLand with your MySQL server and GoLand will be able to help you write your SQL. - -## Setup - -To setup the environment for this assignment, you have the following steps to finish. - -### Update Your Cloned Git Repository - -Your local repository only have your own code, in order to get the content for this assignment, you need to fetch data -from GitHub. Use the following commands: - -```bash -$ git remote add upstream git://github.com/ichn-hu/IDBS-Spring20-Fudan.git # add your TA's repository to the romote -$ git fetch upstream # this command fetches the update in your TA's repository, it would take a while -$ git merge upstream/master # merge the updates into your master, you can also do `git rebase upstream/master` if you used another branch other than master previously for assignment 1 -``` - -### Copy Provided Code to Your Working Directory - -The code provided is under `assignments/ass2/evaluator/`. Similarly you have to create your working directory under -`assignments/ass2/submission/` - -Suppose your current directory is the root of the repository. - -```bash -$ mkdir assignments/ass2/submission/YOURSTUDENTID # put your student id here -$ cp assignments/ass2/evaluator/* assignments/ass2/submission/YOURSTUDENTID/ # copy provided code into your working directory -``` - -You can only modify the files in your own working directory, any attempts to modify files outside your working directory -will make your submission invalid. - -Especially, only `utils.go` in your working directory will be considered in this assignment (other files will be ignored, see -`assignments/ass2/submission/.gitignore`). With this said, you could actually modify other provided files like -`main.go` if it helps you with understanding the code or debugging your own code, but your modification will not be -considered when we evaluate your submission, and you should make sure your code in `utils.go` can work with the original -codebase. - -You should generally only put your code between `YOUR CODE BEGIN` and `YOUR CODE END`. The evaluation of assignment 2 will be based on the three functions you filled in in `utils.go`. - -As for the packages, you can not introduce any other external packages (the `go.mod` file will be ignored for your submission, even if you do, we will not be able to run it). You are free to use other internal packages, as a reference the TA's solution only uses `sync` and `reflect`. - -### Create a New Branch for Development - -It is your TA's fault that he didn't tell you this in assignment 1. It would be better that you don't work on the master -branch, because that will make the git history messy. Create a new branch and develop your code in the new branch, you -could name the branch `ass2`. - -``` -$ git checkout -b ass2 # create and checkout to a new branch ass2 -$ git add . && git commit -m "update from upstream, start ass2" # commit your modification (only `utils.go` will be tracked) and start working -``` - -### Modify Configuration - -Now edit `utils.go`, in the first `YOUR CODE` block, put your student id in `EvaluateID`, `../../../ass1/submission/` -for `SubmissionDir`, and the user name and password to connect your MySQL server. - -You could then run - -```bash -$ go run main.go utils.go -``` - -at your working directory, you should see - -```text -submission created -``` - -in the output if the configuration is correct. If you did not see this line, check the error message and search online, and try to fix it. - -You could ignore the printed error message above this line, these messages are for you to know if there -are any problems with the submissions of assignment 1. They are only relevant if you found your solution for assignment 1 is not compliant with -the evaluator, then these error messages tell you why. - -If you want to argue about your submission for assignment 1, create another pull request with your modified submission for assignment 1 (only modify files in your working directory for assignment 1) and explain why you think you -deserve a higher score in the pull request, mistakes like creating tables using all UPPERCASE names sound like possible to have a second chance. - -Each submission created will have an integer array `score`, and `score[0]` is 0 if the submission's `create_table.sql` is wrong, otherwise it will be 1. `score[1]` to `score[8]` stands for the score for query 1 to query 8 in assignment 1, and they are obtained in the following manner. - -## Concurrent Comparison Result Insert - -Take a look at `compareAndInsert`, which compares each submissions with all the submissions on each query, and insert a record for the comparison in the table `comparison_result`. - -The problem of this function is that it is single-threaded. As you might know, access database is IO-bounded, the CPU might wait for a lot of time for the response of the database, so it makes sense to make the insert concurrent so that the CPU could get more busy and making the insert faster. - -The single thread version provided in the provided code takes almost 1 minutes on your TA's laptop to insert 7200 -records in the database. This is too slow! The QPS (query per second) is about 7200 / 60 = 120. - -With the help of goroutine, it can be easily made concurrent, so please make it concurrent and improve the QPS in `ConcurrentCompareAndInsert`. As a reference, it takes less than 4 seconds with your TA's simple concurrent version, a speed up of 15x. - -You could also do batch insert, which could be even faster, but you won't be able to play with concurrency. If you are interested, you could write a `CompareAndBatchedInsert` function in `utils.go` and test how faster it could be, however this part is unrated. - -Also as a reference, your kind TA provided you a concurrent `createSubmissions` in `main.go`, take a look if you don't know how to start. - -Also as a kind note, `sql.DB` is not thread-safe, you need multiple `sql.DB` if you want concurrent access of the database, and figuring out (by search it online) what is closure, and how to pass variable to a closure might be helpful. - -Run - -```bash -$ go run main.go utils.go -``` - -again, and you will see - -```text -ConcurrentCompareAndInsert takes xxxs -``` - -instead of - -```text -ConcurrentCompareAndInsert Not Implemented -``` - -## Evaluate the Score - -Once you get all the comparison result, it is time to get the score for each submission on each query. - -We evaluate the submission using the following rule. In `comparison_result`, for each query, each -submission has record of `is_equal` to every submissions, and the sum of `is_equal` is the vote of -the submission for the query, if the submission has the highest vote, i.e. most of submissions agreed with this submission's result on the query, the score of the submission on this query will be 1, otherwise 0. - -Look at the [output bellow in hints](#hints) if you are still not sure how the rule works. - -You need to use **a single query** to insert the score result in the table `score` created in `createScoreTable`, where `submitter` is the ID of the submitter of the submission, item ranges from 1 to 8 and stands for each query, score being 0 or 1 means the score of `submitter` on query `item`, and `vote` is the vote mentioned above for sanity check. - -You need to finish `GetScoreSQL` in `utils.go`, which only returns a single string containing the query sent to MySQL that reads from `comparison_result` and inserts into `score`. - -This query can be rather complex and challenging, here are some hints that might be helpful - -* UNION is a good wait to combine result of multiple queries -* Common Table Expression (CTE) can be helpful if you want to reuse the result of a subquery -* `order by` can be used with multiple column -* You can insert with values replaced by a select query -* Window functions might be helpful, check it out if you are interested, but you can finish this query without using it - -You are free to hack around using any features of MySQL you want (version 8.0), there are many possible ways, as long as you can make it with the `GetScoreSQL` function, you will get the score. - -Run - -```bash -$ go run main.go utils.go -``` - -again, and you will see - -```text -GetScoreSQL inserted xxx records into score -``` - -instead of - -```text -GetScoreSQL Not Implemented -``` - -## Get the Score - -Finally, you need to fill in each submission's `score` (i.e. `Submission.score`) with the data in table `score`. Finish `GetScore` and read score from table `score` and you will get output like - -```text -... -18307130252 1 1 1 1 1 1 1 1 0 -18300200015 1 1 1 1 1 1 1 1 0 -18307130031 1 1 1 1 1 1 1 0 1 -18307130112 1 1 1 1 1 1 0 1 0 -... -``` - -if you run `go run main.go utils.go`. - -## Hints - -The sample output from your TA is - -??? note "sample output" - ```text - ╰─$ go run main.go utils.go - 18307130154 0 Error 1146: Table 'ass1_18307130154.employee' doesn't exist - 18307130163 0 Error 1049: Unknown database 'ass1' - 19307130296 0 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE book( - id int(32) not null auto_increment primary key, - name var' at line 8 - 18307130071 1 Error 1054: Unknown column 'jones' in 'where clause' - 18307130071 2 Error 1146: Table 'ass1_18307130071.empolyee' doesn't exist - 18307130071 7 Error 1630: FUNCTION time.AFTER does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual - 18307130071 8 Error 1054: Unknown column 'id' in 'field list' - 18307130102 7 Error 1305: FUNCTION ass1_18307130102.to_date does not exist - 19307130296 7 Error 1054: Unknown column 'id' in 'order clause' - 19307130296 8 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * - FROM record - WHERE record.employee_id=employee.id - ) AS num>1 - ORD' at line 5 - 18307130213 0 Error 1146: Table 'ass1_18307130213.employee' doesn't exist - 18307130297 7 Error 1054: Unknown column 'id' in 'field list' - 18307130252 8 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') - on employee.id = X.id - where X.num > 1 - order by X.num desc' at line 4 - 18307130213 1 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 2 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 3 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 4 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 5 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 6 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist - 18307130213 7 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist - 18307130252 8 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') - on employee.id = X.id - where X.num > 1 - order by X.num desc' at line 4 - 18307130213 1 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 2 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 3 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 4 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 5 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - 18307130213 6 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist - 18307130213 7 Error 1146: Table 'ass1_18307130213.BOOK' doesn't exist - 18307130213 8 Error 1146: Table 'ass1_18307130213.EMPLOYEE' doesn't exist - submission created - ConcurrentCompareAndInsert takes 4.491039717s - GetScoreSQL inserted 264 records into score - 18307130017 1 1 1 1 1 1 1 1 0 - 18307130122 1 1 1 1 1 1 1 1 0 - 18307130213 0 0 0 0 0 0 0 0 0 - 18300750006 1 1 1 1 1 1 1 1 1 - 19307130296 0 1 1 1 1 0 1 0 0 - 18307130024 1 1 1 1 1 1 1 1 1 - 18307130027 1 1 1 1 1 0 1 1 1 - 18307130102 1 1 1 1 1 1 1 0 1 - 18307130103 1 1 1 1 1 1 1 0 1 - 18307130112 1 1 1 1 1 1 0 1 0 - 18307130154 0 1 1 1 1 1 1 0 1 - 18307130297 1 1 1 1 1 1 1 0 0 - 15307130201 1 1 1 1 1 1 1 1 1 - 18307130128 1 1 1 1 1 1 1 1 0 - 18307130252 1 1 1 1 1 1 1 1 0 - 18307130266 1 1 1 1 1 1 1 1 1 - 18307130003 1 1 1 1 1 1 1 1 1 - 18307130182 1 1 1 1 1 1 1 1 1 - 19300290059 1 1 1 1 1 1 0 1 1 - 18307130071 1 0 0 0 0 1 0 0 0 - 18300200015 1 1 1 1 1 1 1 1 0 - 18307130031 1 1 1 1 1 1 1 0 1 - 18307130090 1 1 1 1 1 1 1 0 0 - 18307130116 1 1 1 1 1 1 1 0 0 - 18307130126 1 1 1 1 1 1 1 1 1 - 18307130172 1 1 1 1 1 1 1 0 1 - 18307130341 1 1 1 1 1 1 1 1 1 - 18300200009 1 1 1 1 1 1 1 0 0 - 18307130104 1 1 1 1 1 1 1 0 1 - 18307130123 1 1 1 1 1 1 1 1 1 - 18307130163 0 1 1 1 1 1 1 0 1 - 18307130340 1 1 1 1 1 1 1 1 1 - 18300200012 1 1 1 1 1 1 1 0 1 - ``` - -And some sample from table `score` - -??? note "sample from `score`" - ```text - ass1_result_evaluated_by_16307130177> select * from score limit 30; - +-------------+------+-------+------+ - | submitter | item | score | vote | - +-------------+------+-------+------+ - | 15307130201 | 1 | 1 | 31 | - | 15307130201 | 2 | 1 | 31 | - | 15307130201 | 3 | 1 | 31 | - | 15307130201 | 4 | 1 | 31 | - | 15307130201 | 5 | 1 | 30 | - | 15307130201 | 6 | 1 | 29 | - | 15307130201 | 7 | 1 | 18 | - | 15307130201 | 8 | 1 | 20 | - | 18300200009 | 1 | 1 | 31 | - | 18300200009 | 2 | 1 | 31 | - | 18300200009 | 3 | 1 | 31 | - | 18300200009 | 4 | 1 | 31 | - | 18300200009 | 5 | 1 | 30 | - | 18300200009 | 6 | 1 | 29 | - | 18300200009 | 7 | 0 | 2 | - | 18300200009 | 8 | 0 | 4 | - | 18300200012 | 1 | 1 | 31 | - | 18300200012 | 2 | 1 | 31 | - | 18300200012 | 3 | 1 | 31 | - | 18300200012 | 4 | 1 | 31 | - | 18300200012 | 5 | 1 | 30 | - | 18300200012 | 6 | 1 | 29 | - | 18300200012 | 7 | 0 | 5 | - | 18300200012 | 8 | 1 | 20 | - | 18300200015 | 1 | 1 | 31 | - | 18300200015 | 2 | 1 | 31 | - | 18300200015 | 3 | 1 | 31 | - | 18300200015 | 4 | 1 | 31 | - | 18300200015 | 5 | 1 | 30 | - | 18300200015 | 6 | 1 | 29 | - +-------------+------+-------+------+ - ``` - -## Submit your solution - -As you have done for assignment 1, commit your change for `utils.go` and create a pull request to submit it. - -Since you used another branch (`ass2` as your TA told you above), do the following to push your code to your -repository - -```bash -$ git push --set-upstream origin ass2 -``` - -Also do not look at other's submission before your submission get merged. - From 0fe69e76394891516ed1085cf2081de2b4625e69 Mon Sep 17 00:00:00 2001 From: 15711657500 <15711657500@163.com> Date: Wed, 1 Apr 2020 21:55:07 +0800 Subject: [PATCH 128/189] add readme --- content/assignment2/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/assignment2/readme.md b/content/assignment2/readme.md index ee1ae92..a9fd218 100644 --- a/content/assignment2/readme.md +++ b/content/assignment2/readme.md @@ -41,7 +41,7 @@ Your local repository only have your own code, in order to get the content for t from GitHub. Use the following commands: ```bash -$ git remote add upstream git://github.com/ichn-hu/IDBS-Spring20-Fudan.git # add your TA's repository to the romote +$ git remote add upstream xxx # add your TA's repository to the romote $ git fetch upstream # this command fetches the update in your TA's repository, it would take a while $ git merge upstream/master # merge the updates into your master, you can also do `git rebase upstream/master` if you used another branch other than master previously for assignment 1 ``` From 1df99d49b70edb12ac045927ba6d000a243a09c6 Mon Sep 17 00:00:00 2001 From: EZlzh <1127598375@qq.com> Date: Wed, 1 Apr 2020 23:59:41 +0800 Subject: [PATCH 129/189] submission of 18307130126 for ass2 --- .../ass2/submission/18307130126/utils.go | 73 +++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/assignments/ass2/submission/18307130126/utils.go b/assignments/ass2/submission/18307130126/utils.go index 7b8b5b9..861b097 100644 --- a/assignments/ass2/submission/18307130126/utils.go +++ b/assignments/ass2/submission/18307130126/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130126" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "1357xb++++" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -46,6 +47,42 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + + //db.SetMaxOpenConns(50) + + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + go func(submitter string, comparer string, sub *Submission, sub2 *Submission){ + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }(submitter, comparer, sub, sub2) + } + //if len(subs) > max_connections , it will still open too many files. + wg.Wait() + } + //panic: dial tcp 127.0.0.1:3306: socket: too many open files + //wg.Wait() + + // YOUR CODE END } @@ -56,12 +93,38 @@ func GetScoreSQL() string { SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL = `INSERT INTO score(submitter, item, score, vote) + WITH SUM_VOTE AS + (SELECT submitter, item, SUM(is_equal) AS vote + FROM comparison_result + GROUP BY submitter, item), + MAX_VOTE AS + (SELECT item, MAX(vote) AS maxvote + FROM SUM_VOTE + GROUP BY item) + SELECT submitter, item, IF(vote = maxvote, 1, 0) AS score, vote + FROM SUM_VOTE NATURAL JOIN MAX_VOTE ; ` + // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + row, err := db.Query("SELECT submitter, item, score FROM score") + if err != nil { + panic(err) + } + var stuid string + var item, score int + for row.Next() { + err := row.Scan(&stuid, &item, &score) + if(err != nil) { + panic(err) + } + subs[stuid].score[item] = score + } + defer db.Close() // YOUR CODE END } From b17f2b3d3615fe633fafd3a76768049c9931b748 Mon Sep 17 00:00:00 2001 From: EZlzh <1127598375@qq.com> Date: Thu, 2 Apr 2020 00:00:05 +0800 Subject: [PATCH 130/189] submission of 18307130126 for ass2 --- assignments/ass2/submission/18307130126/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/ass2/submission/18307130126/utils.go b/assignments/ass2/submission/18307130126/utils.go index 861b097..af99bcf 100644 --- a/assignments/ass2/submission/18307130126/utils.go +++ b/assignments/ass2/submission/18307130126/utils.go @@ -18,7 +18,7 @@ var ( EvaluatorID = "18307130126" // your student id, e.g. 18307130177 SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" User = "root" // the user name to connect the database, e.g. root - Password = "1357xb++++" // the password for the user name, e.g. xxx + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) From 767df29cc0d1ec5da18bfd059a8ef1c2613f007b Mon Sep 17 00:00:00 2001 From: XuYipei <1449097870@qq.com> Date: Thu, 2 Apr 2020 00:23:25 +0800 Subject: [PATCH 131/189] update from upstream, start ass2 --- .../ass2/submission/18307130103/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130103/utils.go diff --git a/assignments/ass2/submission/18307130103/utils.go b/assignments/ass2/submission/18307130103/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130103/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 3adbf54555e62b5b462e3be7c520b4bfd2d03b81 Mon Sep 17 00:00:00 2001 From: XuYipei <1449097870@qq.com> Date: Thu, 2 Apr 2020 00:26:30 +0800 Subject: [PATCH 132/189] Submission of Ass2 by 18307130103 --- .../ass2/submission/18307130103/utils.go | 82 +++++++++++++++++-- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/assignments/ass2/submission/18307130103/utils.go b/assignments/ass2/submission/18307130103/utils.go index 7b8b5b9..92907f2 100644 --- a/assignments/ass2/submission/18307130103/utils.go +++ b/assignments/ass2/submission/18307130103/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "reflect" + "sync" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130103" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "XuYipei" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,64 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN +/* + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + } +*/ + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + nm := make(chan string) + for submitter := range subs{ + go func(){ + submitter := <- nm + sub := subs[submitter] + wg.Add(1) + for comparer, sub2 := range subs{ + for i :=0; i < NumSQL; i++{ + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]){ + equal = 1 + }else{ + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + wg.Done() + }() + nm <- submitter + } + wg.Wait() + // YOUR CODE END } @@ -55,7 +113,7 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = "INSERT INTO score(submitter, item, score, vote) SELECT final_table.submitter, final_table.item, final_table.score, final_table.vote FROM(WITH vote_table AS(SELECT submitter, item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item), max_vote_table AS(SELECT item, MAX(vote) as mx FROM vote_table GROUP BY vote_table.item), merge_table AS(SELECT vote_table.submitter, vote_table.item, (vote_table.vote = max_vote_table.mx) AS score, vote_table.vote FROM vote_table INNER JOIN max_vote_table ON vote_table.item = max_vote_table.item) SELECT merge_table.submitter as submitter, merge_table.item as item, merge_table.score as score, merge_table.vote as vote FROM merge_table ORDER BY submitter ASC, item ASC)AS final_table;" // YOUR CODE END return SQL } @@ -63,5 +121,17 @@ func GetScoreSQL() string { func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + rows, err := db.Query("SELECT * FROM score;") + if (err != nil){ + panic(err) + } + for rows.Next(){ + var str string + var item, score, vote int + rows.Scan(&str, &item, &score, &vote) +// fmt.Println(str, item, score,vote) + subs[str].score[item] = score + } + // YOUR CODE END } From cf0ae90065cd3419032ff5bf5b4dd57ae4e323e8 Mon Sep 17 00:00:00 2001 From: unicornt Date: Thu, 2 Apr 2020 01:31:39 +0800 Subject: [PATCH 133/189] submission of 18307130104 for ass2 --- .../ass2/submission/18307130104/utils.go | 103 ++++++++++++++++-- 1 file changed, 96 insertions(+), 7 deletions(-) diff --git a/assignments/ass2/submission/18307130104/utils.go b/assignments/ass2/submission/18307130104/utils.go index 7b8b5b9..f301371 100644 --- a/assignments/ass2/submission/18307130104/utils.go +++ b/assignments/ass2/submission/18307130104/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "reflect" + "sync" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130104" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "unicornt" // the user name to connect the database, e.g. root + Password = "twinblade" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,72 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + type safedb struct{ + db *sql.DB + mux sync.Mutex + } + const tot = 30 + var dbarr[tot] safedb + for i := 0; i < tot; i++ { + dbarr[i] = safedb{ db: db } + } + var wg sync.WaitGroup + cur := 0 + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + wg.Add(1) + cur ++ + if cur == tot { + cur = 0 + } + go func(wg *sync.WaitGroup, cur1 int, submitter string, comparer string, equal int, i int){ + dbarr[cur1].mux.Lock() + defer dbarr[cur1].mux.Unlock() + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := dbarr[cur1].db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + wg.Done() + }(&wg, cur, submitter, comparer, equal, i) + } + } + wg.Wait() + } + /*db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + }*/ // YOUR CODE END } @@ -55,13 +121,36 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = "INSERT INTO score (submitter, item, score, vote) " + + "(SELECT submitter, item, 1 AS score, vote " + + "FROM (SELECT submitter, item, COUNT(*) AS vote FROM comparison_result WHERE is_equal = 1 GROUP BY submitter, item) AS X " + + "WHERE vote >= ALL(SELECT COUNT(*) " + + "FROM comparison_result AS Y " + + "WHERE Y.is_equal = 1 AND X.item = Y.item " + + "GROUP BY submitter)) " + + "UNION " + + "(SELECT submitter, item, 0 AS score, vote " + + "FROM (SELECT submitter, item, COUNT(*) AS vote FROM comparison_result WHERE is_equal = 1 GROUP BY submitter, item) AS X " + + "WHERE vote < SOME(SELECT COUNT(*) " + + "FROM comparison_result AS Y " + + "WHERE Y.is_equal = 1 AND X.item = Y.item " + + "GROUP BY submitter)) " // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + score, scoreerr := db.Query("SELECT submitter, item, score FROM score") + if scoreerr != nil { + panic(scoreerr) + } + for score.Next() { + var id string + var itid, sc int + score.Scan(&id, &itid, &sc) + subs[id].score[itid] = sc + } // YOUR CODE END } From b00c559d8beb999fc7192cba0dcec5ffcffd7a7e Mon Sep 17 00:00:00 2001 From: unicornt Date: Thu, 2 Apr 2020 02:12:03 +0800 Subject: [PATCH 134/189] submission of 18307130104 for ass2 --- .../ass2/submission/18307130104/utils.go | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/assignments/ass2/submission/18307130104/utils.go b/assignments/ass2/submission/18307130104/utils.go index f301371..3eb6db5 100644 --- a/assignments/ass2/submission/18307130104/utils.go +++ b/assignments/ass2/submission/18307130104/utils.go @@ -17,8 +17,8 @@ var ( // YOUR CODE BELOW EvaluatorID = "18307130104" // your student id, e.g. 18307130177 SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "unicornt" // the user name to connect the database, e.g. root - Password = "twinblade" // the password for the user name, e.g. xxx + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -121,20 +121,24 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - SQL = "INSERT INTO score (submitter, item, score, vote) " + - "(SELECT submitter, item, 1 AS score, vote " + - "FROM (SELECT submitter, item, COUNT(*) AS vote FROM comparison_result WHERE is_equal = 1 GROUP BY submitter, item) AS X " + - "WHERE vote >= ALL(SELECT COUNT(*) " + - "FROM comparison_result AS Y " + - "WHERE Y.is_equal = 1 AND X.item = Y.item " + - "GROUP BY submitter)) " + - "UNION " + - "(SELECT submitter, item, 0 AS score, vote " + - "FROM (SELECT submitter, item, COUNT(*) AS vote FROM comparison_result WHERE is_equal = 1 GROUP BY submitter, item) AS X " + - "WHERE vote < SOME(SELECT COUNT(*) " + - "FROM comparison_result AS Y " + - "WHERE Y.is_equal = 1 AND X.item = Y.item " + - "GROUP BY submitter)) " + SQL = `INSERT INTO score (submitter, item, score, vote) + With equal_comp(submitter, item, vote) AS + (SELECT submitter, item, COUNT(DISTINCT comparer) AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter, item) + + (SELECT submitter, item, 1 AS score, vote + FROM equal_comp AS X + WHERE vote >= ALL(SELECT Y.vote + FROM equal_comp AS Y + WHERE Y.item = X.item)) + UNION + (SELECT submitter, item, 0 AS score, vote + FROM equal_comp AS X + WHERE vote < SOME(SELECT Y.vote + FROM equal_comp AS Y + WHERE Y.item = X.item)) ` // YOUR CODE END return SQL } From 4d84b24bd460bb7b2aa4d744cec3228453e067d9 Mon Sep 17 00:00:00 2001 From: lilili2000 <18307130297@fudan.edu.cn> Date: Thu, 2 Apr 2020 09:29:04 +0800 Subject: [PATCH 135/189] submission of 18307130297 for ass2 --- .../ass2/submission/18307130297/utils.go | 87 ++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/assignments/ass2/submission/18307130297/utils.go b/assignments/ass2/submission/18307130297/utils.go index b8412f4..797fbc4 100644 --- a/assignments/ass2/submission/18307130297/utils.go +++ b/assignments/ass2/submission/18307130297/utils.go @@ -6,6 +6,9 @@ import ( // YOUR CODE BEGIN remove the follow packages if you don't need them + "sync" + "reflect" + // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -17,7 +20,7 @@ var ( EvaluatorID = "18307130297" // your student id, e.g. 18307130177 SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" User = "root" // the user name to connect the database, e.g. root - Password = "123456" // the password for the user name, e.g. xxx + // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -46,6 +49,44 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + + wg := sync.WaitGroup{} + + for submitter, sub := range subs { + for comparer, sub2 := range subs { + + wg.Add(1) + + + go func(){ + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + + wg.Done() + + }() + } + wg.Wait() + } + + + // YOUR CODE END } @@ -56,6 +97,30 @@ func GetScoreSQL() string { SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL=`INSERT INTO score + + (SELECT submitter,item,1 AS score,vote + FROM (SELECT submitter,item,1 AS score,COUNT(*) AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter,item) AS X + WHERE vote >= ALL(SELECT COUNT(*) + FROM comparison_result AS Y + WHERE Y.item=X.item AND is_equal = 1 + GROUP BY Y.submitter,Y.item)) + UNION + (SELECT submitter,item,0 AS score,vote + FROM (SELECT submitter,item,0 AS score,COUNT(*) AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter,item) AS X + WHERE vote < SOME(SELECT COUNT(*) + FROM comparison_result AS Y + WHERE Y.item=X.item AND is_equal = 1 + GROUP BY Y.submitter,Y.item)) + ` + + // YOUR CODE END return SQL } @@ -63,5 +128,25 @@ func GetScoreSQL() string { func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + rows,err := db.Query("SELECT submitter,item,score from score") + + if err!=nil{ + panic(err) + } + + for { + ok := rows.Next() + if !ok { + break + } + + var submitter string + var item, s int + + rows.Scan(&submitter, &item, &s) + + subs[submitter].score[item] = s + } + // YOUR CODE END } From 4682fdca9736a7373c1354126e89ca22ffeb7644 Mon Sep 17 00:00:00 2001 From: LucasXXII Date: Thu, 2 Apr 2020 13:08:29 +0800 Subject: [PATCH 136/189] update from upstream, start ass2 --- .../ass2/submission/15307130201/utils.go | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 assignments/ass2/submission/15307130201/utils.go diff --git a/assignments/ass2/submission/15307130201/utils.go b/assignments/ass2/submission/15307130201/utils.go new file mode 100644 index 0000000..a5dbcdb --- /dev/null +++ b/assignments/ass2/submission/15307130201/utils.go @@ -0,0 +1,137 @@ +package main + +import ( + "fmt" + "reflect" + "sync" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "15307130201" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + // *** From the Golang docs *** "A defer statement postpones the execution of a function until the surrounding function returns, either normally or through a panic." + defer func() { + // Execute an SQL phrase to log in as user, and check error (same as in compareAndInsert) + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + // Execute an SQL phrase to query the number of rows in the table "comparison_result" + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + // *** From the Golang docs *** "Every call to Scan, even the first one, must be preceded by a call to Next." + rows.Next() // Moves the "row pointer" to the first row of "comparison_result" + var cnt int // Initialize an integer variable "cnt" + err = rows.Scan(&cnt) // Try to copy the first row to the variable "cnt" + if err != nil { + panic(err) + } + // If the first row does not exist (i.e. the table has 0 rows now), clearly this function is not yet implemented + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } // If there is error, ... + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { // For each submitter j and their submission in the array subs + for i := 0; i < NumSQL; i++ { // For each SQL phrase (known a priori that there is 8 of them) + var equal int // Initialize an integer variable named "equal" + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 // If the results of the i-th SQL phrase are "DeepEqual", ... + } else { + equal = 0 + } + wg.Add(1) + go func(submitter string, sub *Submission, comparer string, sub2 *Submission, i int) { + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) // Execute the SQL phrase + if err != nil { + fmt.Println(s) + panic(err) + } + wg.Done() + }(submitter, sub, comparer, sub2, i) + } + wg.Wait() + } + } + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + // 1. Transform "comparison_result" (submitter, comparer, item, is_equal) to "V" (submitter, item, vote) + // 2. Do a sub-query yielding the table "IV" (item, max_vote) + // 3. Join V and IV to obtain a new table (submitter, item, vote, max_vote) + // 4. The desired table "score" is simply (submitter, item, vote == max_vote, vote) + SQL = fmt.Sprintf( "INSERT INTO score (submitter, item, score, vote) " + + "WITH V (submitter, item, vote) " + + "AS (" + + "SELECT submitter, item, SUM(is_equal) " + + "FROM comparison_result " + + "GROUP BY submitter, item" + + ") " + + "SELECT V.submitter, V.item, if(V.vote = max_vote, 1, 0), V.vote " + + "FROM V, (" + + "SELECT V.item, MAX(V.vote) AS max_vote " + + "FROM V " + + "GROUP BY V.item" + + ") AS IV " + + "WHERE V.item = IV.item") + + //SQL = fmt.Sprintf() + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + rows, err := db.Query("SELECT submitter, item, score FROM score") + if err != nil{ + panic(err) + } + defer rows.Close() + for { + next_row := rows.Next() + if(!next_row){ + break + } + var ( + submitter string + item int + score int + ) + rows.Scan(&submitter, &item, &score) + subs[submitter].score[item] = score + } + // YOUR CODE END +} From e294c5a81a516c21cb98127a49e3de6d92f68e71 Mon Sep 17 00:00:00 2001 From: obangw <18307130116@fudan.edu.cn> Date: Wed, 1 Apr 2020 22:59:02 -0700 Subject: [PATCH 137/189] submission of obangw for ass1 --- assignments/ass1/submission/18307130116/7.sql | 4 +-- assignments/ass1/submission/18307130116/8.sql | 2 +- .../ass1/submission/18307130116/wb94364897 | 27 +++++++++++++++++++ .../submission/18307130116/wb94364897.pub | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 assignments/ass1/submission/18307130116/wb94364897 create mode 100644 assignments/ass1/submission/18307130116/wb94364897.pub diff --git a/assignments/ass1/submission/18307130116/7.sql b/assignments/ass1/submission/18307130116/7.sql index aba7afe..6453710 100644 --- a/assignments/ass1/submission/18307130116/7.sql +++ b/assignments/ass1/submission/18307130116/7.sql @@ -1,4 +1,4 @@ -SELECT DISTINCT id +SELECT DISTINCT book_id FROM book,record WHERE book.id = record.book_id AND record.time > '2016-10-31' -ORDER BY id +ORDER BY book_id diff --git a/assignments/ass1/submission/18307130116/8.sql b/assignments/ass1/submission/18307130116/8.sql index 6b33025..c17377b 100644 --- a/assignments/ass1/submission/18307130116/8.sql +++ b/assignments/ass1/submission/18307130116/8.sql @@ -3,4 +3,4 @@ FROM employee, record WHERE employee.id = record.employee_id GROUP BY id HAVING count(id) > 1 -ORDER BY num +ORDER BY num DESC diff --git a/assignments/ass1/submission/18307130116/wb94364897 b/assignments/ass1/submission/18307130116/wb94364897 new file mode 100644 index 0000000..a7ec325 --- /dev/null +++ b/assignments/ass1/submission/18307130116/wb94364897 @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAyGiL6o12qrgo2nFAnhFtrfIu3No05TDjvvbUJsRs7k7j7+uL +rDIOApMKJ7WqXa5+VEUMPBif0ayQcwZ6cX0CVy+FJoCb+kHPjmyrWxo6SBbeJol+ +M+PRtPaYcmJC9QdIwaKDsCJ7BgvjATTCJi1mHNgtfqv0R/l4yHrUuZvAaCE65v3e +ONayIb81JKeyMlfZJWUbW4RZKACh7H/0KS7FjdAO4Nr7EVkCDsg2S3ZhwCJ5lAZP +mQxRtZIe+F75RpLkJ2KcGtdRXtYXDDi5MNILv1rLbiQRik/udba8k9QT3Vb3Cy85 +TRmqXLDSb2fCctn+88GNqSFiAVp+BRrusoTYzwIDAQABAoIBAH+JoPk827cbicwy +ZKfzeXRIerBMIXt12IoP9MVTHeuuwvpNUU7db/MNdln9D5Wc1YJ1iqq4FQVPp4G8 +LrIIlzO65yawlBL4TMlbuNU6ZLq56thlia4mHq/meu/YPrpGz3ODJAE0gExBxk5f +L+sx2xkiLhm9/rDLP6V+HeCdER5yXoBwD8M59DhumoqoEGXXVsTFFaHO50SF3b8r +I9KJ1awxBQtVMCf19cUV8osZmgcU8I5RbKgB90q8g3zCvVBvXzl2Zu5VXUjRTUDD +oLvBWmgHmnTihP5EKN5VIb+Yp3TR173vcwi3CuJYLy8T9XuORQoCCKCCYgBxq/FV +hKqX73ECgYEA8Lrtv/tZJ7lUuMlQz18uLIrXZrolfcLAitNBgLVPLxnQUrIWm7r+ +9fMpc+6naqff9JQMjuw23Yx4/j6JrsdNF28MuqegMn3XIPMkfh5WOfnEz3Aum4On +oU59OZIcaLn1+r4r2tKKg9CLnLGytptTSFoEi2LFDyCzaRWhKvJ6mrkCgYEA1R7b +RjvolFr0zpx/T5qmu8IHPikMjSOHgtJCDEYan0xDWCeb0kcV71ap84Dnzh54xRka +3IoNPzJylrKdCQV7tMnt77XcTFFcnYmjtG55Zmif+vIQPGpehviAcuPMT3tXbmig +ilWL1RSse7zj1U7oJrwqjpse+6T/toURz3xFq8cCgYB2vk4eH9Z3cMSoraztzW5S +TF457uIlaZZeJBywZz7a5enLkMr0IEY5fatZ40OzqYEf/JNBQKVDnVHlX2W8z9Ro +Fb/6pkqv/UDLoQPELiSsTlbVV+m1jjh2qee9KSRYSDpcZ8fsFWR75renIEQeLPnk +u3p4Ysz/TEsTL7cjHx55CQKBgAQrQFrVXS1ZwiQwh4UFH3HYz891ehtgsIvslQIs +dOTc1wxoafHpFhLCfTyYLvCnQ/GHFjFuOegckoVEJTJB+zOEJ7Vit1Z+2PLz+FHV +P2azcT21cn/cDNFTFyAoOJztar5sKYfLOJsIdn9NKJ/JlVz8nVCA1FBT3/SwEbMf +WTWNAoGBAKpb0m9T7/+CcDyMNMe97RjALIf/kd6MVTazIIESS8rGnXr5S3nZULuO +obcVtvMENJyjgbXm2eBK3a+k0MlpOgvady0/8XIgLFOzTby2U79Szaqs7ExYXzQE +E/oC1xVrtHeH62K2qzN5qMR+YKiHOfpzJTy72E37Q00lFFAC/WiS +-----END RSA PRIVATE KEY----- diff --git a/assignments/ass1/submission/18307130116/wb94364897.pub b/assignments/ass1/submission/18307130116/wb94364897.pub new file mode 100644 index 0000000..f3b0df0 --- /dev/null +++ b/assignments/ass1/submission/18307130116/wb94364897.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIaIvqjXaquCjacUCeEW2t8i7c2jTlMOO+9tQmxGzuTuPv64usMg4Ckwontapdrn5URQw8GJ/RrJBzBnpxfQJXL4UmgJv6Qc+ObKtbGjpIFt4miX4z49G09phyYkL1B0jBooOwInsGC+MBNMImLWYc2C1+q/RH+XjIetS5m8BoITrm/d441rIhvzUkp7IyV9klZRtbhFkoAKHsf/QpLsWN0A7g2vsRWQIOyDZLdmHAInmUBk+ZDFG1kh74XvlGkuQnYpwa11Fe1hcMOLkw0gu/WstuJBGKT+51tryT1BPdVvcLLzlNGapcsNJvZ8Jy2f7zwY2pIWIBWn4FGu6yhNjP 18307130116@fudan.edu.cn From c626e44ecc2d4a4fb55b32518d067f019c655e0c Mon Sep 17 00:00:00 2001 From: obangw <18307130116@fudan.edu.cn> Date: Thu, 2 Apr 2020 01:01:59 -0700 Subject: [PATCH 138/189] update from upstream, start ass2 --- .../ass2/submission/18307130116/utils.go | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 assignments/ass2/submission/18307130116/utils.go diff --git a/assignments/ass2/submission/18307130116/utils.go b/assignments/ass2/submission/18307130116/utils.go new file mode 100644 index 0000000..bfad421 --- /dev/null +++ b/assignments/ass2/submission/18307130116/utils.go @@ -0,0 +1,105 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "sync" + "reflect" + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130116" // your student id, e.g. 18307130177 + SubmissionDir = "/home/musicode/Desktop/assignment2/IDBS-Spring20-Fudan-master/assignments/ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{}; + for submitter, sub := range subs{ + for comparer, sub2 := range subs { + wg.Add(1) + go func() { + for i:= 0; i < NumSQL; i++{ + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }() + } + wg.Wait() +} + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparison_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL = "INSERT INTO score(submitter, item, score, vote) WITH RESULT1 AS (SELECT submitter, item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item), RESULT2 AS (SELECT item, MAX(vote) AS item_max FROM RESULT1 GROUP BY item) SELECT submitter, RESULT1.item, (vote = item_max) AS score,vote FROM RESULT1, RESULT2 WHERE RESULT1.item = RESULT2.item" + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + rows, err := db.Query("SELECT * FROM score") + if err != nil { + panic(err) + } + db.Close() + var submitter string + var score, item, vote int + for rows.Next(){ + rows.Scan(&submitter, &item, &score, &vote) + subs[submitter].score[item] = score + } + // YOUR CODE END +} From 8930f68ebd78f8c1a03b5bad91f1ecdc364a19a2 Mon Sep 17 00:00:00 2001 From: obangw <55530826+obangw@users.noreply.github.com> Date: Thu, 2 Apr 2020 16:14:27 +0800 Subject: [PATCH 139/189] Delete wb94364897 --- .../ass1/submission/18307130116/wb94364897 | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 assignments/ass1/submission/18307130116/wb94364897 diff --git a/assignments/ass1/submission/18307130116/wb94364897 b/assignments/ass1/submission/18307130116/wb94364897 deleted file mode 100644 index a7ec325..0000000 --- a/assignments/ass1/submission/18307130116/wb94364897 +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAyGiL6o12qrgo2nFAnhFtrfIu3No05TDjvvbUJsRs7k7j7+uL -rDIOApMKJ7WqXa5+VEUMPBif0ayQcwZ6cX0CVy+FJoCb+kHPjmyrWxo6SBbeJol+ -M+PRtPaYcmJC9QdIwaKDsCJ7BgvjATTCJi1mHNgtfqv0R/l4yHrUuZvAaCE65v3e -ONayIb81JKeyMlfZJWUbW4RZKACh7H/0KS7FjdAO4Nr7EVkCDsg2S3ZhwCJ5lAZP -mQxRtZIe+F75RpLkJ2KcGtdRXtYXDDi5MNILv1rLbiQRik/udba8k9QT3Vb3Cy85 -TRmqXLDSb2fCctn+88GNqSFiAVp+BRrusoTYzwIDAQABAoIBAH+JoPk827cbicwy -ZKfzeXRIerBMIXt12IoP9MVTHeuuwvpNUU7db/MNdln9D5Wc1YJ1iqq4FQVPp4G8 -LrIIlzO65yawlBL4TMlbuNU6ZLq56thlia4mHq/meu/YPrpGz3ODJAE0gExBxk5f -L+sx2xkiLhm9/rDLP6V+HeCdER5yXoBwD8M59DhumoqoEGXXVsTFFaHO50SF3b8r -I9KJ1awxBQtVMCf19cUV8osZmgcU8I5RbKgB90q8g3zCvVBvXzl2Zu5VXUjRTUDD -oLvBWmgHmnTihP5EKN5VIb+Yp3TR173vcwi3CuJYLy8T9XuORQoCCKCCYgBxq/FV -hKqX73ECgYEA8Lrtv/tZJ7lUuMlQz18uLIrXZrolfcLAitNBgLVPLxnQUrIWm7r+ -9fMpc+6naqff9JQMjuw23Yx4/j6JrsdNF28MuqegMn3XIPMkfh5WOfnEz3Aum4On -oU59OZIcaLn1+r4r2tKKg9CLnLGytptTSFoEi2LFDyCzaRWhKvJ6mrkCgYEA1R7b -RjvolFr0zpx/T5qmu8IHPikMjSOHgtJCDEYan0xDWCeb0kcV71ap84Dnzh54xRka -3IoNPzJylrKdCQV7tMnt77XcTFFcnYmjtG55Zmif+vIQPGpehviAcuPMT3tXbmig -ilWL1RSse7zj1U7oJrwqjpse+6T/toURz3xFq8cCgYB2vk4eH9Z3cMSoraztzW5S -TF457uIlaZZeJBywZz7a5enLkMr0IEY5fatZ40OzqYEf/JNBQKVDnVHlX2W8z9Ro -Fb/6pkqv/UDLoQPELiSsTlbVV+m1jjh2qee9KSRYSDpcZ8fsFWR75renIEQeLPnk -u3p4Ysz/TEsTL7cjHx55CQKBgAQrQFrVXS1ZwiQwh4UFH3HYz891ehtgsIvslQIs -dOTc1wxoafHpFhLCfTyYLvCnQ/GHFjFuOegckoVEJTJB+zOEJ7Vit1Z+2PLz+FHV -P2azcT21cn/cDNFTFyAoOJztar5sKYfLOJsIdn9NKJ/JlVz8nVCA1FBT3/SwEbMf -WTWNAoGBAKpb0m9T7/+CcDyMNMe97RjALIf/kd6MVTazIIESS8rGnXr5S3nZULuO -obcVtvMENJyjgbXm2eBK3a+k0MlpOgvady0/8XIgLFOzTby2U79Szaqs7ExYXzQE -E/oC1xVrtHeH62K2qzN5qMR+YKiHOfpzJTy72E37Q00lFFAC/WiS ------END RSA PRIVATE KEY----- From 29df5d8e0c6453d7079cabd7286ea785bb6c8515 Mon Sep 17 00:00:00 2001 From: obangw <55530826+obangw@users.noreply.github.com> Date: Thu, 2 Apr 2020 16:14:38 +0800 Subject: [PATCH 140/189] Delete wb94364897.pub --- assignments/ass1/submission/18307130116/wb94364897.pub | 1 - 1 file changed, 1 deletion(-) delete mode 100644 assignments/ass1/submission/18307130116/wb94364897.pub diff --git a/assignments/ass1/submission/18307130116/wb94364897.pub b/assignments/ass1/submission/18307130116/wb94364897.pub deleted file mode 100644 index f3b0df0..0000000 --- a/assignments/ass1/submission/18307130116/wb94364897.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIaIvqjXaquCjacUCeEW2t8i7c2jTlMOO+9tQmxGzuTuPv64usMg4Ckwontapdrn5URQw8GJ/RrJBzBnpxfQJXL4UmgJv6Qc+ObKtbGjpIFt4miX4z49G09phyYkL1B0jBooOwInsGC+MBNMImLWYc2C1+q/RH+XjIetS5m8BoITrm/d441rIhvzUkp7IyV9klZRtbhFkoAKHsf/QpLsWN0A7g2vsRWQIOyDZLdmHAInmUBk+ZDFG1kh74XvlGkuQnYpwa11Fe1hcMOLkw0gu/WstuJBGKT+51tryT1BPdVvcLLzlNGapcsNJvZ8Jy2f7zwY2pIWIBWn4FGu6yhNjP 18307130116@fudan.edu.cn From 44e1db43c680a10e7d029af26020623ec5537d08 Mon Sep 17 00:00:00 2001 From: kleinercubs <1910481653@qq.com> Date: Thu, 2 Apr 2020 16:50:10 +0800 Subject: [PATCH 141/189] change 8.sql --- assignments/ass1/submission/18307130252/8.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/assignments/ass1/submission/18307130252/8.sql b/assignments/ass1/submission/18307130252/8.sql index a52d04d..524b739 100644 --- a/assignments/ass1/submission/18307130252/8.sql +++ b/assignments/ass1/submission/18307130252/8.sql @@ -1,7 +1,9 @@ +with X as( + select employee_id as id, count(*) as num + from record + group by employee_id) select employee.id, name, X.num -from employee left outer join ((select employee_id as id, count(*) as num - from record - group by employee_id) as X ) +from employee left outer join X on employee.id = X.id where X.num > 1 order by X.num desc; From 0d1b83dfdaf11a00390b8caac3546704ebeefbfd Mon Sep 17 00:00:00 2001 From: kleinercubs <1910481653@qq.com> Date: Thu, 2 Apr 2020 17:02:12 +0800 Subject: [PATCH 142/189] update from upstream, start ass2 --- .../ass2/submission/18307130252/utils.go | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 assignments/ass2/submission/18307130252/utils.go diff --git a/assignments/ass2/submission/18307130252/utils.go b/assignments/ass2/submission/18307130252/utils.go new file mode 100755 index 0000000..f731278 --- /dev/null +++ b/assignments/ass2/submission/18307130252/utils.go @@ -0,0 +1,142 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + "reflect" + "sync" + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130252" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "kleinercubs" // the user name to connect the database, e.g. root + Password = "kleinercubs" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + + type data struct { + sub string + cmp string + id int + same int + } + + bufferedChan := make(chan data, 128) + wg := sync.WaitGroup{} + + for thread := 0; thread < 16; thread++ { + wg.Add(1) + go func() { + defer wg.Done() + for tmp := range bufferedChan { + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", tmp.sub, tmp.cmp, tmp.id, tmp.same) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + }() + } + + wg.Add(1) + go func() { + defer wg.Done() + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + bufferedChan <- data{submitter, comparer, i + 1, equal} + } + } + } + close(bufferedChan) + }() + + wg.Wait() + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL = `INSERT INTO score + WITH RESULT AS( + SELECT submitter, item, count(is_equal) AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter, item + ) + SELECT submitter, item, IF (vote IN (SELECT MAX(Tmp.vote) FROM RESULT AS Tmp WHERE Tmp.item = RESULT.item), 1, 0),vote + FROM RESULT` + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + rows, err := db.Query("SELECT * FROM score") + + if err != nil { + panic(err) + } + + var submitter string + var item, score, vote int + + for rows.Next() { + rows.Scan(&submitter, &item, &score, &vote) + subs[submitter].score[item] = score + } + + // YOUR CODE END +} From 0af49830703b7f79bc2341525d20b080bd425550 Mon Sep 17 00:00:00 2001 From: kleinercubs <1910481653@qq.com> Date: Thu, 2 Apr 2020 17:03:30 +0800 Subject: [PATCH 143/189] update from upstream, start ass2 --- assignments/ass1/submission/18307130252/8.sql | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/assignments/ass1/submission/18307130252/8.sql b/assignments/ass1/submission/18307130252/8.sql index 524b739..a52d04d 100644 --- a/assignments/ass1/submission/18307130252/8.sql +++ b/assignments/ass1/submission/18307130252/8.sql @@ -1,9 +1,7 @@ -with X as( - select employee_id as id, count(*) as num - from record - group by employee_id) select employee.id, name, X.num -from employee left outer join X +from employee left outer join ((select employee_id as id, count(*) as num + from record + group by employee_id) as X ) on employee.id = X.id where X.num > 1 order by X.num desc; From ddc959d27653878da1edc7993c835aa74f4f4ca5 Mon Sep 17 00:00:00 2001 From: YinxuanH <18307130340@fudan.edu.cn> Date: Thu, 2 Apr 2020 19:48:22 +0800 Subject: [PATCH 144/189] submission of 18307130340 for ass2 --- .../ass2/submission/18307130340/utils.go | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/assignments/ass2/submission/18307130340/utils.go b/assignments/ass2/submission/18307130340/utils.go index 7b8b5b9..d1db359 100644 --- a/assignments/ass2/submission/18307130340/utils.go +++ b/assignments/ass2/submission/18307130340/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130340" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "hyx" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,34 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + go func(submitter, comparer string, sub, sub2 *Submission) { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }(submitter, comparer, sub, sub2) + } + wg.Wait() + } // YOUR CODE END } @@ -55,13 +83,33 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = "INSERT INTO score (submitter, item, score, vote) " + + "SELECT DISTINCT X.submitter, X.item, is_equal, vote " + + "FROM comparison_result, " + + "(SELECT submitter, item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item) AS X, " + + "(SELECT item, MAX(vote) AS max " + + "FROM (SELECT submitter, item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item) AS Z " + + "Group by item) AS Y " + + "WHERE comparison_result.submitter = X.submitter AND comparison_result.item = X.item AND X.item = Y.item " + + "AND ((vote = max AND is_equal = 1) OR (vote <> max AND is_equal = 0));" // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + rows, err := db.Query("SELECT submitter, item, score FROM score") + if err != nil { + panic(err) + } + for rows.Next() { + var submitter string + var item, score int + err = rows.Scan(&submitter, &item, &score) + if err != nil { + panic(err) + } + subs[submitter].score[item] = score + } // YOUR CODE END } From d82f9ba1cd55ff61980053e80e2c338000addf38 Mon Sep 17 00:00:00 2001 From: lilili2000 <62167504+lilili2000@users.noreply.github.com> Date: Thu, 2 Apr 2020 20:38:49 +0800 Subject: [PATCH 145/189] Update utils.go --- assignments/ass2/evaluator/utils.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assignments/ass2/evaluator/utils.go b/assignments/ass2/evaluator/utils.go index b8412f4..7b8b5b9 100644 --- a/assignments/ass2/evaluator/utils.go +++ b/assignments/ass2/evaluator/utils.go @@ -14,10 +14,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "18307130297" // your student id, e.g. 18307130177 - SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "root" // the user name to connect the database, e.g. root - Password = "123456" // the password for the user name, e.g. xxx + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx // YOUR CODE END ) From 88b4e8832cea80a8de4f593249f7d5aafdb23cc2 Mon Sep 17 00:00:00 2001 From: xhs7700 Date: Thu, 2 Apr 2020 22:49:11 +0800 Subject: [PATCH 146/189] update from upstream, start ass2 --- .../ass2/submission/18307130090/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130090/utils.go diff --git a/assignments/ass2/submission/18307130090/utils.go b/assignments/ass2/submission/18307130090/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130090/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From f68cbe4487c52ed70fa36a9d04ee2aabd98c360a Mon Sep 17 00:00:00 2001 From: daihuasheng <18307130123@fudan.edu.cn> Date: Fri, 3 Apr 2020 00:44:42 +0800 Subject: [PATCH 147/189] update from upstream, start ass2 --- .../ass2/submission/18307130123/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130123/utils.go diff --git a/assignments/ass2/submission/18307130123/utils.go b/assignments/ass2/submission/18307130123/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130123/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From e46f274cd41434e013ab3ffb7264ebd9264fc6ee Mon Sep 17 00:00:00 2001 From: bblss123 Date: Fri, 3 Apr 2020 00:48:03 +0800 Subject: [PATCH 148/189] update from upstream, start ass2 --- .../ass2/submission/18307130102/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130102/utils.go diff --git a/assignments/ass2/submission/18307130102/utils.go b/assignments/ass2/submission/18307130102/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130102/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 99054fc5975d75681dba8220d46aa0714317fbdc Mon Sep 17 00:00:00 2001 From: bblss123 Date: Fri, 3 Apr 2020 00:51:05 +0800 Subject: [PATCH 149/189] submission of 18307130102 for ass2 --- .../ass2/submission/18307130102/utils.go | 77 +++++++++++++++++-- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/assignments/ass2/submission/18307130102/utils.go b/assignments/ass2/submission/18307130102/utils.go index 7b8b5b9..eb9f985 100644 --- a/assignments/ass2/submission/18307130102/utils.go +++ b/assignments/ass2/submission/18307130102/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130102" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,39 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if(err != nil){ + panic(nil) + } + db.SetMaxOpenConns(50) + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + go func(submitter string, comparer string, sub *Submission, sub2 *Submission){ + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }(submitter, comparer, sub, sub2) + } + } + wg.Wait() + //time.Sleep(10000 * time.Millisecond) + //fmt.Println("emmm") // YOUR CODE END } @@ -55,13 +88,41 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - - // YOUR CODE END + SQL = `INSERT INTO score + WITH X AS ( + SELECT submitter, item, SUM(is_equal) AS vote FROM comparison_result as C + GROUP BY submitter, item + ), Z AS ( + SELECT item, MAX(vote) as mx from X + GROUP BY item + ), Y AS + ( + SELECT X.submitter, X.item, CASE WHEN Z.mx = X.vote THEN 1 ELSE 0 END AS score FROM X, Z + WHERE X.item = Z.item + ) + SELECT submitter, item, score, vote FROM (SELECT * FROM X JOIN Y USING (submitter, item)) AS S` return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + for i:= 1; i <= NumSQL; i++{ + for submitter, sub := range subs{ + rows, err := db.Query("SELECT score FROM score WHERE submitter = ? AND item = ?", submitter, i) + if err != nil{ + panic(err) + } + var cnt int = 0 + var scr int + for rows.Next(){ + cnt++ + rows.Scan(&scr) + } + if(cnt != 1){ + panic("The table score has something wrong.") + } + sub.score[i] = scr + } + } // YOUR CODE END } From a4290c572644672a29180d86400bb18eb1122f37 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Fri, 3 Apr 2020 02:51:50 +0800 Subject: [PATCH 150/189] Implement ConcurrentCompareAndInsert --- .../ass2/submission/18307130003/utils.go | 58 ++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/assignments/ass2/submission/18307130003/utils.go b/assignments/ass2/submission/18307130003/utils.go index 4de7e8a..1f69ea6 100644 --- a/assignments/ass2/submission/18307130003/utils.go +++ b/assignments/ass2/submission/18307130003/utils.go @@ -2,12 +2,10 @@ package main import ( "fmt" + "reflect" + "sync" "time" - // YOUR CODE BEGIN - - // YOUR CODE END - _ "github.com/go-sql-driver/mysql" sql "github.com/jmoiron/sqlx" ) @@ -17,9 +15,9 @@ var ( EvaluatorID = "18307130003" // SubmissionDir is the relative path of the submission directory of assignment 1 SubmissionDir = "../../../ass1/submission/" - // User is the user name to connect the database + // User is the username used to connect to the database User = "root" - // Password is the password for the user name + // Password for the username Password = "Hakula" ) @@ -27,7 +25,7 @@ var ( func ConcurrentCompareAndInsert(subs map[string]*Submission) { start := time.Now() defer func() { - db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(localhost:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) if err != nil { panic(nil) } @@ -46,8 +44,52 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { } fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() - // YOUR CODE BEGIN + // Connect to the database + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(localhost:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + db.SetMaxOpenConns(64) + db.SetMaxIdleConns(16) + + type query struct { + sid string // the ID of submitter + cid string // the ID of comparer + qid int // the ID of SQL query + res int // the result of comparison + } + + // Insert results into the database + insert := func(q query) { + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", q.sid, q.cid, q.qid, q.res) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + + // Check if the answers are correct + var wg sync.WaitGroup + for sid, submitter := range subs { + for cid, comparer := range subs { + wg.Add(1) + go func(sid, cid string, submitter, comparer *Submission) { + for i := 0; i < NumSQL; i++ { + var res int + if reflect.DeepEqual(submitter.sqlResults[i], comparer.sqlResults[i]) { + res = 1 + } else { + res = 0 + } + insert(query{sid, cid, i + 1, res}) + } + wg.Done() + }(sid, cid, submitter, comparer) + } + } + wg.Wait() // YOUR CODE END } From 5031dd8daa132dd12a24cfc04b06a3e1faef7d57 Mon Sep 17 00:00:00 2001 From: xhs7700 Date: Fri, 3 Apr 2020 03:08:41 +0800 Subject: [PATCH 151/189] submission of 18307130090 for ass2 --- .../ass2/submission/18307130090/utils.go | 51 ++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/assignments/ass2/submission/18307130090/utils.go b/assignments/ass2/submission/18307130090/utils.go index 7b8b5b9..9b6730c 100644 --- a/assignments/ass2/submission/18307130090/utils.go +++ b/assignments/ass2/submission/18307130090/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,9 +15,9 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root + EvaluatorID = "18307130090" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root Password = "" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,30 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg:=sync.WaitGroup{} + for submitter,sub :=range subs{ + wg.Add(1) + go func(submitter string,sub *Submission){ + for comparer,sub2 :=range subs{ + for i:=0;i=all(select vote from tmp as x where x.item=y.item),vote from tmp as y;` // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + for submitter,sub:=range subs{ + for i:=1;i Date: Fri, 3 Apr 2020 03:22:17 +0800 Subject: [PATCH 152/189] Implement GetScore --- .../ass2/submission/18307130003/utils.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/assignments/ass2/submission/18307130003/utils.go b/assignments/ass2/submission/18307130003/utils.go index 1f69ea6..f95d193 100644 --- a/assignments/ass2/submission/18307130003/utils.go +++ b/assignments/ass2/submission/18307130003/utils.go @@ -90,7 +90,6 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { } } wg.Wait() - // YOUR CODE END } // GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table @@ -106,7 +105,17 @@ func GetScoreSQL() string { // GetScore reads your score from table `score` func GetScore(db *sql.DB, subs map[string]*Submission) { - // YOUR CODE BEGIN - - // YOUR CODE END + rows, err := db.Query("SELECT submitter, item, score FROM score") + if err != nil { + panic(err) + } + for rows.Next() { + var sid string + var qid, score int + err := rows.Scan(&sid, &qid, &score) + if err != nil { + panic(err) + } + subs[sid].score[qid] = score + } } From 53203af225cc2c91b1c60655ba16f7f82ce238f9 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Fri, 3 Apr 2020 04:41:10 +0800 Subject: [PATCH 153/189] Implement GetScoreSQL --- .../ass2/submission/18307130003/utils.go | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/assignments/ass2/submission/18307130003/utils.go b/assignments/ass2/submission/18307130003/utils.go index f95d193..fb1b30d 100644 --- a/assignments/ass2/submission/18307130003/utils.go +++ b/assignments/ass2/submission/18307130003/utils.go @@ -96,10 +96,37 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { // `comparision_result` and inserts the score of each submitter on each query into table `score` func GetScoreSQL() string { var SQL string - SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. - // YOUR CODE BEGIN - - // YOUR CODE END + SQL = ` +INSERT INTO + score +WITH submitter_votes AS ( + SELECT + submitter, + item, + SUM(is_equal) AS vote + FROM + comparison_result + GROUP BY + submitter, + item +), +grading_standard AS ( + SELECT + item, + MAX(vote) AS max_vote + FROM + submitter_votes + GROUP BY + item +) +SELECT + submitter, + item, + IF(vote = max_vote, 1, 0) AS score, + vote +FROM + submitter_votes + JOIN grading_standard USING(item);` return SQL } @@ -109,6 +136,7 @@ func GetScore(db *sql.DB, subs map[string]*Submission) { if err != nil { panic(err) } + defer db.Close() for rows.Next() { var sid string var qid, score int From 890806e8f520ae6359be26cbc819f971f66e22e8 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Fri, 3 Apr 2020 04:46:27 +0800 Subject: [PATCH 154/189] Change to initial address --- assignments/ass2/submission/18307130003/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assignments/ass2/submission/18307130003/utils.go b/assignments/ass2/submission/18307130003/utils.go index fb1b30d..c41626d 100644 --- a/assignments/ass2/submission/18307130003/utils.go +++ b/assignments/ass2/submission/18307130003/utils.go @@ -25,7 +25,7 @@ var ( func ConcurrentCompareAndInsert(subs map[string]*Submission) { start := time.Now() defer func() { - db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(localhost:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) if err != nil { panic(nil) } @@ -46,7 +46,7 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { }() // Connect to the database - db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(localhost:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) if err != nil { panic(err) } From 4f8fa1c8f0ea08d56826ffe471aa2c6d44ccaf84 Mon Sep 17 00:00:00 2001 From: xiaoas Date: Fri, 3 Apr 2020 11:41:03 +0800 Subject: [PATCH 155/189] update from upstream, start ass2 --- .../ass2/submission/18307130027/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130027/utils.go diff --git a/assignments/ass2/submission/18307130027/utils.go b/assignments/ass2/submission/18307130027/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130027/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From d58a93302b539db767babd7d38bc38ef1b30c087 Mon Sep 17 00:00:00 2001 From: moyiii-ai <19307130296@fudan.edu.cn> Date: Fri, 3 Apr 2020 11:49:02 +0800 Subject: [PATCH 156/189] sumbission of 19307130296 for ass2 --- .../ass2/submission/19307130296/utils.go | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 assignments/ass2/submission/19307130296/utils.go diff --git a/assignments/ass2/submission/19307130296/utils.go b/assignments/ass2/submission/19307130296/utils.go new file mode 100644 index 0000000..572e2a1 --- /dev/null +++ b/assignments/ass2/submission/19307130296/utils.go @@ -0,0 +1,141 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "reflect" + "sync" + // YOUR CODE END + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "19307130296" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "orz" // the user name to connect the database, e.g. root + Password = "123" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + check := func(err error) { + if(err != nil) { + panic(err) + } + } + + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + check(err) + stmt, err := db.Preparex("INSERT INTO comparison_result VALUES (?,?,?,?)") + check(err) + defer stmt.Close() + + type node struct { + submitter string + comparer string + item int + is_equal int + } + ch := make(chan node, 20) + + var w sync.WaitGroup + solve := func() { + defer w.Done() + for temp := range ch { + _, err := stmt.Exec(temp.submitter, temp.comparer, temp.item, temp.is_equal) + check(err) + } + } + + for i := 0; i < 50; i++ { + w.Add(1) + go solve() + } + + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + ch <- node{submitter, comparer, i + 1, equal} + } + } + } + + close(ch) + w.Wait() + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL =`INSERT INTO score + (WITH scoreCTE (submitter,item,vote) AS ( + SELECT distinct submitter, item, SUM(is_equal) + FROM comparison_result + GROUP BY submitter, item + ) + ((SELECT submitter, item, '1' AS score, vote + FROM scoreCTE AS X + WHERE vote=(SELECT MAX(vote) + FROM scoreCTE AS Y + WHERE Y.item=X.item)) + UNION + (SELECT submitter, item, '0' AS score, vote + FROM scoreCTE AS X + WHERE vote!=(SELECT MAX(vote) + FROM scoreCTE AS Y + WHERE Y.item=X.item))))` + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + rows, err := db.Query("SELECT submitter, item, score From score") + if err != nil { + panic(err) + } + var item, score int + var submitter string + for rows.Next() { + rows.Scan(&submitter, &item, &score) + subs[submitter].score[item] = score + } + // YOUR CODE END +} From 4fc78c164058f9680a221d4266cade1facc5cbb4 Mon Sep 17 00:00:00 2001 From: xudinghuan <18307130031@fudan.edu.cn> Date: Fri, 3 Apr 2020 00:04:56 -0700 Subject: [PATCH 157/189] submission of 18307130031 for ass2 --- .../ass2/submission/18307130031/utils.go | 112 +++++++++++++++++- 1 file changed, 106 insertions(+), 6 deletions(-) diff --git a/assignments/ass2/submission/18307130031/utils.go b/assignments/ass2/submission/18307130031/utils.go index 7b8b5b9..100a707 100644 --- a/assignments/ass2/submission/18307130031/utils.go +++ b/assignments/ass2/submission/18307130031/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130031" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "xudinghuan" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,16 +46,104 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil{ + fmt.Println("fail to connect database") + panic(err) + } + + stmt, err := db.Prepare("INSERT INTO comparison_result VALUES (?,?,?,?)") + if err != nil{ + fmt.Println("fail to prepare statement") + panic(err) + } + + + var wg sync.WaitGroup + const num = 35 + + type result struct{ + submitter string + comparer string + item int + is_equal int + } + + ch := make(chan result, num) + + job := func(){ + tx, err := db.Begin() + if err != nil{ + fmt.Println("fail to initialize transaction") + panic(err) + } + + exec := tx.Stmt(stmt) + defer func(){ + err := tx.Commit() + if err != nil{ + fmt.Println("fail to commit transaction") + panic(err) + } + }() + + for i := range ch{ + _, err := exec.Exec(i.submitter, i.comparer, i.item, i.is_equal) + if err != nil{ + fmt.Println("fail to perform insertions") + panic(err) + } + } + + wg.Done() + exec.Close() + } + + for i := 0; i < num; i++{ + wg.Add(1) + go job() + } + + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + + ch <- result{submitter, comparer, i + 1, equal} + } + } + } + close(ch) + + wg.Wait() + // YOUR CODE END } - + // GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table // `comparision_result` and inserts the score of each submitter on each query into table `score` func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL = `INSERT INTO score + WITH onenum AS(SELECT submitter, item, COUNT(comparer) AS vote + FROM comparison_result + WHERE is_equal = '1' + GROUP BY submitter, item), + standard AS(SELECT item, MAX(vote) AS highest + FROM onenum GROUP BY item) + SELECT submitter, onenum.item, IF(vote = highest, 1, 0) AS score, vote + FROM onenum, standard + WHERE onenum.item = standard.item + ORDER BY onenum.item` + // YOUR CODE END return SQL @@ -62,6 +151,17 @@ func GetScoreSQL() string { func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN + rows, err := db.Query("SELECT submitter, item, score FROM score") + if err != nil{ + panic(err) + } + + for rows.Next() { + var submitter string + var item, score int + rows.Scan(&submitter, &item, &score) + subs[submitter].score[item] = score + } // YOUR CODE END } From ed8bc9ccf0c5fb1c6c3e3e198183873e47af9ff7 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:22:49 +0800 Subject: [PATCH 158/189] Add files via upload --- 1.sql | 3 ++ 2.sql | 3 ++ 3.sql | 4 ++ 4.sql | 4 ++ 5.sql | 3 ++ 6.sql | 3 ++ 7.sql | 4 ++ 8.sql | 6 +++ create_table.sql | 19 ++++++++ utils.go | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 159 insertions(+) create mode 100644 1.sql create mode 100644 2.sql create mode 100644 3.sql create mode 100644 4.sql create mode 100644 5.sql create mode 100644 6.sql create mode 100644 7.sql create mode 100644 8.sql create mode 100644 create_table.sql create mode 100644 utils.go diff --git a/1.sql b/1.sql new file mode 100644 index 0000000..6f073ee --- /dev/null +++ b/1.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name='Jones'; diff --git a/2.sql b/2.sql new file mode 100644 index 0000000..02b2d99 --- /dev/null +++ b/2.sql @@ -0,0 +1,3 @@ +SELECT name +FROM employee +WHERE id=1 OR id=2; diff --git a/3.sql b/3.sql new file mode 100644 index 0000000..21e9699 --- /dev/null +++ b/3.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE id<>1 +ORDER BY id ASC; diff --git a/4.sql b/4.sql new file mode 100644 index 0000000..862f031 --- /dev/null +++ b/4.sql @@ -0,0 +1,4 @@ +SELECT name +FROM employee +WHERE age BETWEEN 25 AND 30 +ORDER BY id ASC; diff --git a/5.sql b/5.sql new file mode 100644 index 0000000..248afdb --- /dev/null +++ b/5.sql @@ -0,0 +1,3 @@ +SELECT * +FROM employee +WHERE name LIKE 'J%'; diff --git a/6.sql b/6.sql new file mode 100644 index 0000000..79f4172 --- /dev/null +++ b/6.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT publisher +FROM book +ORDER BY publisher; diff --git a/7.sql b/7.sql new file mode 100644 index 0000000..f157c18 --- /dev/null +++ b/7.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT book_id +FROM record +WHERE time > '2016-10-31' +ORDER BY book_id; diff --git a/8.sql b/8.sql new file mode 100644 index 0000000..abab13c --- /dev/null +++ b/8.sql @@ -0,0 +1,6 @@ +SELECT DISTINCT id,name,COUNT(*) AS num +FROM employee,record +WHERE employee.id=record.employee_id +GROUP BY id + HAVING num > 1 +ORDER BY num desc; diff --git a/create_table.sql b/create_table.sql new file mode 100644 index 0000000..c97e986 --- /dev/null +++ b/create_table.sql @@ -0,0 +1,19 @@ +CREATE TABLE employee ( id INT NOT NULL, + name VARCHAR(32) NOT NULL, + office VARCHAR(32) NOT NULL, + age SMALLINT NOT NULL, + PRIMARY KEY(id), + CHECK(age BETWEEN 0 AND 100)); + +CREATE TABLE book ( id INT NOT NULL, + name VARCHAR(32) NOT NULL, + author VARCHAR(32) NOT NULL, + publisher VARCHAR(32) NOT NULL, + PRIMARY KEY(id)); + +CREATE TABLE record ( book_id INT NOT NULL, + employee_id INT NOT NULL, + time DATE NOT NULL, + FOREIGN KEY(book_id) REFERENCES book(id), + FOREIGN KEY(employee_id) REFERENCES employee(id), + PRIMARY KEY(book_id,employee_id)); diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..78711f5 --- /dev/null +++ b/utils.go @@ -0,0 +1,110 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "reflect" + "sync" + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130213" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + wg.Add(1) + go func(s string) { + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + wg.Done(); + }(s) + + } + wg.Wait(); + } + } + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL="INSERT INTO score(submitter, item, score, vote) "+ +"(SELECT submitter, MVT.item, IF(VT.vote >= MVT.maxv,1,0) AS score, vote "+ +"FROM ( SELECT submitter, item, SUM(is_equal) as vote FROM comparison_result GROUP BY submitter, item) AS VT, ( SELECT VT.item, MAX(VT.vote) AS maxv FROM ( SELECT submitter, item, SUM(is_equal) as vote FROM comparison_result GROUP BY submitter, item) AS VT GROUP BY VT.item) AS MVT "+ +"WHERE VT.item=MVT.item AND VT.vote=MVT.maxv);" + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + for submitter,sub:=range subs{ + for i:=0;i Date: Fri, 3 Apr 2020 15:23:23 +0800 Subject: [PATCH 159/189] Delete 1.sql --- 1.sql | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 1.sql diff --git a/1.sql b/1.sql deleted file mode 100644 index 6f073ee..0000000 --- a/1.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT * -FROM employee -WHERE name='Jones'; From 46c04170f6c9bfa06a5568468f115f8b6734f243 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:23:44 +0800 Subject: [PATCH 160/189] Delete 2.sql --- 2.sql | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 2.sql diff --git a/2.sql b/2.sql deleted file mode 100644 index 02b2d99..0000000 --- a/2.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT name -FROM employee -WHERE id=1 OR id=2; From 81a99e98cdc692af4217a53f48b5f5451f0499d4 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:23:59 +0800 Subject: [PATCH 161/189] Delete 3.sql --- 3.sql | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 3.sql diff --git a/3.sql b/3.sql deleted file mode 100644 index 21e9699..0000000 --- a/3.sql +++ /dev/null @@ -1,4 +0,0 @@ -SELECT name -FROM employee -WHERE id<>1 -ORDER BY id ASC; From 0bc39724b9f3dacadb5262c2801d8fe46ad98664 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:24:12 +0800 Subject: [PATCH 162/189] Delete 4.sql --- 4.sql | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 4.sql diff --git a/4.sql b/4.sql deleted file mode 100644 index 862f031..0000000 --- a/4.sql +++ /dev/null @@ -1,4 +0,0 @@ -SELECT name -FROM employee -WHERE age BETWEEN 25 AND 30 -ORDER BY id ASC; From 8aa24df4c195cae27874c116a839b634b900f764 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:24:23 +0800 Subject: [PATCH 163/189] Delete 5.sql --- 5.sql | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 5.sql diff --git a/5.sql b/5.sql deleted file mode 100644 index 248afdb..0000000 --- a/5.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT * -FROM employee -WHERE name LIKE 'J%'; From 2416db45acce7676d823537c59de4b21b4c3d858 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:24:35 +0800 Subject: [PATCH 164/189] Delete 6.sql --- 6.sql | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 6.sql diff --git a/6.sql b/6.sql deleted file mode 100644 index 79f4172..0000000 --- a/6.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT DISTINCT publisher -FROM book -ORDER BY publisher; From e30f6052ce80eee06146c5fd29d0a09271716291 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:24:48 +0800 Subject: [PATCH 165/189] Delete 7.sql --- 7.sql | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 7.sql diff --git a/7.sql b/7.sql deleted file mode 100644 index f157c18..0000000 --- a/7.sql +++ /dev/null @@ -1,4 +0,0 @@ -SELECT DISTINCT book_id -FROM record -WHERE time > '2016-10-31' -ORDER BY book_id; From 96f7b50139c2e7ce46992a4a7bd9ce72c51ace65 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:25:03 +0800 Subject: [PATCH 166/189] Delete 8.sql --- 8.sql | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 8.sql diff --git a/8.sql b/8.sql deleted file mode 100644 index abab13c..0000000 --- a/8.sql +++ /dev/null @@ -1,6 +0,0 @@ -SELECT DISTINCT id,name,COUNT(*) AS num -FROM employee,record -WHERE employee.id=record.employee_id -GROUP BY id - HAVING num > 1 -ORDER BY num desc; From 11092cf9feebe985c98803aa2da42e109eba177b Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:25:17 +0800 Subject: [PATCH 167/189] Delete utils.go --- utils.go | 110 ------------------------------------------------------- 1 file changed, 110 deletions(-) delete mode 100644 utils.go diff --git a/utils.go b/utils.go deleted file mode 100644 index 78711f5..0000000 --- a/utils.go +++ /dev/null @@ -1,110 +0,0 @@ -package main - -import ( - "fmt" - "time" - - // YOUR CODE BEGIN remove the follow packages if you don't need them - "reflect" - "sync" - // YOUR CODE END - - _ "github.com/go-sql-driver/mysql" - sql "github.com/jmoiron/sqlx" -) - -var ( - // YOUR CODE BELOW - EvaluatorID = "18307130213" // your student id, e.g. 18307130177 - SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "root" // the user name to connect the database, e.g. root - Password = "123456" // the password for the user name, e.g. xxx - // YOUR CODE END -) - -// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! -func ConcurrentCompareAndInsert(subs map[string]*Submission) { - start := time.Now() - defer func() { - db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) - if err != nil { - panic(nil) - } - rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") - if err != nil { - panic(err) - } - rows.Next() - var cnt int - err = rows.Scan(&cnt) - if err != nil { - panic(err) - } - if cnt == 0 { - panic("ConcurrentCompareAndInsert Not Implemented") - } - fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) - }() - // YOUR CODE BEGIN - db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) - if err != nil { - panic(err) - } - wg := sync.WaitGroup{} - for submitter, sub := range subs { - for comparer, sub2 := range subs { - - for i := 0; i < NumSQL; i++ { - var equal int - if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { - equal = 1 - } else { - equal = 0 - } - s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) - wg.Add(1) - go func(s string) { - _, err := db.Exec(s) - if err != nil { - fmt.Println(s) - panic(err) - } - wg.Done(); - }(s) - - } - wg.Wait(); - } - } - // YOUR CODE END -} - -// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table -// `comparision_result` and inserts the score of each submitter on each query into table `score` -func GetScoreSQL() string { - var SQL string - SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. - // YOUR CODE BEGIN - SQL="INSERT INTO score(submitter, item, score, vote) "+ -"(SELECT submitter, MVT.item, IF(VT.vote >= MVT.maxv,1,0) AS score, vote "+ -"FROM ( SELECT submitter, item, SUM(is_equal) as vote FROM comparison_result GROUP BY submitter, item) AS VT, ( SELECT VT.item, MAX(VT.vote) AS maxv FROM ( SELECT submitter, item, SUM(is_equal) as vote FROM comparison_result GROUP BY submitter, item) AS VT GROUP BY VT.item) AS MVT "+ -"WHERE VT.item=MVT.item AND VT.vote=MVT.maxv);" - // YOUR CODE END - return SQL -} - -func GetScore(db *sql.DB, subs map[string]*Submission) { - // YOUR CODE BEGIN - for submitter,sub:=range subs{ - for i:=0;i Date: Fri, 3 Apr 2020 15:25:30 +0800 Subject: [PATCH 168/189] Delete create_table.sql --- create_table.sql | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 create_table.sql diff --git a/create_table.sql b/create_table.sql deleted file mode 100644 index c97e986..0000000 --- a/create_table.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE TABLE employee ( id INT NOT NULL, - name VARCHAR(32) NOT NULL, - office VARCHAR(32) NOT NULL, - age SMALLINT NOT NULL, - PRIMARY KEY(id), - CHECK(age BETWEEN 0 AND 100)); - -CREATE TABLE book ( id INT NOT NULL, - name VARCHAR(32) NOT NULL, - author VARCHAR(32) NOT NULL, - publisher VARCHAR(32) NOT NULL, - PRIMARY KEY(id)); - -CREATE TABLE record ( book_id INT NOT NULL, - employee_id INT NOT NULL, - time DATE NOT NULL, - FOREIGN KEY(book_id) REFERENCES book(id), - FOREIGN KEY(employee_id) REFERENCES employee(id), - PRIMARY KEY(book_id,employee_id)); From e99760d0ed3c2dd7b8606e4708ebd18e8eb5cc4e Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:26:28 +0800 Subject: [PATCH 169/189] Add files via upload --- assignments/ass1/submission/18307130213/7.sql | 8 ++++---- assignments/ass1/submission/18307130213/8.sql | 2 +- assignments/ass1/submission/18307130213/create_table.sql | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/assignments/ass1/submission/18307130213/7.sql b/assignments/ass1/submission/18307130213/7.sql index d7f737b..f157c18 100644 --- a/assignments/ass1/submission/18307130213/7.sql +++ b/assignments/ass1/submission/18307130213/7.sql @@ -1,4 +1,4 @@ -SELECT DISTINCT id -FROM book,record -WHERE book.id = record.book_id AND record.time > 2016-10-31 -ORDER BY id ASC; +SELECT DISTINCT book_id +FROM record +WHERE time > '2016-10-31' +ORDER BY book_id; diff --git a/assignments/ass1/submission/18307130213/8.sql b/assignments/ass1/submission/18307130213/8.sql index dd8aefe..abab13c 100644 --- a/assignments/ass1/submission/18307130213/8.sql +++ b/assignments/ass1/submission/18307130213/8.sql @@ -3,4 +3,4 @@ FROM employee,record WHERE employee.id=record.employee_id GROUP BY id HAVING num > 1 -ORDER BY num DESC; +ORDER BY num desc; diff --git a/assignments/ass1/submission/18307130213/create_table.sql b/assignments/ass1/submission/18307130213/create_table.sql index 90a4fc0..c97e986 100644 --- a/assignments/ass1/submission/18307130213/create_table.sql +++ b/assignments/ass1/submission/18307130213/create_table.sql @@ -9,7 +9,7 @@ CREATE TABLE book ( id INT NOT NULL, name VARCHAR(32) NOT NULL, author VARCHAR(32) NOT NULL, publisher VARCHAR(32) NOT NULL, - PRIMARY KEY(ID)); + PRIMARY KEY(id)); CREATE TABLE record ( book_id INT NOT NULL, employee_id INT NOT NULL, From d84ba8c6415c757abbcb5aaae6c65d527dff9713 Mon Sep 17 00:00:00 2001 From: Pryest <54388244+Pryest@users.noreply.github.com> Date: Fri, 3 Apr 2020 15:27:12 +0800 Subject: [PATCH 170/189] Add files via upload --- .../ass2/submission/18307130213/utils.go | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/assignments/ass2/submission/18307130213/utils.go b/assignments/ass2/submission/18307130213/utils.go index 7b8b5b9..78711f5 100644 --- a/assignments/ass2/submission/18307130213/utils.go +++ b/assignments/ass2/submission/18307130213/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "reflect" + "sync" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130213" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,36 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + wg.Add(1) + go func(s string) { + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + wg.Done(); + }(s) + + } + wg.Wait(); + } + } // YOUR CODE END } @@ -55,13 +85,26 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL="INSERT INTO score(submitter, item, score, vote) "+ +"(SELECT submitter, MVT.item, IF(VT.vote >= MVT.maxv,1,0) AS score, vote "+ +"FROM ( SELECT submitter, item, SUM(is_equal) as vote FROM comparison_result GROUP BY submitter, item) AS VT, ( SELECT VT.item, MAX(VT.vote) AS maxv FROM ( SELECT submitter, item, SUM(is_equal) as vote FROM comparison_result GROUP BY submitter, item) AS VT GROUP BY VT.item) AS MVT "+ +"WHERE VT.item=MVT.item AND VT.vote=MVT.maxv);" // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + for submitter,sub:=range subs{ + for i:=0;i Date: Fri, 3 Apr 2020 15:29:37 +0800 Subject: [PATCH 171/189] Add files via upload From f4f47d8cc0f67e46dcd9212b7123596be4299f73 Mon Sep 17 00:00:00 2001 From: 18307130266-wangxinyi <18307130266@fudan.edu.cn> Date: Fri, 3 Apr 2020 15:52:28 +0800 Subject: [PATCH 172/189] update from upstream,start ass2 --- .../ass2/submission/18307130266/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/18307130266/utils.go diff --git a/assignments/ass2/submission/18307130266/utils.go b/assignments/ass2/submission/18307130266/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/18307130266/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From 7d4caf8ad2b2c2506baaf754b8b38a62e049948e Mon Sep 17 00:00:00 2001 From: 18307130128-yanghang <18307130128@fudan.edu.cn> Date: Fri, 3 Apr 2020 16:39:28 +0800 Subject: [PATCH 173/189] submission of 18307130128 for ass2 --- .../ass2/submission/18307130128/utils.go | 66 ++++++++++++++++--- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/assignments/ass2/submission/18307130128/utils.go b/assignments/ass2/submission/18307130128/utils.go index 7b8b5b9..9b9b465 100644 --- a/assignments/ass2/submission/18307130128/utils.go +++ b/assignments/ass2/submission/18307130128/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130128" // your student id, e.g. 18307130177 + SubmissionDir = "/home/hang_y/IDBS-Spring20-Fudan/assignments/ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,36 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + db.SetMaxOpenConns(200) + db.SetMaxIdleConns(100) + wg := sync.WaitGroup{} + for submitter, sub := range subs { + wg.Add(1) + go func(submitter string, sub *Submission){ + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err = db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + } + wg.Done() + }(submitter, sub) + } + wg.Wait() // YOUR CODE END } @@ -53,15 +83,33 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { // `comparision_result` and inserts the score of each submitter on each query into table `score` func GetScoreSQL() string { var SQL string - SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = "INSERT INTO score(submitter,item,score,vote) SELECT V1.submitter, V1.item, 1 AS score, V1.vote AS vote FROM (SELECT submitter,item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item) V1 WHERE V1.vote = (SELECT MAX(V2.vote) FROM (SELECT submitter,item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item) V2 WHERE V1.item = V2.item) UNION ALL SELECT V3.submitter, V3.item, 0 AS score, V3.vote AS vote FROM (SELECT submitter,item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item) V3 WHERE V3.vote < (SELECT MAX(V4.vote) FROM (SELECT submitter,item, SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter, item) V4 WHERE V3.item = V4.item)" // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + type scoreInfo struct{ + Submitter string `db:"submitter"` + Item int `db:"item"` + Score int `db:"score"` + Vote int `db:"vote"` + } + for submitter, sub := range subs{ + for i := 0; i < NumSQL; i++ { + var scoredata *scoreInfo = new(scoreInfo) + s := fmt.Sprintf("SELECT * FROM score WHERE submitter = '%s' AND item = %d", submitter, i + 1) + err := db.Get(scoredata, s) + if err == nil { + sub.score[i + 1] = scoredata.Score + }else{ + fmt.Println(s) + panic(err) + } + } + } // YOUR CODE END } From 1eb70a334119435140cc5eb69eb7631859235581 Mon Sep 17 00:00:00 2001 From: 105gun Date: Fri, 3 Apr 2020 17:20:20 +0800 Subject: [PATCH 174/189] ass 2 --- .../ass2/submission/18300200009/utils.go | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 assignments/ass2/submission/18300200009/utils.go diff --git a/assignments/ass2/submission/18300200009/utils.go b/assignments/ass2/submission/18300200009/utils.go new file mode 100644 index 0000000..8ef12bb --- /dev/null +++ b/assignments/ass2/submission/18300200009/utils.go @@ -0,0 +1,123 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "sync" + "reflect" + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18300200009" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "105gun" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + go func(submitter string, comparer string, sub *Submission, sub2 *Submission){ + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }(submitter, comparer, sub, sub2) + } + wg.Wait() + } + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL =` +INSERT INTO score +SELECT submitter, Xlist.item, IF(Xlist.vote = Ylist.value, 1, 0), Xlist.vote +FROM ( SELECT submitter, item, SUM(is_equal) AS vote + FROM comparison_result + GROUP BY submitter, item +) AS Xlist, +( SELECT item, MAX(vote) AS value + FROM ( SELECT submitter, item, SUM(is_equal) AS vote + FROM comparison_result + GROUP BY submitter, item + ) AS TMP + GROUP BY item +) AS Ylist +WHERE Xlist.item = Ylist.item; +` + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + for submit,sub := range subs{ + s := fmt.Sprintf("SELECT item,score FROM score WHERE submitter=%s;",submit) + rows,err := db.Query(s) + if err != nil { + panic(err) + } + var a,b int + for rows.Next() { + _ = rows.Scan(&a,&b) + sub.score[a] = b + } + + } + // YOUR CODE END +} From 2a593605c675f2ac344433e59664cc919b6b74ef Mon Sep 17 00:00:00 2001 From: xiaoas Date: Fri, 3 Apr 2020 18:23:58 +0800 Subject: [PATCH 175/189] fin. utils.go --- .../ass2/submission/18307130027/utils.go | 71 ++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/assignments/ass2/submission/18307130027/utils.go b/assignments/ass2/submission/18307130027/utils.go index 7b8b5b9..1daea42 100644 --- a/assignments/ass2/submission/18307130027/utils.go +++ b/assignments/ass2/submission/18307130027/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "reflect" + // "sync" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130027" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,36 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + db.SetMaxOpenConns(100) + db.SetMaxIdleConns(100) + db.SetConnMaxLifetime(0) + // newch := make(chan bool) + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + for db.Stats().InUse > 64{ + } + go func (sqlst string) { + _, err := db.Exec(sqlst) + if err != nil { + fmt.Println(sqlst) + panic(err) + } + } (s) + } + } + } // YOUR CODE END } @@ -55,13 +85,38 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = ` +insert into score (submitter, item, score, vote) +with scr as (select submitter, item, sum(is_equal)as cnt from comparison_result group by submitter, item) +(SELECT submitter, item, 1, cnt +FROM scr AS X +WHERE cnt >= ALL(SELECT cnt + FROM scr + WHERE item = X.item)) + union +(SELECT submitter, item, 0, cnt +FROM scr AS X +WHERE cnt < SOME(SELECT cnt + FROM scr + WHERE item = X.item)) + ` // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + rows, err := db.Query("select submitter, item, score from score") + if err != nil { + panic(err) + } + var sid string + var item, score int + // rows.Next() + for rows.Next() { + rows.Scan(&sid, &item, &score) + // fmt.Println(sid, item, score) + subs[sid].score[item] = score + } // YOUR CODE END } From f9b55bb0dc79a11ec5714d318cf5de1a8ac1ca9d Mon Sep 17 00:00:00 2001 From: codeplay0314 Date: Fri, 3 Apr 2020 21:20:56 +0800 Subject: [PATCH 176/189] update from upstream, start ass2 --- .../ass2/submission/18307130163/utils.go | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 assignments/ass2/submission/18307130163/utils.go diff --git a/assignments/ass2/submission/18307130163/utils.go b/assignments/ass2/submission/18307130163/utils.go new file mode 100644 index 0000000..99376b3 --- /dev/null +++ b/assignments/ass2/submission/18307130163/utils.go @@ -0,0 +1,128 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + "sync" + "reflect" + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "18307130163" // your student id, e.g. 18307130177 + SubmissionDir = "D:/study/大二下/数据库引论/lab/IDBS-Spring20-Fudan/assignments/ass1/submission" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + db.SetMaxOpenConns(100) + defer db.Close() + + wg := sync.WaitGroup{} + defer wg.Wait() + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + go func() { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }() + } + } + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + SQL = ` + INSERT INTO score + WITH votes AS ( + SELECT submitter, item, COUNT(comparer) AS vote + FROM comparison_result + WHERE is_equal = 1 + GROUP BY submitter, item + ), standard AS ( + SELECT item, MAX(vote) AS highest + FROM votes + GROUP BY item + ) + SELECT submitter, item, IF(vote = highest, 1, 0) AS score, vote + FROM votes JOIN standard USING(item) + ` + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + rows, rowsErr := db.Query("SELECT submitter, item, score FROM score") + if rowsErr != nil { + panic(rowsErr) + } + + for { + ok := rows.Next() + if !ok { + break + } + + var uid string + var item, score int + rows.Scan(&uid, &item, &score) + subs[uid].score[item] = score + } + // YOUR CODE END +} From 3e2307e9b9513c2e539cbe498ddcf86fefe7f8fc Mon Sep 17 00:00:00 2001 From: daihuasheng <18307130123@fudan.edu.cn> Date: Fri, 3 Apr 2020 22:16:46 +0800 Subject: [PATCH 177/189] submission of 118307130123 for ass2 --- .../ass2/submission/18307130123/utils.go | 72 +++++++++++++++++-- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/assignments/ass2/submission/18307130123/utils.go b/assignments/ass2/submission/18307130123/utils.go index 7b8b5b9..e16021b 100644 --- a/assignments/ass2/submission/18307130123/utils.go +++ b/assignments/ass2/submission/18307130123/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,9 +15,9 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root + EvaluatorID = "18307130123" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root Password = "" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,37 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg:=sync.WaitGroup{} + for submitter, sub := range subs { + wg.Add(1) + go func(submitter string, sub *Submission){ + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + + } + wg.Done() + }(submitter, sub) + } + wg.Wait() + //The number of open files (-n) is no more than 1024 + //Actually we can change the limited number into a bigger one, but I give it up finally since I'm not sure if it'll work on another computer. // YOUR CODE END } @@ -55,13 +86,40 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = `INSERT INTO score + SELECT submitter,VoteResult.item,(CASE WHEN VoteResult.vote = MaxVoteResult.max_vote THEN 1 ELSE 0 END) AS score,VoteResult.vote + FROM (SELECT submitter,item,SUM(is_equal) AS vote + FROM comparison_result + GROUP BY submitter,item)AS VoteResult, + + (SELECT item,MAX(VoteResult.vote) AS max_vote + FROM (SELECT submitter,item,SUM(is_equal) AS vote FROM comparison_result GROUP BY submitter,item)AS VoteResult + GROUP BY item) AS MaxVoteResult + WHERE VoteResult.item = MaxVoteResult.item` + //The version of MySQL is too old, but I don't want to update now since I need to copy the database.So I export to table VoteResult twice. // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + rows,err:=db.Query(`SELECT submitter,item,score FROM score`) + if err!=nil{ + panic(err) + } + for rows.Next(){ + var sub string + var it int + var sc int + err=rows.Scan(&sub,&it,&sc) + if err!=nil{ + panic(err) + } + subs[sub].score[it]=sc + } + rows.Close() + if err = rows.Err();err != nil{ + panic(err) + } // YOUR CODE END } From 511b0f5c204e6558db9c7e2972fd5439ef55730f Mon Sep 17 00:00:00 2001 From: 18307130266-wangxinyi <18307130266@fudan.edu.cn> Date: Sat, 4 Apr 2020 22:06:06 +0800 Subject: [PATCH 178/189] submission of 18307130266 for ass2 --- .../ass2/submission/18307130266/utils.go | 69 +++++++++++++++++-- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/assignments/ass2/submission/18307130266/utils.go b/assignments/ass2/submission/18307130266/utils.go index 7b8b5b9..8300990 100644 --- a/assignments/ass2/submission/18307130266/utils.go +++ b/assignments/ass2/submission/18307130266/utils.go @@ -5,7 +5,8 @@ import ( "time" // YOUR CODE BEGIN remove the follow packages if you don't need them - + "sync" + "reflect" // YOUR CODE END _ "github.com/go-sql-driver/mysql" @@ -14,10 +15,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "18307130266" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission/" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "123456" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +46,35 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN - + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + for submitter, sub := range subs { + for comparer, sub2 := range subs { + wg.Add(1) + db.SetMaxOpenConns(50) + go func(){ + for i := 0; i < NumSQL; i++ { + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + } + wg.Done() + }() + } + } + wg.Wait() // YOUR CODE END } @@ -55,6 +84,19 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN + SQL = `INSERT INTO score(submitter, item, score, vote) + WITH votes AS + (SELECT submitter, item, SUM(is_equal) AS vote + FROM comparison_result + GROUP BY submitter, item + ), + i_vote AS + (SELECT item, MAX(vote) AS hi_vote + FROM votes + GROUP BY item + ) + SELECT submitter, item, IF(vote = hi_vote, 1, 0) AS score, vote + FROM votes NATURAL JOIN i_vote ; ` // YOUR CODE END return SQL @@ -62,6 +104,19 @@ func GetScoreSQL() string { func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + rows, err := db.Query("SELECT submitter, item, score FROM score") + if err != nil { + panic(err) + } + defer db.Close() + var submitter string + var item, score int + for rows.Next() { + err := rows.Scan(&submitter, &item, &score) + if(err != nil) { + panic(err) + } + subs[submitter].score[item] = score + } // YOUR CODE END } From edbca0755f57cb28469e8666c3c2cb3bcdd5d1ae Mon Sep 17 00:00:00 2001 From: cbshnrh <15307130192@fudan.edu.cn> Date: Sun, 5 Apr 2020 19:01:09 -0700 Subject: [PATCH 179/189] update from upstream, start ass2 --- .../ass2/submission/15307130192/utils.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 assignments/ass2/submission/15307130192/utils.go diff --git a/assignments/ass2/submission/15307130192/utils.go b/assignments/ass2/submission/15307130192/utils.go new file mode 100644 index 0000000..7b8b5b9 --- /dev/null +++ b/assignments/ass2/submission/15307130192/utils.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "time" + + // YOUR CODE BEGIN remove the follow packages if you don't need them + + // YOUR CODE END + + _ "github.com/go-sql-driver/mysql" + sql "github.com/jmoiron/sqlx" +) + +var ( + // YOUR CODE BELOW + EvaluatorID = "" // your student id, e.g. 18307130177 + SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "" // the user name to connect the database, e.g. root + Password = "" // the password for the user name, e.g. xxx + // YOUR CODE END +) + +// ConcurrentCompareAndInsert is similar with compareAndInsert in `main.go`, but it is concurrent and faster! +func ConcurrentCompareAndInsert(subs map[string]*Submission) { + start := time.Now() + defer func() { + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(nil) + } + rows, err := db.Query("SELECT COUNT(*) FROM comparison_result") + if err != nil { + panic(err) + } + rows.Next() + var cnt int + err = rows.Scan(&cnt) + if err != nil { + panic(err) + } + if cnt == 0 { + panic("ConcurrentCompareAndInsert Not Implemented") + } + fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) + }() + // YOUR CODE BEGIN + + // YOUR CODE END +} + +// GetScoreSQL returns a string which contains only ONE SQL to be executed, which collects the data in table +// `comparision_result` and inserts the score of each submitter on each query into table `score` +func GetScoreSQL() string { + var SQL string + SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. + // YOUR CODE BEGIN + + // YOUR CODE END + return SQL +} + +func GetScore(db *sql.DB, subs map[string]*Submission) { + // YOUR CODE BEGIN + + // YOUR CODE END +} From bd815a5d1093b7bd8582e143893368838e51f232 Mon Sep 17 00:00:00 2001 From: cbshrnh <746068668@qq.com> Date: Mon, 6 Apr 2020 06:20:20 -0700 Subject: [PATCH 180/189] submission of cbshnrh for ass2 --- .../ass2/submission/15307130192/utils.go | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/assignments/ass2/submission/15307130192/utils.go b/assignments/ass2/submission/15307130192/utils.go index 7b8b5b9..f05f241 100644 --- a/assignments/ass2/submission/15307130192/utils.go +++ b/assignments/ass2/submission/15307130192/utils.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "reflect" + "sync" "time" // YOUR CODE BEGIN remove the follow packages if you don't need them @@ -14,10 +16,10 @@ import ( var ( // YOUR CODE BELOW - EvaluatorID = "" // your student id, e.g. 18307130177 - SubmissionDir = "" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" - User = "" // the user name to connect the database, e.g. root - Password = "" // the password for the user name, e.g. xxx + EvaluatorID = "15307130192" // your student id, e.g. 18307130177 + SubmissionDir = "../../../ass1/submission" // the relative path the the submission directory of assignment 1, it should be "../../../ass1/submission/" + User = "root" // the user name to connect the database, e.g. root + Password = "qwer1234" // the password for the user name, e.g. xxx // YOUR CODE END ) @@ -45,7 +47,38 @@ func ConcurrentCompareAndInsert(subs map[string]*Submission) { fmt.Println("ConcurrentCompareAndInsert takes ", time.Since(start)) }() // YOUR CODE BEGIN + db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/ass1_result_evaluated_by_%s", User, Password, EvaluatorID)) + if err != nil { + panic(err) + } + wg := sync.WaitGroup{} + cap_goroutine := make(chan int, 50) + for submitter, sub := range subs { + for comparer, sub2 := range subs { + for i := 0; i < NumSQL; i++ { + cap_goroutine <- 0 + wg.Add(1) + go func(submitter string, comparer string, sub *Submission, sub2 *Submission, i int) { + defer wg.Done() + var equal int + if reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i]) { + equal = 1 + } else { + equal = 0 + } + s := fmt.Sprintf("INSERT INTO comparison_result VALUES ('%s', '%s', %d, %d)", submitter, comparer, i+1, equal) + _, err := db.Exec(s) + if err != nil { + fmt.Println(s) + panic(err) + } + <-cap_goroutine + }(submitter, comparer, sub, sub2, i) + } + } + } + wg.Wait() // YOUR CODE END } @@ -55,13 +88,33 @@ func GetScoreSQL() string { var SQL string SQL = "SELECT 1" // ignore this line, it just makes the returned SQL a valid SQL if you haven't written yours. // YOUR CODE BEGIN - + SQL = `INSERT INTO score +(WITH score_raw (submitter, item, vote) AS ( +SELECT submitter, item, sum(is_equal) AS vote FROM comparison_result +GROUP BY submitter, item), +max_vote (item, vote_max) AS ( +SELECT item, MAX(vote) FROM score_raw +GROUP BY item) +(SELECT submitter, item, '0' AS score, vote FROM score_raw AS X +WHERE vote < (SELECT vote_max FROM max_vote AS Y WHERE X.item = Y.item)) +UNION +(SELECT submitter, item, '1' AS score, vote FROM score_raw AS X +WHERE vote = (SELECT vote_max FROM max_vote AS Y WHERE X.item = Y.item)))` // YOUR CODE END return SQL } func GetScore(db *sql.DB, subs map[string]*Submission) { // YOUR CODE BEGIN - + rows, err := db.Query("SELECT submitter, item, score FROM score") + if err != nil { + panic(err) + } + var submitter string + var item, score int + for rows.Next() { + rows.Scan(&submitter, &item, &score) + subs[submitter].score[item] = score + } // YOUR CODE END } From 57b5bde63c9f36bc433134a92aef2c8244d69fb0 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 15:55:48 +0800 Subject: [PATCH 181/189] add ass3 --- assignments/ass3/boilerplate/go.mod | 8 +++ assignments/ass3/boilerplate/go.sum | 8 +++ assignments/ass3/boilerplate/library.go | 43 ++++++++++++++++ assignments/ass3/boilerplate/library_test.go | 14 ++++++ assignments/ass3/submission/.gitignore | 5 ++ content/assignment3/readme.md | 52 ++++++++++++++++++++ content/index.md | 3 ++ mkdocs.yml | 2 + 8 files changed, 135 insertions(+) create mode 100644 assignments/ass3/boilerplate/go.mod create mode 100644 assignments/ass3/boilerplate/go.sum create mode 100644 assignments/ass3/boilerplate/library.go create mode 100644 assignments/ass3/boilerplate/library_test.go create mode 100644 assignments/ass3/submission/.gitignore create mode 100644 content/assignment3/readme.md diff --git a/assignments/ass3/boilerplate/go.mod b/assignments/ass3/boilerplate/go.mod new file mode 100644 index 0000000..8d25d49 --- /dev/null +++ b/assignments/ass3/boilerplate/go.mod @@ -0,0 +1,8 @@ +module github.com/ichn-hu/IDBS-Spring20-Fudan/assignments/ass3/boilerplate + +go 1.14 + +require ( + github.com/go-sql-driver/mysql v1.4.0 + github.com/jmoiron/sqlx v1.2.0 +) diff --git a/assignments/ass3/boilerplate/go.sum b/assignments/ass3/boilerplate/go.sum new file mode 100644 index 0000000..850a734 --- /dev/null +++ b/assignments/ass3/boilerplate/go.sum @@ -0,0 +1,8 @@ +github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= +github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= diff --git a/assignments/ass3/boilerplate/library.go b/assignments/ass3/boilerplate/library.go new file mode 100644 index 0000000..ddf447c --- /dev/null +++ b/assignments/ass3/boilerplate/library.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + + // mysql connector + _ "github.com/go-sql-driver/mysql" + sqlx "github.com/jmoiron/sqlx" +) + +const ( + User = "user" + Password = "password" + DBName = "ass3" +) + +type Library struct { + db *sqlx.DB +} + +func (lib *Library) ConnectDB() { + db, err := sqlx.Open("mysql", fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/%s", User, Password, DBName)) + if err != nil { + panic(err) + } + lib.db = db +} + +// CreateTables created the tables in MySQL +func (lib *Library) CreateTables() error { + return nil +} + +// AddBook add a book into the library +func (lib *Library) AddBook(title, auther, ISBN string) error { + return nil +} + +// etc... + +func main() { + fmt.Println("Welcome to the Library Management System!") +} \ No newline at end of file diff --git a/assignments/ass3/boilerplate/library_test.go b/assignments/ass3/boilerplate/library_test.go new file mode 100644 index 0000000..7480bae --- /dev/null +++ b/assignments/ass3/boilerplate/library_test.go @@ -0,0 +1,14 @@ +package main + +import ( + "testing" +) + +func TestCreateTables(t *testing.T) { + lib := Library{} + lib.ConnectDB() + err := lib.CreateTables() + if err != nil { + t.Errorf("can't create tables") + } +} diff --git a/assignments/ass3/submission/.gitignore b/assignments/ass3/submission/.gitignore new file mode 100644 index 0000000..042d709 --- /dev/null +++ b/assignments/ass3/submission/.gitignore @@ -0,0 +1,5 @@ +/* +!.gitignore +!/*/ +/*/* +!/*/REPORT.pdf diff --git a/content/assignment3/readme.md b/content/assignment3/readme.md new file mode 100644 index 0000000..4a11fdd --- /dev/null +++ b/content/assignment3/readme.md @@ -0,0 +1,52 @@ +# Assignment 3, Library + +In this assignment, you are going to use what you have learned about MySQL and Go to implement a library management system. + +As a sophomore of *Fairy Union of Defense and Attack Nebula* University (FUDAN University) majoring in Computer Science, you are assigned to help build the library management system for the University. + +The goal of this assignment to let you know how to design an information management system, and you are given a maximum amount of freedom to design and implement the system, as long as you make use of Go. + +## Design + +As you are familiar with the library system in Fudan, the requirements are similar to the current library system: + +* add books to the library by the administrator's account +* remove a book from the library with explanation (e.g. book is lost) +* add student account by the administrator's account so that the student could borrow books from the library +* query books by title, author or ISBN +* borrow a book from the library with a student account +* query the borrow history of a student account +* query the books a student has borrowed and not returned yet +* check the deadline of returning a borrowed book +* extend the deadline of returning a book, at most 3 times (i.e. refuse to extend if the deadline has been extended for 3 times) +* check if a student has any overdue books that needs to be returned +* return a book to the library by a student account (make sure the student has borrowed the book) +* suspend student's account if the student has more than 3 overdue books (not able to borrow new books unless she has returned books so that she has overdue books less or equal to 3) + +And you could add more functionalities to the system as you like. + +## Requirement + +You should implement the system using Go and mysql. You should abstract the functionalities as Go functions, such as + +```go +// AddBook adds a book to the library +func AddBook(book_title string, publisher string) error { + // query mysql and do the work +} +``` + +You should document your code with comments and also write tests to prove your implementation for the functionalities is correct. + +Take a look at [here](https://blog.alexellis.io/golang-writing-unit-tests/), [here](https://gobyexample.com/testing) or [here](https://labix.org/gocheck) for how to write tests for go programs. + +The simple boilerplate provided might be helpful as a starter, but your are not restricted to it. + +Interactions to the system is not required (your tests is already a way of interaction), however it would be a plus if you implement a simple command line interface to interact with the system. + +## Submission + +You should submit a PDF file as the report explaining how you implement your system and how your implementation fulfills the functionalities, and the link to your project on GitHub (create a repository under your own account, and put your project there), and instructions on how to get your system running. + +Your report can be in either Chinese or English, and there is no difference in terms of marking, as long as you can make yourself clear. + diff --git a/content/index.md b/content/index.md index 10460a3..52b4344 100644 --- a/content/index.md +++ b/content/index.md @@ -21,6 +21,9 @@ This course is an introductory course to database systems. In this course, you w |4|2020-03-20|Assignment 1 Due
Assignment 2 Released

|| |5|2020-03-27||| |6|2020-04-03|
Assignment 2 Due|| +|8|2020-04-17|Assignment 3 Released

|| +|11|2020-05-08|
Assignment 3 Due|| + ## Assignment Guidance diff --git a/mkdocs.yml b/mkdocs.yml index 646e8fd..70fc239 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -74,3 +74,5 @@ nav: - Instruction: assignment1/readme.md - Assignment 2: - Instruction: assignment2/readme.md + - Assignment 3: + - Instruction: assignment3/readme.md From cb1273042d9de7f2968c97c2043fb08cdb9bde96 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 16:21:26 +0800 Subject: [PATCH 182/189] fix favicon --- mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index 70fc239..161ef56 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -19,7 +19,7 @@ theme: name: 'material' language: 'en' custom_dir: 'custom/' - favicon: '/static/assets/fudan.svg' + favicon: 'static/assets/fudan.svg' palette: primary: 'Black' accent: 'Blue' From 26e4f57e49ba40c7eb3a62fd15817d2781ce9912 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 16:22:26 +0800 Subject: [PATCH 183/189] fix favicon --- mkdocs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 161ef56..bc14d2b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -19,7 +19,7 @@ theme: name: 'material' language: 'en' custom_dir: 'custom/' - favicon: 'static/assets/fudan.svg' + favicon: '/static/assets/fudan.svg' palette: primary: 'Black' accent: 'Blue' @@ -27,7 +27,7 @@ theme: text: 'Roboto' code: 'Roboto Mono' logo: - icon: 'code' + icon: 'material/code' feature: tabs: true From e43137c6c156a8e971a00e4736c0d880710ddd33 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 16:31:44 +0800 Subject: [PATCH 184/189] fix favicon --- mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index bc14d2b..817d9e3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -27,7 +27,7 @@ theme: text: 'Roboto' code: 'Roboto Mono' logo: - icon: 'material/code' + icon: material/code feature: tabs: true From 1e541d8af2154fcb0772bfc95563f37b2f8ce337 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 16:55:36 +0800 Subject: [PATCH 185/189] fix favicon --- mkdocs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 817d9e3..4be929a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -26,10 +26,10 @@ theme: font: text: 'Roboto' code: 'Roboto Mono' - logo: - icon: material/code + icon: + logo: material/code feature: - tabs: true + - tabs: true # # Customization extra: From 80a9dadf14ce1852218348c60aea03213104b6a4 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 16:59:26 +0800 Subject: [PATCH 186/189] fix favicon --- mkdocs.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 4be929a..7ebc616 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -26,10 +26,8 @@ theme: font: text: 'Roboto' code: 'Roboto Mono' - icon: - logo: material/code feature: - - tabs: true + - tabs # # Customization extra: From a53528c7f1566c54d73232804c9daac831d04808 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 17:20:16 +0800 Subject: [PATCH 187/189] fix favicon --- .icons/fudan.svg | 177 +++++++++++++++++++++++++++++++++++++++++++++++ mkdocs.yml | 6 +- 2 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 .icons/fudan.svg diff --git a/.icons/fudan.svg b/.icons/fudan.svg new file mode 100644 index 0000000..df7c951 --- /dev/null +++ b/.icons/fudan.svg @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mkdocs.yml b/mkdocs.yml index 7ebc616..4cdd322 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -26,16 +26,16 @@ theme: font: text: 'Roboto' code: 'Roboto Mono' + icon: + logo: material/cloud feature: - tabs # # Customization extra: social: - - type: 'github' + - icon: fontawesome/brands/github-alt link: 'https://github.com/ichn-hu' - - type: 'quote-left' - link: 'https://github.com/ichn-hu/IDBS-Spring20-Fudan' extra_css: - 'static/css/katex.css' From f9714c21a55891196c27c6da5fe6f533fb224c0a Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 17:26:14 +0800 Subject: [PATCH 188/189] add submission --- content/assignment3/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/assignment3/readme.md b/content/assignment3/readme.md index 4a11fdd..efa40bb 100644 --- a/content/assignment3/readme.md +++ b/content/assignment3/readme.md @@ -46,7 +46,7 @@ Interactions to the system is not required (your tests is already a way of inter ## Submission -You should submit a PDF file as the report explaining how you implement your system and how your implementation fulfills the functionalities, and the link to your project on GitHub (create a repository under your own account, and put your project there), and instructions on how to get your system running. +You should submit a PDF file as the report explaining how you implement your system and how your implementation fulfills the functionalities. Also include the link to a project on GitHub (create a repository under your own account, and put your project there), and instructions on how to get your system running. Your report can be in either Chinese or English, and there is no difference in terms of marking, as long as you can make yourself clear. From 12dd506c9e62d0249168aa96e2673a12419058c8 Mon Sep 17 00:00:00 2001 From: ichn-hu Date: Fri, 17 Apr 2020 17:35:17 +0800 Subject: [PATCH 189/189] add link --- content/assignment3/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/assignment3/readme.md b/content/assignment3/readme.md index efa40bb..7bd52ac 100644 --- a/content/assignment3/readme.md +++ b/content/assignment3/readme.md @@ -40,7 +40,7 @@ You should document your code with comments and also write tests to prove your i Take a look at [here](https://blog.alexellis.io/golang-writing-unit-tests/), [here](https://gobyexample.com/testing) or [here](https://labix.org/gocheck) for how to write tests for go programs. -The simple boilerplate provided might be helpful as a starter, but your are not restricted to it. +The [simple boilerplate](https://github.com/ichn-hu/IDBS-Spring20-Fudan/tree/master/assignments/ass3/boilerplate) provided might be helpful as a starter, but your are not restricted to it. Interactions to the system is not required (your tests is already a way of interaction), however it would be a plus if you implement a simple command line interface to interact with the system.