FETCH PROP - keep sorting order

Nebula Graph: 3
Github issue: https://github.com/vesoft-inc/nebula/issues/3960
Problem: Using FETCH PROP loses sort order
Question: Shylock-Hg suggests on Github to use ORDER BY clause (does not work for me)

Example:

GO FROM "userid" OVER `follow` YIELD `follow`._dst AS following, `follow`._rank as rank | 
    LIMIT 10 | 
    FETCH PROP ON * $-.following YIELD vertex AS v, $-.rank | 
    ORDER BY $-.rank;

YIELDing $.rank fails:
[ERROR (-1009)]: SemanticError: unsupported input/variable property expression in yield.

Dear @doublemax ,

It should be ordered as follow for the query you had put in the issue.

(root@nebula) [basketballplayer]> GO FROM "player100" OVER `follow` YIELD `follow`._dst AS following | FETCH PROP ON * $-.following YIELD vertex AS v, properties(vertex).name as name | ORDER BY $-.name
+-------------------------------------------------------+-----------------+
| v                                                     | name            |
+-------------------------------------------------------+-----------------+
| ("player125" :player{age: 41, name: "Manu Ginobili"}) | "Manu Ginobili" |
| ("player101" :player{age: 36, name: "Tony Parker"})   | "Tony Parker"   |
+-------------------------------------------------------+-----------------+
Got 2 rows (time spent 2502/19356 us)

While in this query pattern, fetch is actually not needed, you could instead yield them in the go sentence directly.

(root@nebula) [basketballplayer]> GO FROM "player100" OVER `follow` YIELD properties($$) AS v, properties($$).name AS name | ORDER BY $-.name
+----------------------------------+-----------------+
| v                                | name            |
+----------------------------------+-----------------+
| {age: 41, name: "Manu Ginobili"} | "Manu Ginobili" |
| {age: 36, name: "Tony Parker"}   | "Tony Parker"   |
+----------------------------------+-----------------+
Got 2 rows (time spent 2175/127370 us)

Thu, 03 Mar 2022 14:06:28 CST

Dear @wey,

Thanks you very much for your help!

The first suggestion fails, because we need to ORDER BY “edge-weight” (excellent feature by the way).
The second solution is a clever idea, but does not answer the property name, e.g.:

+-----------------------------------------------------+
| ("user-id", {created:1282730149, region:"CH", ...}) |
+-----------------------------------------------------+

but should answer the property-name user:

+----------------------------------------------------------+
| ("user-id", user:{created:1282730149, region:"CH", ...}) |
+----------------------------------------------------------+

It would be all easy if FETCH PROP would keep the order…

Best wishes!
Markus

1 Like

Dear @wey,

Your second suggestion was the solution:

GO FROM "userid" OVER `follow` YIELD $$ as v;

Somethimes you can’t see the wood for trees.

Though it would still be helpful if FETCH PROP would keep the order, e.g. after GROUP BY

Again, thanks for your kind help!
Best wishes

1 Like

Dear Markus,

I am glad the GO clause already fits your needs :slight_smile: !

The issue we hit here is actually not related to ORDER BY, instead, it’s only related to FETCH.

The minimal reproduce would be:

(root@nebula) [basketballplayer]> YIELD "player100" AS foo | FETCH PROP ON * $-.foo YIELD vertex as v,
+----------------------------------------------------+
| v                                                  |
+----------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------+
Got 1 rows (time spent 1736/47438 us)


(root@nebula) [basketballplayer]> YIELD "player100" AS foo | FETCH PROP ON * $-.foo YIELD vertex as v, $-.foo as foo
[ERROR (-1009)]: SemanticError: unsupported input/variable property expression in yield.

Fri, 04 Mar 2022 12:23:32 CST

It is meant to support the pattern to YIELD variable but not just to put it as input of FETCH itself.

Do you really see its use case? If so, could you help raise it as an issue with the use case described?

Thanks again(welcome back to the community)!

BR//Wey

Dear @wey,

Your “edge weight” feature is just too good. :hugs:
Fast queries and excellent elite resultsets.

Simplified example (everything works perfect, only the FETCH PROP clause changes the sort order):

GO FROM "user-100" OVER click YIELD click._dst AS post, click._rank AS rank | LIMIT 10000 |
GROUP BY $-.post YIELD $-.post AS post, sum($-.rank) AS rank | 
ORDER BY $-.rank DESC | LIMIT 100 |
FETCH PROP ON * $-.post YIELD vertex AS v

If you dedice WONTFIX - not a big issue.

Thanks for all your efforts + best wishes
Markus

1 Like

Dear Markus,

Thanks a lot for your nice word(this means a lot to us)!

Just in case you missed this, the reason you don’t yield vertex in the initial GO sentence was due to it being slower compared to only fetch prop on 100 of them, right ?(which is indeed optimal to fetch after limit 100)

GO FROM "user-100" OVER click YIELD click._dst AS post, click._rank AS rank , properties($$) AS v | LIMIT 10000 |
GROUP BY $-.post YIELD $-.post AS post, sum($-.rank) AS rank | 
ORDER BY $-.rank DESC | LIMIT 100

Also, now I understand that the ability to pass variables into piped fetch enables you to sort based on it.

This is the issue on this: Enable piped var being yield in FETCH PROP · Issue #3984 · vesoft-inc/nebula · GitHub
It’s more than welcomed to add things there.

Thanks!
BR//Wey

Dear @wey,

You summed it up better. Thanks for creating #3984!
Nebula is really very well thought out.

Best wishes from Vienna!
Markus

1 Like

Thanks a lot, Markus for your kind word!

PS. I was lucky enough to visit Vienna once before the pandemic, beautiful city of art and history!
:heart: from Shanghai
Wey