Skip to content

Commit ff2261a

Browse files
committed
Add mysql source
1 parent cae81ca commit ff2261a

File tree

10 files changed

+703
-12
lines changed

10 files changed

+703
-12
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ jobs:
203203
- {os: ubuntu-20.04, r: 'release', test-src: 'test-mssql', covr: false, desc: 'SQL Server without covr' }
204204
- {os: ubuntu-22.04, r: 'release', test-src: 'test-postgres', covr: true, desc: 'Postgres with covr' }
205205
- {os: ubuntu-22.04, r: 'release', test-src: 'test-maria', covr: true, desc: 'MariaDB with covr' }
206-
- {os: ubuntu-22.04, r: 'release', test-src: 'test-mysql-maria', covr: true, desc: 'MySQL with covr' }
206+
- {os: ubuntu-22.04, r: 'release', test-src: 'test-mysql', covr: true, desc: 'MySQL with covr' }
207207
- {os: ubuntu-22.04, r: 'release', test-src: 'test-duckdb', covr: true, desc: 'DuckDB with covr' }
208208
- {os: ubuntu-22.04, r: 'release', test-src: 'test-sqlite', covr: true, desc: 'SQLite with covr' }
209209
# End custom: matrix elements

.github/workflows/custom/after-install/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ runs:
2020
mariadb-version: 10.9
2121

2222
- uses: ankane/setup-mysql@v1
23-
if: env.DM_TEST_SRC == 'test-mysql-maria'
23+
if: env.DM_TEST_SRC == 'test-mysql'
2424
with:
2525
mysql-version: "8.0"
2626

2727
- name: Create database (MariaDB), set it to UTF-8, add time zone info
28-
if: env.DM_TEST_SRC == 'test-maria' || env.DM_TEST_SRC == 'test-mysql-maria'
28+
if: env.DM_TEST_SRC == 'test-maria' || env.DM_TEST_SRC == 'test-mysql'
2929
run: |
3030
mysql -e "CREATE DATABASE IF NOT EXISTS test; ALTER DATABASE test CHARACTER SET 'utf8'; FLUSH PRIVILEGES;"
3131
shell: bash

Makefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ all: qtest
33
# Quiet tests
44
# Run with make -j $(nproc) -O
55
# or with pmake
6-
qtest: qtest-df qtest-sqlite qtest-postgres qtest-mssql qtest-duckdb qtest-maria
6+
qtest: qtest-df qtest-sqlite qtest-postgres qtest-mssql qtest-duckdb qtest-maria qtest-mysql
77

88
# Progress tests
9-
test: test-df test-sqlite test-postgres test-mssql test-duckdb test-maria
9+
test: test-df test-sqlite test-postgres test-mssql test-duckdb test-maria test-mysql
1010

1111
# Testing with lazytest
12-
ltest: ltest-df ltest-sqlite ltest-postgres ltest-mssql ltest-duckdb ltest-maria
12+
ltest: ltest-df ltest-sqlite ltest-postgres ltest-mssql ltest-duckdb ltest-maria ltest-mysql
1313

1414
# Silent testing
15-
stest: stest-df stest-sqlite stest-postgres stest-mssql stest-duckdb stest-maria
15+
stest: stest-df stest-sqlite stest-postgres stest-mssql stest-duckdb stest-maria stest-mysql
1616

1717
# Connectivity tests
18-
connect: connect-sqlite connect-postgres connect-mssql connect-duckdb connect-maria
18+
connect: connect-sqlite connect-postgres connect-mssql connect-duckdb connect-maria connect-mysql
1919

2020
qtest-%:
2121
DM_TEST_SRC=$@ time R -q -e 'options("crayon.enabled" = TRUE); Sys.setenv(TESTTHAT_PARALLEL = FALSE); testthat::test_local(filter = "${DM_TEST_FILTER}")'
@@ -32,10 +32,20 @@ ltest-%:
3232
connect-%:
3333
DM_TEST_SRC=$@ R -q -e 'suppressMessages(pkgload::load_all()); my_test_con()'
3434

35+
db-init-maria:
36+
while ! R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_maria(root = TRUE)$$con, "GRANT ALL ON *.* TO '"'"'compose'"'"'@'"'"'%'"'"';"); DBI::dbExecute(test_src_maria()$$con, "FLUSH PRIVILEGES")'; do sleep 1; done
37+
38+
db-init-mysql:
39+
while ! R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mysql(root = TRUE)$$con, "GRANT ALL ON *.* TO '"'"'compose'"'"'@'"'"'%'"'"';"); DBI::dbExecute(test_src_mysql()$$con, "FLUSH PRIVILEGES")'; do sleep 1; done
40+
41+
db-init-mssql:
42+
while ! R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mssql(FALSE)$$con, "CREATE DATABASE test")'; do sleep 1; done
43+
44+
db-init: db-init-maria db-init-mysql db-init-mssql
45+
3546
db-start:
36-
docker-compose up -d --force-recreate
37-
R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_maria(root = TRUE)$$con, "GRANT ALL ON *.* TO '"'"'compose'"'"'@'"'"'%'"'"';"); DBI::dbExecute(test_src_maria()$$con, "FLUSH PRIVILEGES")'
38-
R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mssql(FALSE)$$con, "CREATE DATABASE test")'
47+
docker-compose up -d --force-recreate --wait
48+
$(MAKE) db-init
3949

