pyorient icon indicating copy to clipboard operation
pyorient copied to clipboard

nested records not fetched

Open kived opened this issue 9 years ago • 2 comments

When a query includes nested records, pyorient does not include the nested records, but rather a link to the nested record (or tries to, in the case of temporary records, see #209). Orient Studio returns the nested records themselves. This is particularly an issue in the case of temporary records, as you can't simply select the temporary record in a separate query.

For example, with the query select 1, $t let $t=(select 1), the oRecordData of the first record is (with my monkey patch to fix temporary record links):

screen shot 2016-08-15 at 14 49 49

The result is the same with non-temporary records, example select 1, $t let $t=(select from some_table limit 1) fetchplan *:1:

screen shot 2016-08-15 at 14 57 53

While Studio includes the actual nested record data:

screen shot 2016-08-15 at 14 52 25

Raw response as shown in Studio:

{
    "result": [
        {
            "1": 1,
            "@type": "d",
            "@rid": "#-2:3",
            "@version": 0,
            "$t": [
                {
                    "1": 1,
                    "@type": "d",
                    "@rid": "#-2:1",
                    "@version": 0
                }
            ],
            "@fieldTypes": "$t=z"
        }
    ],
    "notification": "Query executed in 0.043 sec. Returned 1 record(s)"
}

Studio also properly includes the nested data automatically for temporary records (like (select 1)), and includes the nested data for a persisted record when using an appropriate fetchplan. (I won't show an example here as I can't share details of our data or structures).

My current workaround is to convert the result to JSON in my query (select @this.toJSON() as data from (...)), then parse the returned JSON in Python.

kived avatar Aug 15 '16 22:08 kived

Hi,

Can you share some code snippets on how you are processing the (select @this.toJSON() as data from (...))? I has a similar query but was getting a JSON serialisation issue? Refer my issue 217 just posted?

Thanks

kfloz avatar Sep 23 '16 16:09 kfloz

@kfloz

            process = respond

            if jsonify:
                def process(v):
                    return respond(loads(v.oRecordData['data']))
                query = 'SELECT @this.toJson() AS data FROM ({})'.format(query)

            result = self.client_command(query)
            response = [process(v) for v in result]

respond() is my helper for preparing a response for use in my application, self.client_command() is simply a reconnecting wrapper around OrientDB().command().

As noted in the responses to your issue #217, the result will still be an OrientDB record response with a single field - by default it will be named this, I just prefer to alias it as data.

kived avatar Oct 17 '16 17:10 kived