Get record from a select and not just the RID

119 views
Skip to first unread message

Chris Whalen

unread,
Aug 13, 2015, 6:21:37 PM8/13/15
to OrientDB
I could not find this question answered anywhere, though I expect it common.

I have a server function that gets a Person's ancestors

Function: GetAncestors
Parameters: rid


select * from (traverse out('IsChildOf') from " + rid + ") where $depth >= 1 order by $path"

Now when I get my list of people

select *, GetAncestors(@rid) as Ancestors from Person order by Name

The ancestors are returned simply as rids.  Is there a way to get the actual record?  I noticed that if I change my GetAncestors function, and specify specific properties instead of "*", the list of people will now have records for the ancestors.  My problem is that I cannot hard code the properties in the function as there is not a set schema for a Person.  I know this shouldn't be the default behavior, for cases of a giant set of records, but is there a way to force this for specific cases?

user.w...@gmail.com

unread,
Aug 14, 2015, 11:57:19 AM8/14/15
to OrientDB
Hi Chris,

Try this:

select expand(Ancestors) from (select GetAncestors(@rid) as Ancestors from Person order by name)

Regards, 
Michela

Chris Whalen

unread,
Aug 17, 2015, 12:39:18 PM8/17/15
to OrientDB
I appreciate the suggestion however hat doesn't seem to output the desired behavior.

When I run:

select *, GetAncestors(@rid) as Ancestors from Person order by Name

I get the following:

{
    "result": [
        {
            "@type": "d",
            "@rid": "#-2:0",
            "@version": 0,
            "rid": "#22:0",
            "Name": "Frank",
            "Ancestors": [
                
            ],
            "@fieldTypes": "rid=x"
        },
        {
            "@type": "d",
            "@rid": "#-2:1",
            "@version": 0,
            "rid": "#22:1",
            "Name": "Bob",
            "Ancestors": [
                "#22:0"
            ],
            "@fieldTypes": "rid=x"
        },
        {
            "@type": "d",
            "@rid": "#-2:2",
            "@version": 0,
            "rid": "#22:2",
            "Name": "Dave",
            "Ancestors": [
                "#22:0"
            ],
            "@fieldTypes": "rid=x"
        },
        {
            "@type": "d",
            "@rid": "#-2:3",
            "@version": 0,
            "rid": "#22:3",
            "Name": "Chad",
            "Ancestors": [
                "#22:1",
                "#22:0"
            ],
            "@fieldTypes": "rid=x"
        }
    ],
    "notification": "Query executed in 0.296 sec. Returned 4 record(s)"
}

What I would like is:

{
  "result": [
    {
      "@type": "d",
      "@rid": "#-2:0",
      "@version": 0,
      "rid": "#22:0",
      "Name": "Frank",
      "Ancestors": [],
      "@fieldTypes": "rid=x"
    },
    {
      "@type": "d",
      "@rid": "#-2:1",
      "@version": 0,
      "rid": "#22:1",
      "Name": "Bob",
      "Ancestors": [
        {
          "@type": "d",
          "@rid": "#-2:0",
          "@version": 0,
          "rid": "#22:0",
          "Name": "Frank",
          "Ancestors": [],
          "@fieldTypes": "rid=x"
        }
      ],
      "@fieldTypes": "rid=x"
    },
    {
      "@type": "d",
      "@rid": "#-2:2",
      "@version": 0,
      "rid": "#22:2",
      "Name": "Dave",
      "Ancestors": [
        {
          "@type": "d",
          "@rid": "#-2:0",
          "@version": 0,
          "rid": "#22:0",
          "Name": "Frank",
          "Ancestors": [],
          "@fieldTypes": "rid=x"
        }
      ],
      "@fieldTypes": "rid=x"
    },
    {
      "@type": "d",
      "@rid": "#-2:3",
      "@version": 0,
      "rid": "#22:3",
      "Name": "Chad",
      "Ancestors": [
        {
          "@type": "d",
          "@rid": "#-2:0",
          "@version": 0,
          "rid": "#22:0",
          "Name": "Frank",
          "Ancestors": [],
          "@fieldTypes": "rid=x"
        },
        {
          "@type": "d",
          "@rid": "#-2:1",
          "@version": 0,
          "rid": "#22:1",
          "Name": "Bob",
          "Ancestors": [
            "#22:0"
          ],
          "@fieldTypes": "rid=x"
        }
      ],
      "@fieldTypes": "rid=x"
    }
  ],
  "notification": "Query executed in 0.296 sec. Returned 4 record(s)"
}

When I run your suggestion:

select expand(Ancestors) from (select GetAncestors(@rid) as Ancestors from Person order by name)

 I get:

