orientjs icon indicating copy to clipboard operation
orientjs copied to clipboard

Query has different outputs in studio and orientjs db.query

Open shyamchandranmec opened this issue 9 years ago • 19 comments

When we execute the below query in orientdb studio it shows the comment with a nested json named author which has name and rid in it.

select *, $author as author from Comment let $author = (select name, @rid from User where out(WROTE_COMMENT).@rid in $parent.current.@rid ) where in(HAS_COMMENT) in [#15:2]

screen shot 2016-01-31 at 3 00 26 pm

But when this is executed using orientjs db.query, the author property is an array with some random id.

`class: "Comment"

rid: "#28:1"

type: "d"

version: 1

author: ["#-2:0"]

comment: "comment one"

`

How can I get the same output as I get in orient studio

shyamchandranmec avatar Jan 31 '16 09:01 shyamchandranmec

hi @shyamchandranmec i'm checking

wolf4ood avatar Feb 01 '16 10:02 wolf4ood

@shyamchandranmec

How is your model?

Post <-> Comment <-> User?

wolf4ood avatar Feb 03 '16 15:02 wolf4ood

Which record type is #15:2?

wolf4ood avatar Feb 03 '16 15:02 wolf4ood

hi @maggiolo00

#15:2 is Post..

and the model is like this..

Post ----out(HAS_COMMENT)---Comment
Comment ----in(WROTE_COMMENT)---User

If you need the db dump I can give it...

shyamchandranmec avatar Feb 04 '16 04:02 shyamchandranmec

hi @shyamchandranmec yes with the dump i can quickly help you This is my email [email protected] Thanks

wolf4ood avatar Feb 04 '16 07:02 wolf4ood

@maggiolo00

I have sent the db dump to your mail. Thanks

shyamchandranmec avatar Feb 05 '16 06:02 shyamchandranmec

@shyamchandranmec

you could use this query that is more optimized. You will not have where condition just use the graph property starting from Post rid #15:2

select *,$author.name as authorName,$author as authorRid from (select expand(out('Has_Comment')) from #15:2) let $author = in('Wrote_Comment')[0]

wolf4ood avatar Feb 09 '16 12:02 wolf4ood

@maggiolo00 , Thanks for your time. I will try this out.

shyamchandranmec avatar Feb 10 '16 04:02 shyamchandranmec

hi @shyamchandranmec

did you have the chance to try it out?

wolf4ood avatar Feb 15 '16 11:02 wolf4ood

Hi, I was a bit busy with other tasks.. I will try this asap...

Thanks Shyam Chandran

On Mon, Feb 15, 2016 at 5:07 PM, Enrico Risa [email protected] wrote:

hi @shyamchandranmec https://github.com/shyamchandranmec

did you have the chance to try it out?

— Reply to this email directly or view it on GitHub https://github.com/orientechnologies/orientjs/issues/139#issuecomment-184176528 .

shyamchandranmec avatar Feb 15 '16 11:02 shyamchandranmec

I'm getting a really odd situation as well where the query in orientdb studio returns results different than the exact same query placed inside db.query()

In particular, I have some subqueries in a LET statement but once it gets returned by orientjs in db.query(), the results of the subquery don't match the right row being returned.

However, it works fine in orientdb studio.

Can I reach out to you @maggiolo00 via email with more details?

EricLin2004 avatar Feb 18 '16 23:02 EricLin2004

hi @EricLin2004 yes drop me an email i will look at it tomorrow

wolf4ood avatar Feb 18 '16 23:02 wolf4ood

@maggiolo00

I checked my code. I am already doing this as a workaround to this problem. What I tried to achieve is to get the user details as a separate nested json. For which I tried the query which I have asked in the question.

The output of that query is different in both studio and db.query.... Is this a bug?

shyamchandranmec avatar Mar 05 '16 06:03 shyamchandranmec

@maggiolo00 Any updates on this?

shyamchandranmec avatar Mar 07 '16 13:03 shyamchandranmec

hi @shyamchandranmec

which api are you using to query?

the query builder or raw query?

wolf4ood avatar Mar 07 '16 15:03 wolf4ood

Try this should work with fetchplan

db.query('select *, $author as author from Comment let $author = (select name,@rid from User where out(WROTE_COMMENT).@rid in $parent.current.@rid ) where in(HAS_COMMENT) in [#15:2]',{
        fetchPlan : "author:1"
    })
    .then(function(res){

        res.forEach(function(r){
            console.log(r);
        });
    })

wolf4ood avatar Mar 07 '16 15:03 wolf4ood

hi @shyamchandranmec

did you try the solution with fetchPlan?

wolf4ood avatar Mar 08 '16 11:03 wolf4ood

hi @shyamchandranmec did you try it?

wolf4ood avatar Apr 29 '16 14:04 wolf4ood

hi @shyamchandranmec

Any updates?

wolf4ood avatar Aug 01 '16 14:08 wolf4ood