Projections for nested documents in query
See original GitHub issueThe problem
Current syntax of projections comes from relational world where everything is a flat table. However there is links and nested records in document model. And there is no possibility to project fields of linked or nested documents and keep nesting.
There is a possibility to prevent loading of some fields of linked documents using fetch plan. But it is not allow to include only specific fields.
For example you have a Shop, Merchandise and Producer. And you want to select all shops with merchandise and its producers, but producer have a lot of properties and you need to load only its name and country.
SELECT name, include(merchandise, 'name', 'producer') FROM Shop
The query above loads all properties of producer.
fetchPlan and include/exclude functions Some use-cases can be implemented by fetchPlan and include/exclude functions, however this is less convenient and provide less flexibility.
Proposed syntax
selectQuery ::= SELECT <projections> FROM ...
projections ::= <projection>(, <projection>)*
projection ::= <fieldName>(':{' <projections> '}')? (as <alias>)?
Examples
SELECT
name,
address:{country:{name, capital} as country, city.name as city, street, building}
FROM Customer
Result example:
{
name: "Customer1"
address: {
country: {
name: "Ukraine",
capital: "Kiev"
}
town: "Dnipropetrovsk"
street: "..."
building: 99
}
}
Graph example:
SELECT
name,
out('repositories').out('commits'):{date, message} as commits
FROM Developer
Result example:
{
name: "Martin",
commits: [
{date: "12-08-2013", message: "Fix minor bug"}
{date: "13-08-2013", message: "Fix major bug"}
]
}
Issue Analytics
- State:
- Created 10 years ago
- Comments:24 (16 by maintainers)
Top GitHub Comments
The nested projection syntax is implemented in develop branch (3.0 SNAPSHOT). It will be released with 3.0 M2.
For more details https://github.com/orientechnologies/orientdb-docs/blob/3.0.x/sql/SQL-Projections.md
Is there a way for doing this with the projection api?
https://stackoverflow.com/questions/49495351/orientdb-returning-json-with-embedded-vertices-from-a-match-query
I’m trying for hours now and I can’t find the right syntax or any examples of this use case.