{
    "result": [
        {
            "@type": "d",
            "@rid": "#-2:0",
            "@version": 0,
            "rid": "#22:0",
            "Name": "Frank",
            "Ancestors": [
                
            ],
            "@fieldTypes": "rid=x"
        },
        {
            "@type": "d",
            "@rid": "#-2:0",
            "@version": 0,
            "rid": "#22:0",
            "Name": "Frank",
            "Ancestors": [
                
            ],
            "@fieldTypes": "rid=x"
        },
        {
            "@type": "d",
            "@rid": "#-2:1",
            "@version": 0,
            "rid": "#22:1",
            "Name": "Bob",
            "Ancestors": [
                "#22:0"
            ],
            "@fieldTypes": "rid=x"
        },
        {
            "@type": "d",
            "@rid": "#-2:0",
            "@version": 0,
            "rid": "#22:0",
            "Name": "Frank",
            "Ancestors": [
                
            ],
            "@fieldTypes": "rid=x"
        }
    ],
    "notification": "Query executed in 0.287 sec. Returned 4 record(s)"
}

user.w...@gmail.com

unread,
Aug 18, 2015, 5:28:30 AM8/18/15
to OrientDB
Hi Chris,

I can't do exactly what you want, the only thing that I can do is this:

select *, GetAncestors(@rid).include("name") as Ancestors from Person order by Name

{
    "result": [
        {
            "@type": "d",
            "@rid": "#12:0",
            "@version": 4,
            "@class": "Person",
            "name": "Anna",
            "in_IsChildOf": [
                "#13:1"
            ],
            "Ancestors": [
                
            ],
            "@fieldTypes": "in_IsChildOf=g"
        },
        {
            "@type": "d",
            "@rid": "#12:1",
            "@version": 3,
            "@class": "Person",
            "name": "Mario",
            "out_IsChildOf": [
                "#13:1"
            ],
            "in_IsChildOf": [
                "#13:4"
            ],
            "Ancestors": [
                {
                    "@type": "d",
                    "@version": 0,
                    "name": "Anna"
                }
            ],
            "@fieldTypes": "out_IsChildOf=g,in_IsChildOf=g,Ancestors=z"
        },
        {
            "@type": "d",
            "@rid": "#12:2",
            "@version": 3,
            "@class": "Person",
            "name": "Luca",
            "in_IsChildOf": [
                "#13:0"
            ],
            "out_IsChildOf": [
                "#13:4"
            ],
            "Ancestors": [
                {
                    "@type": "d",
                    "@version": 0,
                    "name": "Mario"
                },
                {
                    "@type": "d",
                    "@version": 0,
                    "name": "Anna"
                }
            ],
            "@fieldTypes": "in_IsChildOf=g,out_IsChildOf=g,Ancestors=z"
        },
        {
            "@type": "d",
            "@rid": "#12:3",
            "@version": 4,
            "@class": "Person",
            "name": "Andrea",
            "out_IsChildOf": [
                "#13:0"
            ],
            "Ancestors": [
                {
                    "@type": "d",
                    "@version": 0,
                    "name": "Luca"
                },
                {
                    "@type": "d",
                    "@version": 0,
                    "name": "Mario"
                },
                {
                    "@type": "d",
                    "@version": 0,
                    "name": "Anna"
                }
            ],
            "@fieldTypes": "out_IsChildOf=g,Ancestors=z"
        }
    ],
    "notification": "Query executed in 0.06 sec. Returned 4 record(s)"
}

Regards,
Michela

Chris Whalen

unread,
Aug 18, 2015, 11:06:46 AM8/18/15
to OrientDB
Yeah, that is as close as I could get as well.  I think there should be a way to do a ".include("*") and get back the entire record.  It would save me a couple more trips back to the database to fetch the records.  Thanks for your attempt.

Chris Whalen

unread,
Aug 19, 2015, 4:20:41 PM8/19/15
to orient-...@googlegroups.com
I think I might have gotten closer utilizing fetch plans.  I'll let you know what I come up with.

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/4ltzMIfg7rk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Chris Whalen
cwhal...@gmail.com

Chris Whalen

unread,
Aug 19, 2015, 11:11:32 PM8/19/15
to OrientDB
I am pretty sure that fetch plans are what I'm looking for.  I've shifted my question to focus on fetch plans and how to get them to resolve peroperly.  That question can be found here.  I think this question thread can be marked as closed.
To unsubscribe from this group and all its topics, send an email to orient-database+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Chris Whalen
cwhal...@gmail.com
Reply all
Reply to author
Forward
0 new messages