question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetchPlan returning extra properties

See original GitHub issue

I’m using OrientDB v.2.1.1 with useLightweightEdges property set to true. Using fetchPlan queries often return extra properties non included in the query or even some of properties excluded in more ways.

Here is an example:

Given this simple structure

User    V     #13
Event   V     #14
Org     V     #15
Media   V     #16

admin   E     User  --> Org
follow  E     User  --> Org
author  E     Event --> Org
avatar  E     Org   --> Media
thumb   E     Event --> Media

I need to write a query that fetches a specific Event, its relative thumb, author and the author’s avatar. Nothing else.

1st query:

SELECT @this.toJSON('rid,class,fetchPlan:[*]in_*:-2 [*]out_*:-2 out_thumb:0 out_author:0 out_author.out_avatar:0') FROM Event WHERE @rid = #14:8

Returns:

{
    "@rid": "#14:8",
    "@class": "Event",
    "name": "EVENT_TEST",
    "out_author": [
        {
            "@rid": "#15:0",
            "@class": "Org",
            "name": "ORG_TEST",
            ! "in_admin": [ "#13:0", "#13:5", "#13:6", "#13:9", "#13:10", "#13:13" ],
            ! "in_follow": [ "#13:0", "#13:4", "#13:5", "#13:6", "#13:14", "#13:15" ],
            ! "in_author": [ "#14:6", "#14:7", "#14:8", "#14:9", "#14:10", "#14:11" ],
            "out_avatar": [
                {
                    "@rid": "#16:2",
                    "@class": "Media",
                    "url": "www.image.com",
                    ! "in_thumb": [ "#14:4", "#14:6", "#14:7", "#14:12", "#14:14", "#14:15" ],
                    ! "in_avatar": [ "#15:0" ]
                }
            ]
        }
    ],
    "out_thumb": [
        {
            "@rid": "#16:1",
            "@class": "Media",
            "url": "www.image.com",
            ! "in_thumb": [ "#14:2", "#14:5", "#14:8", "#14:9", "#14:10", "#14:13" ],
            ! "in_avatar": [ "#15:2" ]
        }
    ]
}

Where these properties should have been excluded: out_author.in_admin out_author.in_follow out_author.in_author out_author.out_avatar.in_thumb out_author.out_avatar.in_avatar out_thumb.in_thumb out_thumb.in_avatar

2nd query:

made by adding some parameters to the 1st query to explicitly exclude the extra properties

SELECT @this.toJSON('rid,class,fetchPlan:[*]in_*:-2 [*]out_*:-2 out_thumb:0 out_author:0 out_author.out_avatar:0 [*]in_avatar:-2 [*]in_thumb:-2 [*]in_author:-2 [*]in_admin:-2 [*]in_follow:-2') FROM Event WHERE @rid = #14:8

Returns

{
    "@rid": "#14:8",
    "@class": "Event",
    "name": "EVENT_TEST",
    "out_author": [
        {
            "@rid": "#15:0",
            "@class": "Org",
            "name": "ORG_TEST",
            ! "in_admin": [ "#13:0", "#13:5", "#13:6", "#13:9", "#13:10", "#13:13" ],
            ! "in_follow": [ "#13:0", "#13:4", "#13:5", "#13:6", "#13:14", "#13:15" ],
            "out_avatar": [
                {
                    "@rid": "#16:2",
                    "@class": "Media",
                    "url": "www.image.com"
                }
            ]
        }
    ],
    "out_thumb": [
        {
            "@rid": "#16:1",
            "@class": "Media",
            "url": "www.image.com"
        }
    ]
}

Partially works since removes out_author.in_author out_author.out_avatar.in_thumb out_author.out_avatar.in_avatar out_thumb.in_thumb out_thumb.in_avatar

But it doesn’t remove out_author.in_admin out_author.in_follow

3nd query:

made by adding some parameters to the 2st query to even more explicitly exclude the extra properties remained

SELECT @this.toJSON('rid,class,fetchPlan:[*]in_*:-2 [*]out_*:-2 out_thumb:0 out_author:0 out_author.out_avatar:0 [*]in_avatar:-2 [*]in_thumb:-2 [*]in_author:-2 [*]in_admin:-2 [*]in_follow:-2 out_author.in_admin:-2 out_author.in_follow:-2') FROM Event WHERE @rid = #14:8

Returns:

// The same as for 2nd query 

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
micha-nerdlichtercommented, Oct 20, 2015

…even nicer: use “as” to rename the edges:

select
  outE("thumb").include("url","type","size") as thumb,
  outE("author").include("name") as author,
  outE("author").outE("avatar").include("url") as avatar
from #13:0
1reaction
micha-nerdlichtercommented, Oct 20, 2015

I don’t understand why you are using the toJSON-function, this looks so complicated… why not use the outE()-function with include()?

select outE("thumb").include("url","type","size"), outE("author").include("name"), outE("author").outE("avatar").include("url") from #14:8

Btw if you replace the ... from Event where @rid with select ... from #14:8 your query is faster.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FetchPlans & Partial object data loading | Telerik Forums
I tried to load an object using a fetchplan where only the ID and a NAME property should be loaded for that object...
Read more >
How to keep a few properties in each returned object from a ...
I got a fetch call that return 100+ objects in an array. Each object got about 10 properties. I want to keep only...
Read more >
7. Fetch Groups - Apache OpenJPA
The FetchGroup annotation has the following properties: ... The FetchPlan maintains the set of active fetch groups and the maximum fetch depth.
Read more >
Chapter 12. Fetch plans, strategies, and profiles
What Hibernate loads depends on the fetch plan: you define the (sub)graph of the network of ... EXTRA ) public Set<Bid> getBids() {...
Read more >
Chapter 19. Improving performance
"Extra-lazy" collection fetching - individual elements of the collection ... (This is Hibernate's equivalent of what some ORM solutions call a "fetch plan".)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found