4050
db-restart:
4151
docker-compose up -d

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ volumes:
66
driver: local
77
maria-db:
88
driver: local
9+
mysql-db:
10+
driver: local
911
services:
1012
# https://www.beekeeperstudio.io/blog/how-to-use-mariadb-with-docker
1113
mysql:
12-
# FIXME: Still need to add Makefile rules to provision MySQL database
1314
container_name: mysql
1415
image: mysql
1516
environment:
1617
MYSQL_ROOT_PASSWORD: "YourStrong!Passw0rd"
1718
MYSQL_DATABASE: test
1819
MYSQL_USER: compose
1920
MYSQL_PASSWORD: "YourStrong!Passw0rd"
21+
volumes:
22+
- mysql-db:/var/lib/mysql
2023
ports:
2124
- "3307:3306"
2225
maria:

tests/testthat/_snaps/mysql.md

Lines changed: 311 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
# build_copy_queries snapshot test for pixarfilms
2+
3+
Code
4+
pixar_dm %>% build_copy_queries(src_db, .) %>% as.list()
5+
Output
6+
$name
7+
[1] "pixar_films" "academy" "box_office" "genres"
8+
[5] "public_response"
9+
10+
$remote_name
11+
pixar_films academy box_office genres
12+
"pixar_films" "academy" "box_office" "genres"
13+
public_response
14+
"public_response"
15+
16+
$columns
17+
$columns[[1]]
18+
[1] "number" "film" "release_date" "run_time" "film_rating"
19+
20+
$columns[[2]]
21+
[1] "film" "award_type" "status"
22+
23+
$columns[[3]]
24+
[1] "film" "budget" "box_office_us_canada"
25+
[4] "box_office_other" "box_office_worldwide"
26+
27+
$columns[[4]]
28+
[1] "film" "genre"
29+
30+
$columns[[5]]
31+
[1] "film" "rotten_tomatoes" "metacritic" "cinema_score"
32+
[5] "critics_choice"
33+
34+
35+
$sql_table
36+
<SQL> CREATE TEMPORARY TABLE `pixar_films` (
37+
`number` VARCHAR(255),
38+
`film` VARCHAR(255),
39+
`release_date` DATE,
40+
`run_time` DOUBLE,
41+
`film_rating` VARCHAR(255),
42+
PRIMARY KEY (`film`)
43+
)
44+
<SQL> CREATE TEMPORARY TABLE `academy` (
45+
`film` VARCHAR(255),
46+
`award_type` VARCHAR(255),
47+
`status` VARCHAR(255),
48+
PRIMARY KEY (`film`, `award_type`)
49+
)
50+
<SQL> CREATE TEMPORARY TABLE `box_office` (
51+
`film` VARCHAR(255),
52+
`budget` DOUBLE,
53+
`box_office_us_canada` DOUBLE,
54+
`box_office_other` DOUBLE,
55+
`box_office_worldwide` DOUBLE,
56+
PRIMARY KEY (`film`)
57+
)
58+
<SQL> CREATE TEMPORARY TABLE `genres` (
59+
`film` VARCHAR(255),
60+
`genre` VARCHAR(255),
61+
PRIMARY KEY (`film`, `genre`)
62+
)
63+
<SQL> CREATE TEMPORARY TABLE `public_response` (
64+
`film` VARCHAR(255),
65+
`rotten_tomatoes` DOUBLE,
66+
`metacritic` DOUBLE,
67+
`cinema_score` VARCHAR(255),
68+
`critics_choice` DOUBLE,
69+
PRIMARY KEY (`film`)
70+
)
71+
72+
$sql_index
73+
$sql_index[[1]]
74+
NULL
75+
76+
$sql_index[[2]]
77+
NULL
78+
79+
$sql_index[[3]]
80+
NULL
81+
82+
$sql_index[[4]]
83+
NULL
84+
85+
$sql_index[[5]]
86+
NULL
87+
88+
89+
$index_name
90+
$index_name[[1]]
91+
NULL
92+
93+
$index_name[[2]]
94+
NULL
95+
96+
$index_name[[3]]
97+
NULL
98+
99+
$index_name[[4]]
100+
NULL
101+
102+
$index_name[[5]]
103+
NULL
104+
105+
106+
107+
# build_copy_queries snapshot test for dm_for_filter()
108+
109+
Code
110+
dm_for_filter() %>% build_copy_queries(src_db, .) %>% as.list()
111+
Output
112+
$name
113+
[1] "tf_1" "tf_3" "tf_6" "tf_2" "tf_4" "tf_5"
114+
115+
$remote_name
116+
tf_1 tf_3 tf_6 tf_2 tf_4 tf_5
117+
"tf_1" "tf_3" "tf_6" "tf_2" "tf_4" "tf_5"
118+
119+
$columns
120+
$columns[[1]]
121+
[1] "a" "b"
122+
123+
$columns[[2]]
124+
[1] "f" "f1" "g"
125+
126+
$columns[[3]]
127+
[1] "zz" "n" "o"
128+
129+
$columns[[4]]
130+
[1] "c" "d" "e" "e1"
131+
132+
$columns[[5]]
133+
[1] "h" "i" "j" "j1"
134+
135+
$columns[[6]]
136+
[1] "ww" "k" "l" "m"
137+
138+
139+
$sql_table
140+
<SQL> CREATE TEMPORARY TABLE `tf_1` (
141+
`a` INT AUTO_INCREMENT,
142+
`b` VARCHAR(255),
143+
PRIMARY KEY (`a`)
144+
)
145+
<SQL> CREATE TEMPORARY TABLE `tf_3` (
146+
`f` VARCHAR(255),
147+
`f1` INT,
148+
`g` VARCHAR(255),
149+
PRIMARY KEY (`f`, `f1`)
150+
)
151+
<SQL> CREATE TEMPORARY TABLE `tf_6` (
152+
`zz` INT,
153+
`n` VARCHAR(255),
154+
`o` VARCHAR(255),
155+
PRIMARY KEY (`o`),
156+
UNIQUE (`n`)
157+
)
158+
<SQL> CREATE TEMPORARY TABLE `tf_2` (
159+
`c` VARCHAR(255),
160+
`d` INT,
161+
`e` VARCHAR(255),
162+
`e1` INT,
163+
PRIMARY KEY (`c`)
164+
)
165+
<SQL> CREATE TEMPORARY TABLE `tf_4` (
166+
`h` VARCHAR(255),
167+
`i` VARCHAR(255),
168+
`j` VARCHAR(255),
169+
`j1` INT,
170+
PRIMARY KEY (`h`)
171+
)
172+
<SQL> CREATE TEMPORARY TABLE `tf_5` (
173+
`ww` INT,
174+
`k` INT,
175+
`l` VARCHAR(255),
176+
`m` VARCHAR(255),
177+
PRIMARY KEY (`k`)
178+
)
179+
180+
$sql_index
181+
$sql_index[[1]]
182+
NULL
183+
184+
$sql_index[[2]]
185+
NULL
186+
187+
$sql_index[[3]]
188+
NULL
189+
190+
$sql_index[[4]]
191+
NULL
192+
193+
$sql_index[[5]]
194+
NULL
195+
196+
$sql_index[[6]]
197+
NULL
198+
199+
200+
$index_name
201+
$index_name[[1]]
202+
NULL
203+
204+
$index_name[[2]]
205+
NULL
206+
207+
$index_name[[3]]
208+
NULL
209+
210+
$index_name[[4]]
211+
NULL
212+
213+
$index_name[[5]]
214+
NULL
215+
216+
$index_name[[6]]
217+
NULL
218+
219+
220+
221+
# build_copy_queries avoids duplicate indexes
222+
223+
Code
224+
as.list(queries)
225+
Output
226+
$name
227+
[1] "parent1" "parent2" "child" "child__a"
228+
229+
$remote_name
230+
$remote_name$parent1
231+
<Id> table = parent1
232+
233+
$remote_name$parent2
234+
<Id> table = parent2
235+
236+
$remote_name$child
237+
<Id> table = child
238+
239+
$remote_name$child__a
240+
<Id> table = child__a
241+
242+
243+
$columns
244+
$columns[[1]]
245+
[1] "key"
246+
247+
$columns[[2]]
248+
[1] "a__key"
249+
250+
$columns[[3]]
251+
[1] "a__key"
252+
253+
$columns[[4]]
254+
[1] "key"
255+
256+
257+
$sql_table
258+
<SQL> CREATE TEMPORARY TABLE `parent1` (
259+
`key` DOUBLE,
260+
PRIMARY KEY (`key`)
261+
)
262+
<SQL> CREATE TEMPORARY TABLE `parent2` (
263+
`a__key` DOUBLE,
264+
PRIMARY KEY (`a__key`)
265+
)
266+
<SQL> CREATE TEMPORARY TABLE `child` (
267+
`a__key` DOUBLE
268+
)
269+
<SQL> CREATE TEMPORARY TABLE `child__a` (
270+
`key` DOUBLE
271+
)
272+
273+
$sql_index
274+
$sql_index[[1]]
275+
NULL
276+
277+
$sql_index[[2]]
278+
NULL
279+
280+
$sql_index[[3]]
281+
NULL
282+
283+
$sql_index[[4]]
284+
NULL
285+
286+
287+
$index_name
288+
$index_name[[1]]
289+
NULL
290+
291+
$index_name[[2]]
292+
NULL
293+
294+
$index_name[[3]]
295+
NULL
296+
297+
$index_name[[4]]
298+
NULL
299+
300+
301+

0 commit comments

Comments
 (0)