So far (nodbi 0.4.2), docdb_query.src_sqlite would not return those values from records that are objects (and contain further json data). This was because json_extract() was used, which requires a full json path including numerators for all child objects (https://www.sqlite.org/json1.html#jex).
General handling of objects was not included in my initial implementation of nodbi functions for the RSQLite backend. The PR covers this important use case and enables to retrieve all fields from all paths such as "friends.name". This works by now using json_tree(), finding elements whose paths match the specified fields and by casting values into their reported type (see https://sqlite.org/json1.html#jeach).
The major changes are in docdb_query, which is subsequently used more by other docdb_* functions. At the same time, the code is simpler and cleaner.
Example
The contacts are a json data set that is part of the nodbi package and its friends field has subitems with keys name and id. With this PR, friends in the returned data.frame is a column that is a list with one data.frame per row. More complex objects will have more nesting levels of lists and data frames. The mapdata is additionally included in the package and used below to show how several fields can be extraacted using simple regular expressions (noting that square brackets are not supported because they are used in json strings).
Description
So far (
nodbi
0.4.2),docdb_query.src_sqlite
would not return those values from records that are objects (and contain further json data). This was becausejson_extract()
was used, which requires a full json path including numerators for all child objects (https://www.sqlite.org/json1.html#jex).General handling of objects was not included in my initial implementation of nodbi functions for the RSQLite backend. The PR covers this important use case and enables to retrieve all fields from all paths such as "friends.name". This works by now using
json_tree()
, finding elements whose paths match the specified fields and by casting values into their reported type (see https://sqlite.org/json1.html#jeach).The major changes are in
docdb_query
, which is subsequently used more by otherdocdb_*
functions. At the same time, the code is simpler and cleaner.Example
The
contacts
are a json data set that is part of the nodbi package and itsfriends
field has subitems with keysname
andid
. With this PR,friends
in the returned data.frame is a column that is a list with one data.frame per row. More complex objects will have more nesting levels of lists and data frames. Themapdata
is additionally included in the package and used below to show how several fields can be extraacted using simple regular expressions (noting that square brackets are not supported because they are used in json strings).