Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: Add full-fledged mysql test source #2097

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ jobs:
- {os: ubuntu-20.04, r: 'release', test-src: 'test-mssql', covr: false, desc: 'SQL Server without covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-postgres', covr: true, desc: 'Postgres with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-maria', covr: true, desc: 'MariaDB with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-mysql-maria', covr: true, desc: 'MySQL with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-mysql', covr: true, desc: 'MySQL with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-duckdb', covr: true, desc: 'DuckDB with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-sqlite', covr: true, desc: 'SQLite with covr' }
# End custom: matrix elements
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/custom/after-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ runs:
mariadb-version: 10.9

- uses: ankane/setup-mysql@v1
if: env.DM_TEST_SRC == 'test-mysql-maria'
if: env.DM_TEST_SRC == 'test-mysql'
with:
mysql-version: "8.0"

- name: Create database (MariaDB), set it to UTF-8, add time zone info
if: env.DM_TEST_SRC == 'test-maria' || env.DM_TEST_SRC == 'test-mysql-maria'
if: env.DM_TEST_SRC == 'test-maria' || env.DM_TEST_SRC == 'test-mysql'
run: |
mysql -e "CREATE DATABASE IF NOT EXISTS test; ALTER DATABASE test CHARACTER SET 'utf8'; FLUSH PRIVILEGES;"
shell: bash
Expand Down
26 changes: 18 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ all: qtest
# Quiet tests
# Run with make -j $(nproc) -O
# or with pmake
qtest: qtest-df qtest-sqlite qtest-postgres qtest-mssql qtest-duckdb qtest-maria
qtest: qtest-df qtest-sqlite qtest-postgres qtest-mssql qtest-duckdb qtest-maria qtest-mysql

# Progress tests
test: test-df test-sqlite test-postgres test-mssql test-duckdb test-maria
test: test-df test-sqlite test-postgres test-mssql test-duckdb test-maria test-mysql

# Testing with lazytest
ltest: ltest-df ltest-sqlite ltest-postgres ltest-mssql ltest-duckdb ltest-maria
ltest: ltest-df ltest-sqlite ltest-postgres ltest-mssql ltest-duckdb ltest-maria ltest-mysql

# Silent testing
stest: stest-df stest-sqlite stest-postgres stest-mssql stest-duckdb stest-maria
stest: stest-df stest-sqlite stest-postgres stest-mssql stest-duckdb stest-maria stest-mysql

# Connectivity tests
connect: connect-sqlite connect-postgres connect-mssql connect-duckdb connect-maria
connect: connect-sqlite connect-postgres connect-mssql connect-duckdb connect-maria connect-mysql

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

db-init-maria:
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

db-init-mysql:
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

db-init-mssql:
while ! R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mssql(FALSE)$$con, "CREATE DATABASE test")'; do sleep 1; done

db-init: db-init-maria db-init-mysql db-init-mssql

db-start:
docker-compose up -d --force-recreate
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")'
R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mssql(FALSE)$$con, "CREATE DATABASE test")'
docker-compose up -d --force-recreate --wait
$(MAKE) db-init

db-restart:
docker-compose up -d
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ volumes:
driver: local
maria-db:
driver: local
mysql-db:
driver: local
services:
# https://www.beekeeperstudio.io/blog/how-to-use-mariadb-with-docker
mysql:
# FIXME: Still need to add Makefile rules to provision MySQL database
container_name: mysql
image: mysql
environment:
MYSQL_ROOT_PASSWORD: "YourStrong!Passw0rd"
MYSQL_DATABASE: test
MYSQL_USER: compose
MYSQL_PASSWORD: "YourStrong!Passw0rd"
volumes:
- mysql-db:/var/lib/mysql
ports:
- "3307:3306"
maria:
Expand Down
311 changes: 311 additions & 0 deletions tests/testthat/_snaps/mysql.md

Large diffs are not rendered by default.

301 changes: 301 additions & 0 deletions tests/testthat/_snaps/mysql/build_copy_queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
# build_copy_queries snapshot test for pixarfilms

Code
pixar_dm %>% build_copy_queries(src_db, .) %>% as.list()
Output
$name
[1] "pixar_films" "academy" "box_office" "genres"
[5] "public_response"

$remote_name
pixar_films academy box_office genres
"pixar_films" "academy" "box_office" "genres"
public_response
"public_response"

$columns
$columns[[1]]
[1] "number" "film" "release_date" "run_time" "film_rating"

$columns[[2]]
[1] "film" "award_type" "status"

$columns[[3]]
[1] "film" "budget" "box_office_us_canada"
[4] "box_office_other" "box_office_worldwide"

$columns[[4]]
[1] "film" "genre"

$columns[[5]]
[1] "film" "rotten_tomatoes" "metacritic" "cinema_score"
[5] "critics_choice"


