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

Support for nested database fields #158

Closed
javierluraschi opened this issue Sep 11, 2018 · 4 comments
Closed

Support for nested database fields #158

javierluraschi opened this issue Sep 11, 2018 · 4 comments
Labels
feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL
Milestone

Comments

@javierluraschi
Copy link
Contributor

It is increasingly common for databases to support unstructured data, for instance, in Apache Spark or Apache Drill; however, to my knowledge this might not be supported in dbplyr, is it?

A common case is to selected nested fields from within a field, two examples:

writeLines('[{"a":1,"b":{"a":10,"b":100}},{"a":2,"b":{"a":20,"b":200}}]', "test.json")

library(sparklyr)
sc <- spark_connect(master = "local")

nested_tbl <- spark_read_json(sc, "nested", "test.json")

# SQL query is supported
DBI::dbGetQuery(sc, "SELECT b.a FROM nested")
   a
1 10
2 20
# Query in dplyr...
nested_tbl %>% select(b.a)
 Error in .f(.x[[i]], ...) : object 'b.a' not found 
@hadley
Copy link
Member

hadley commented Jan 2, 2019

I think we could add support for something like this:

nested_tbl %>% mutate(a = b$a)

If you're interested in this feature, the most helpful think would be to provide a bulleted for each database linking to the docs for nested fields

@hadley hadley added feature a feature request or enhancement help wanted ❤️ we'd love your help! func trans 🌍 Translation of individual functions to SQL labels Jan 2, 2019
@hadley
Copy link
Member

hadley commented Jan 3, 2019

I think that's enough to suggest that we can translate $ to ..

@roboton
Copy link

roboton commented Nov 17, 2021

There are a number of JSON operators in Postgres that also query nested structures: https://www.postgresql.org/docs/12/functions-json.html

Is this something that could be considered for dbplyr?

@MattCowgill
Copy link

This would be a very useful feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL
Projects
None yet
Development

No branches or pull requests

4 participants