Skip to content

Commit 8e147f9

Browse files
committed
for mariadb, use jq for simplifying when user requests nested fields
1 parent c4abec5 commit 8e147f9

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

R/query.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,8 @@ docdb_query.src_mariadb <- function(src, key, query, ...) {
14921492
fldQ$selectFields[i] <- paste0(
14931493
'(CASE WHEN JSON_EXISTS(`/** key **/`.json, \'$."',
14941494
gsub('[.]', '[0].', fldQ$selectFields[i]), '"\') ',
1495-
'THEN JSON_EXTRACT(`/** key **/`.json, \'$."', gsub('"[.]"', '"**."', fldQ$selectFields[i]), '"\') ',
1495+
'THEN JSON_EXTRACT(`/** key **/`.json, \'$."',
1496+
gsub('"[.]"', '"**."', fldQ$selectFields[i]), '"\') ',
14961497
"ELSE 'null' END) ")
14971498

14981499
}
@@ -1550,19 +1551,21 @@ docdb_query.src_mariadb <- function(src, key, query, ...) {
15501551

15511552
# - - - - - - - - -
15521553

1553-
# TODO if query concerns only _id and excludeField
1554-
# id empty, then could do query only as SQL
1555-
15561554
# - if query needs jqr, which for src_mariadb is
15571555
# whenever there is a query specified by the
15581556
# user, at any level of depth in the json structure,
15591557
# since queries cannot sufficiently be translated
15601558
# with SQ and JSON functions in MariaDB 12.
15611559
fldQ$jqrWhere <- character(0L)
15621560
if (length(fldQ$queryCondition)) fldQ$jqrWhere <- fldQ$queryJq
1563-
# special case: if no query and only includeFields, no need for jq
1561+
#
1562+
# special case: if no query and only root includeFields, no need for jq
15641563
if (!length(fldQ$queryCondition) &&
1565-
!length(fldQ$excludeFields)) fldQ$includeFields <- character(0L)
1564+
!length(fldQ$excludeFields) &&
1565+
length(fldQ$includeFields) &&
1566+
!grepl(".", fldQ$includeFields, fixed = TRUE)) fldQ$includeFields <-
1567+
character(0L)
1568+
#
15661569
# special case: jq needed, _id not in excludeFields,
15671570
# thus _id needs to be in includeFields
15681571
if (length(fldQ$queryCondition) &&

README.Rmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ result <- rbenchmark::benchmark(
336336
# 2026-07-11 with M3 hardware, databases via homebrew
337337
result[ , c("test", "replications", "elapsed")]
338338
# test replications elapsed
339-
# 5 SQLite 3 1.1
340-
# 1 DuckDB 3 1.1
341-
# 3 MongoDB 3 2.0
342-
# 4 PostgreSQL 3 2.0
343-
# 2 MariaDB 3 3.0
339+
# 1 DuckDB 3 0.85
340+
# 5 SQLite 3 0.91
341+
# 4 PostgreSQL 3 1.94
342+
# 2 MariaDB 3 2.70
343+
# 3 MongoDB 3 2.86
344344
# 7 Elastic 3 29.0
345345
# 6 CouchDB 3 57.4
346346
@@ -353,7 +353,7 @@ for (pkg in pkgs) message(pkg, ": ", packageVersion(pkg))
353353
# RSQLite: 3.53.3
354354
# duckdb: 1.5.4.3
355355
# RPostgres: 1.4.10
356-
# mongolite: 4.0.0
356+
# mongolite: 4.1.0
357357
# elastic: 1.2.2
358358
# sofa: 0.4.0
359359
# RMariaDB: 1.3.5

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,11 @@ result <- rbenchmark::benchmark(
372372
# 2026-07-11 with M3 hardware, databases via homebrew
373373
result[ , c("test", "replications", "elapsed")]
374374
# test replications elapsed
375-
# 5 SQLite 3 1.1
376-
# 1 DuckDB 3 1.1
377-
# 3 MongoDB 3 2.0
378-
# 4 PostgreSQL 3 2.0
379-
# 2 MariaDB 3 3.0
375+
# 1 DuckDB 3 0.85
376+
# 5 SQLite 3 0.91
377+
# 4 PostgreSQL 3 1.94
378+
# 2 MariaDB 3 2.70
379+
# 3 MongoDB 3 2.86
380380
# 7 Elastic 3 29.0
381381
# 6 CouchDB 3 57.4
382382

@@ -389,7 +389,7 @@ for (pkg in pkgs) message(pkg, ": ", packageVersion(pkg))
389389
# RSQLite: 3.53.3
390390
# duckdb: 1.5.4.3
391391
# RPostgres: 1.4.10
392-
# mongolite: 4.0.0
392+
# mongolite: 4.1.0
393393
# elastic: 1.2.2
394394
# sofa: 0.4.0
395395
# RMariaDB: 1.3.5

0 commit comments

Comments
 (0)