$sql_table
<SQL> CREATE TEMPORARY TABLE `pixar_films` (
`number` VARCHAR(255),
`film` VARCHAR(255),
`release_date` DATE,
`run_time` DOUBLE,
`film_rating` VARCHAR(255),
PRIMARY KEY (`film`)
)
<SQL> CREATE TEMPORARY TABLE `academy` (
`film` VARCHAR(255),
`award_type` VARCHAR(255),
`status` VARCHAR(255),
PRIMARY KEY (`film`, `award_type`)
)
<SQL> CREATE TEMPORARY TABLE `box_office` (
`film` VARCHAR(255),
`budget` DOUBLE,
`box_office_us_canada` DOUBLE,
`box_office_other` DOUBLE,
`box_office_worldwide` DOUBLE,
PRIMARY KEY (`film`)
)
<SQL> CREATE TEMPORARY TABLE `genres` (
`film` VARCHAR(255),
`genre` VARCHAR(255),
PRIMARY KEY (`film`, `genre`)
)
<SQL> CREATE TEMPORARY TABLE `public_response` (
`film` VARCHAR(255),
`rotten_tomatoes` DOUBLE,
`metacritic` DOUBLE,
`cinema_score` VARCHAR(255),
`critics_choice` DOUBLE,
PRIMARY KEY (`film`)
)

$sql_index
$sql_index[[1]]
NULL

$sql_index[[2]]
NULL

$sql_index[[3]]
NULL

$sql_index[[4]]
NULL

$sql_index[[5]]
NULL


$index_name
$index_name[[1]]
NULL

$index_name[[2]]
NULL

$index_name[[3]]
NULL

$index_name[[4]]
NULL

$index_name[[5]]
NULL



# build_copy_queries snapshot test for dm_for_filter()

Code
dm_for_filter() %>% build_copy_queries(src_db, .) %>% as.list()
Output
$name
[1] "tf_1" "tf_3" "tf_6" "tf_2" "tf_4" "tf_5"

$remote_name
tf_1 tf_3 tf_6 tf_2 tf_4 tf_5
"tf_1" "tf_3" "tf_6" "tf_2" "tf_4" "tf_5"

$columns
$columns[[1]]
[1] "a" "b"

$columns[[2]]
[1] "f" "f1" "g"

$columns[[3]]
[1] "zz" "n" "o"

$columns[[4]]
[1] "c" "d" "e" "e1"

$columns[[5]]
[1] "h" "i" "j" "j1"

$columns[[6]]
[1] "ww" "k" "l" "m"


$sql_table
<SQL> CREATE TEMPORARY TABLE `tf_1` (
`a` INT AUTO_INCREMENT,
`b` VARCHAR(255),
PRIMARY KEY (`a`)
)
<SQL> CREATE TEMPORARY TABLE `tf_3` (
`f` VARCHAR(255),
`f1` INT,
`g` VARCHAR(255),
PRIMARY KEY (`f`, `f1`)
)
<SQL> CREATE TEMPORARY TABLE `tf_6` (
`zz` INT,
`n` VARCHAR(255),
`o` VARCHAR(255),
PRIMARY KEY (`o`),
UNIQUE (`n`)
)
<SQL> CREATE TEMPORARY TABLE `tf_2` (
`c` VARCHAR(255),
`d` INT,
`e` VARCHAR(255),
`e1` INT,
PRIMARY KEY (`c`)
)
<SQL> CREATE TEMPORARY TABLE `tf_4` (
`h` VARCHAR(255),
`i` VARCHAR(255),
`j` VARCHAR(255),
`j1` INT,
PRIMARY KEY (`h`)
)
<SQL> CREATE TEMPORARY TABLE `tf_5` (
`ww` INT,
`k` INT,
`l` VARCHAR(255),
`m` VARCHAR(255),
PRIMARY KEY (`k`)
)

$sql_index
$sql_index[[1]]
NULL

$sql_index[[2]]
NULL

$sql_index[[3]]
NULL

$sql_index[[4]]
NULL

$sql_index[[5]]
NULL

$sql_index[[6]]
NULL


$index_name
$index_name[[1]]
NULL

$index_name[[2]]
NULL

$index_name[[3]]
NULL

$index_name[[4]]
NULL

$index_name[[5]]
NULL

$index_name[[6]]
NULL



# build_copy_queries avoids duplicate indexes

Code
as.list(queries)
Output
$name
[1] "parent1" "parent2" "child" "child__a"

$remote_name
$remote_name$parent1
<Id> table = parent1

$remote_name$parent2
<Id> table = parent2

$remote_name$child
<Id> table = child

$remote_name$child__a
<Id> table = child__a


$columns
$columns[[1]]
[1] "key"

$columns[[2]]
[1] "a__key"

$columns[[3]]
[1] "a__key"

$columns[[4]]
[1] "key"


$sql_table
<SQL> CREATE TEMPORARY TABLE `parent1` (
`key` DOUBLE,
PRIMARY KEY (`key`)
)
<SQL> CREATE TEMPORARY TABLE `parent2` (
`a__key` DOUBLE,
PRIMARY KEY (`a__key`)
)
<SQL> CREATE TEMPORARY TABLE `child` (
`a__key` DOUBLE
)
<SQL> CREATE TEMPORARY TABLE `child__a` (
`key` DOUBLE
)

$sql_index
$sql_index[[1]]
NULL

$sql_index[[2]]
NULL

$sql_index[[3]]
NULL

$sql_index[[4]]
NULL


$index_name
$index_name[[1]]
NULL

$index_name[[2]]
NULL

$index_name[[3]]
NULL

$index_name[[4]]
NULL



Loading
Loading