nebula-graph

Does nGQL allow you to reference the VID of two tags in a query ? (rather the VID of one and the property of the other?


I use the following two queries in nGQL to create instances of two tags:

INSERT VERTEX Topic (topicId, first_proposed, approval_status,
followers, tagged_tally) VALUES 9999:("Sample topic id", TIMESTAMP(),
"Pending", 10, 20);

INSERT VERTEX Post(text_added, last_updated, author, postId,
creation_date, shared_total, flagged_total, views, total_likes,
is_a_repost, post_format) VALUES 4444: ("Sample text", timestamp(),
"John Doe", 1234, TIMESTAMP(), 0, 0, 0, 0, false, "some format");

I use the following edge multiple times between the topic instance with VID 9999 and the Post with VID 4444, in which I change the timestamp value, and to do so I repeat the following INSERT EDGE statement:

INSERT EDGE is_tagged (when_tagged) VALUES 4444 -> 9999:(timestamp('2023-06-11T02:18:43'));

I now wish to count the total number of these edge occurrences. The closest I have managed is the following:

GO FROM 4444 OVER is_tagged WHERE $$.Topic.topicId == "Sample topic id" YIELD edge AS e | GROUP BY $-.e YIELD COUNT(*) AS number;

However I wish to reference 9999 and not have to replace the VID for Topic with the property value of Topic_id. How can I do this ? Ideally I want something akin to this:

GO FROM 4444 OVER is_tagged
WHERE VERTEX_ID($$.Topic) == "destination_topic_vid"

or this:

GO FROM 4444 OVER is_tagged
WHERE destination(is_tagged)._dst == 9999
YIELD edge AS e | GROUP BY $-.e YIELD COUNT(*) AS number;

Solution

  • If we know exactly the source and dest VID of the given edge, we could do FETCH to get the edges between the two, your intuition of specifying VID not prop value is correct.

    FETCH PROP ON serve "player100" -> "team204" YIELD src(edge) | YIELD count(*)
    

    One more thing, INSERT EDGE is_tagged (when_tagged) VALUES 4444 -> 9999:(timestamp('2023-06-11T02:18:43')); multiple times will not insert multiple instances of is_tagged edges, instead, it updates one edge's prop:when_tagged a couple of times after the first INSERT.

    One instance of edge in NebulaGraph is (src_id, dst_id, type, rank), where by default, rank is 0 when it's omitted, to enable multiple instances of a given edge per pair of (src, dst), we could put timestamp as RANK field.

    Like:

    INSERT EDGE is_tagged (when_tagged) VALUES 4444 -> 9999@1686449923:(timestamp('2023-06-11T02:18:43'));
    INSERT EDGE is_tagged (when_tagged) VALUES 4444 -> 9999@1686449983:(timestamp('2023-06-11T02:19:43'));
    

    Hope it helps, and welcome to the NebulaGraph community!

    BR//Wey


    update, regarding the approach to do with GO, it's underlying do "expand" from start node to all its edges, then filter, thus technically it's a bit of more expensive :).

    See:

    -----+-----------+--------------+-------------------------------+--------------------------------------------------------------------------------------------------
    | id | name      | dependencies | profiling data                | operator info                                                                                   |
    -----+-----------+--------------+-------------------------------+--------------------------------------------------------------------------------------------------
    |  4 | Aggregate | 3            | {                             | outputVar: {                                                                                    |
    |    |           |              |   "execTime": "40(us)",       |   "colNames": [                                                                                 |
    |    |           |              |   "rows": 1,                  |     "count(*)"                                                                                  |
    |    |           |              |   "totalTime": "44(us)",      |   ],                                                                                            |
    |    |           |              |   "version": 0                |   "type": "DATASET",                                                                            |
    |    |           |              | }                             |   "name": "__Aggregate_4"                                                                       |
    |    |           |              |                               | }                                                                                               |
    |    |           |              |                               | inputVar: __Project_3                                                                           |
    |    |           |              |                               | groupKeys: []                                                                                   |
    |    |           |              |                               | groupItems: [                                                                                   |
    |    |           |              |                               |   {                                                                                             |
    |    |           |              |                               |     "expr": "count(*)"                                                                          |
    |    |           |              |                               |   }                                                                                             |
    |    |           |              |                               | ]                                                                                               |
    -----+-----------+--------------+-------------------------------+--------------------------------------------------------------------------------------------------
    |  3 | Project   | 2            | {                             | outputVar: {                                                                                    |
    |    |           |              |   "execTime": "97(us)",       |   "colNames": [                                                                                 |
    |    |           |              |   "rows": 1,                  |     "src(EDGE)"                                                                                 |
    |    |           |              |   "totalTime": "110(us)",     |   ],                                                                                            |
    |    |           |              |   "version": 0                |   "type": "DATASET",                                                                            |
    |    |           |              | }                             |   "name": "__Project_3"                                                                         |
    |    |           |              |                               | }                                                                                               |
    |    |           |              |                               | inputVar: __Filter_2                                                                            |
    |    |           |              |                               | columns: [                                                                                      |
    |    |           |              |                               |   "src(EDGE)"                                                                                   |
    |    |           |              |                               | ]                                                                                               |
    -----+-----------+--------------+-------------------------------+--------------------------------------------------------------------------------------------------
    |  2 | Filter    | 1            | {                             | outputVar: {                                                                                    |
    |    |           |              |   "execTime": "80(us)",       |   "colNames": [],                                                                               |
    |    |           |              |   "rows": 1,                  |   "type": "DATASET",                                                                            |
    |    |           |              |   "totalTime": "94(us)",      |   "name": "__Filter_2"                                                                          |
    |    |           |              |   "version": 0                | }                                                                                               |
    |    |           |              | }                             | inputVar: __GetEdges_1                                                                          |
    |    |           |              |                               | condition: ((__EMPTY__!=serve._src) AND ((__EMPTY__!=serve._dst) AND (__EMPTY__!=serve._rank))) |
    |    |           |              |                               | isStable: false                                                                                 |
    -----+-----------+--------------+-------------------------------+--------------------------------------------------------------------------------------------------
    |  1 | GetEdges  | 0            | {                             | outputVar: {                                                                                    |
    |    |           |              |   "execTime": "840(us)",      |   "colNames": [],                                                                               |
    |    |           |              |   "resp[0]": {                |   "type": "DATASET",                                                                            |
    |    |           |              |     "exec": "2364(us)",       |   "name": "__GetEdges_1"                                                                        |
    |    |           |              |     "host": "storaged2:9779", | }                                                                                               |
    |    |           |              |     "total": "7274(us)"       | inputVar: __VAR_0                                                                               |
    |    |           |              |   },                          | space: 11                                                                                       |
    |    |           |              |   "rows": 1,                  | dedup: false                                                                                    |
    |    |           |              |   "totalTime": "8126(us)",    | limit: 9223372036854775807                                                                      |
    |    |           |              |   "total_rpc": "7652(us)",    | filter:                                                                                         |
    |    |           |              |   "version": 0                | orderBy: []                                                                                     |
    |    |           |              | }                             | src: COLUMN[0]                                                                                  |
    |    |           |              |                               | type: "14"                                                                                      |
    |    |           |              |                               | ranking: COLUMN[1]                                                                              |
    |    |           |              |                               | dst: COLUMN[2]                                                                                  |
    |    |           |              |                               | props: [                                                                                        |
    |    |           |              |                               |   {                                                                                             |
    |    |           |              |                               |     "props": [                                                                                  |
    |    |           |              |                               |       "_dst",                                                                                   |
    |    |           |              |                               |       "_rank",                                                                                  |
    |    |           |              |                               |       "_src",                                                                                   |
    |    |           |              |                               |       "_type",                                                                                  |
    |    |           |              |                               |       "end_year",                                                                               |
    |    |           |              |                               |       "start_year"                                                                              |
    |    |           |              |                               |     ],                                                                                          |
    |    |           |              |                               |     "type": 14                                                                                  |
    |    |           |              |                               |   }                                                                                             |
    |    |           |              |                               | ]                                                                                               |
    |    |           |              |                               | exprs:                                                                                          |
    -----+-----------+--------------+-------------------------------+--------------------------------------------------------------------------------------------------
    |  0 | Start     |              | {                             | outputVar: {                                                                                    |
    |    |           |              |   "execTime": "0(us)",        |   "colNames": [],                                                                               |
    |    |           |              |   "rows": 0,                  |   "type": "DATASET",                                                                            |
    |    |           |              |   "totalTime": "189(us)",     |   "name": "__Start_0"                                                                           |
    |    |           |              |   "version": 0                | }                                                                                               |
    |    |           |              | }                             |                                                                                                 |
    -----+-----------+--------------+-------------------------------+--------------------------------------------------------------------------------------------------
    
    Thu, 29 Jun 2023 19:59:19 CST
    
    (root@nebula) [basketballplayer]> PROFILE GO FROM "player100" OVER serve WHERE dst(edge) == "team204" YIELD edge AS e | YIELD COUNT(*) AS number;
    +--------+
    | number |
    +--------+
    | 1      |
    +--------+
    Got 1 rows (time spent 29.928ms/41.691958ms)
    
    Execution Plan (optimize time 1842 us)
    
    -----+-----------+--------------+---------------------------------------+------------------------------------
    | id | name      | dependencies | profiling data                        | operator info                     |
    -----+-----------+--------------+---------------------------------------+------------------------------------
    |  6 | Aggregate | 5            | {                                     | outputVar: {                      |
    |    |           |              |   "execTime": "44(us)",               |   "colNames": [                   |
    |    |           |              |   "rows": 1,                          |     "number"                      |
    |    |           |              |   "totalTime": "47(us)",              |   ],                              |
    |    |           |              |   "version": 0                        |   "type": "DATASET",              |
    |    |           |              | }                                     |   "name": "__Aggregate_6"         |
    |    |           |              |                                       | }                                 |
    |    |           |              |                                       | inputVar: __Project_5             |
    |    |           |              |                                       | groupKeys: []                     |
    |    |           |              |                                       | groupItems: [                     |
    |    |           |              |                                       |   {                               |
    |    |           |              |                                       |     "expr": "COUNT(*)"            |
    |    |           |              |                                       |   }                               |
    |    |           |              |                                       | ]                                 |
    -----+-----------+--------------+---------------------------------------+------------------------------------
    |  5 | Project   | 4            | {                                     | outputVar: {                      |
    |    |           |              |   "execTime": "37(us)",               |   "colNames": [                   |
    |    |           |              |   "rows": 1,                          |     "e"                           |
    |    |           |              |   "totalTime": "52(us)",              |   ],                              |
    |    |           |              |   "version": 0                        |   "type": "DATASET",              |
    |    |           |              | }                                     |   "name": "__Project_5"           |
    |    |           |              |                                       | }                                 |
    |    |           |              |                                       | inputVar: __Filter_4              |
    |    |           |              |                                       | columns: [                        |
    |    |           |              |                                       |   "EDGE AS e"                     |
    |    |           |              |                                       | ]                                 |
    -----+-----------+--------------+---------------------------------------+------------------------------------
    |  4 | Filter    | 3            | {                                     | outputVar: {                      |
    |    |           |              |   "execTime": "31(us)",               |   "colNames": [                   |
    |    |           |              |   "rows": 1,                          |     "EDGE"                        |
    |    |           |              |   "totalTime": "41(us)",              |   ],                              |
    |    |           |              |   "version": 0                        |   "type": "DATASET",              |
    |    |           |              | }                                     |   "name": "__Filter_4"            |
    |    |           |              |                                       | }                                 |
    |    |           |              |                                       | inputVar: __ExpandAll_3           |
    |    |           |              |                                       | condition: (dst(EDGE)=="team204") |
    |    |           |              |                                       | isStable: false                   |
    -----+-----------+--------------+---------------------------------------+------------------------------------
    |  3 | ExpandAll | 2            | {                                     | outputVar: {                      |
    |    |           |              |   "execTime": "404(us)",              |   "colNames": [                   |
    |    |           |              |   "graphExpandAllTime+2": "319(us)",  |     "EDGE"                        |
    |    |           |              |   "resp[0]": {                        |   ],                              |
    |    |           |              |     "exec": "7838(us)",               |   "type": "DATASET",              |
    |    |           |              |     "host": "storaged2:9779",         |   "name": "__ExpandAll_3"         |
    |    |           |              |     "storage_detail": {               | }                                 |
    |    |           |              |       "GetNeighborsNode": "3837(us)", | inputVar: __Expand_2              |
    |    |           |              |       "HashJoinNode": "3804(us)",     | space: 11                         |
    |    |           |              |       "RelNode": "3838(us)",          | dedup: false                      |
    |    |           |              |       "SingleEdgeNode": "3801(us)"    | limit: -1                         |
    |    |           |              |     },                                | filter:                           |
    |    |           |              |     "total": "15741(us)"              | orderBy: []                       |
    |    |           |              |   },                                  | sample: false                     |
    |    |           |              |   "rows": 1,                          | joinInput: false                  |
    |    |           |              |   "totalTime": "18340(us)",           | maxSteps: 1                       |
    |    |           |              |   "version": 0                        | edgeProps: [                      |
    |    |           |              | }                                     |   {                               |
    |    |           |              |                                       |     "props": [                    |
    |    |           |              |                                       |       "_dst",                     |
    |    |           |              |                                       |       "_rank",                    |
    |    |           |              |                                       |       "_src",                     |
    |    |           |              |                                       |       "_type",                    |
    |    |           |              |                                       |       "end_year",                 |
    |    |           |              |                                       |       "start_year"                |
    |    |           |              |                                       |     ],                            |
    |    |           |              |                                       |     "type": 14                    |
    |    |           |              |                                       |   }                               |
    |    |           |              |                                       | ]                                 |
    |    |           |              |                                       | stepLimits: []                    |
    |    |           |              |                                       | minSteps: 1                       |
    |    |           |              |                                       | vertexProps:                      |
    |    |           |              |                                       | vertexColumns: []                 |
    |    |           |              |                                       | edgeColumns: [                    |
    |    |           |              |                                       |   "EDGE AS EDGE"                  |
    |    |           |              |                                       | ]                                 |
    -----+-----------+--------------+---------------------------------------+------------------------------------
    |  2 | Expand    | 1            | {                                     | outputVar: {                      |
    |    |           |              |   "execTime": "279(us)",              |   "colNames": [                   |
    |    |           |              |   "rows": 1,                          |     "_expand_vid"                 |
    |    |           |              |   "totalTime": "1274(us)",            |   ],                              |
    |    |           |              |   "version": 0                        |   "type": "DATASET",              |
    |    |           |              | }                                     |   "name": "__Expand_2"            |
    |    |           |              |                                       | }                                 |
    |    |           |              |                                       | inputVar: __VAR_0                 |
    |    |           |              |                                       | space: 11                         |
    |    |           |              |                                       | dedup: false                      |
    |    |           |              |                                       | limit:                            |
    |    |           |              |                                       | filter:                           |
    |    |           |              |                                       | orderBy: []                       |
    |    |           |              |                                       | sample: false                     |
    |    |           |              |                                       | joinInput: false                  |
    |    |           |              |                                       | maxSteps: 0                       |
    |    |           |              |                                       | edgeProps: [                      |
    |    |           |              |                                       |   {                               |
    |    |           |              |                                       |     "props": [                    |
    |    |           |              |                                       |       "_dst"                      |
    |    |           |              |                                       |     ],                            |
    |    |           |              |                                       |     "type": 14                    |
    |    |           |              |                                       |   }                               |
    |    |           |              |                                       | ]                                 |
    |    |           |              |                                       | stepLimits: []                    |
    -----+-----------+--------------+---------------------------------------+------------------------------------
    |  1 | Start     |              | {                                     | outputVar: {                      |
    |    |           |              |   "execTime": "6(us)",                |   "colNames": [],                 |
    |    |           |              |   "rows": 0,                          |   "type": "DATASET",              |
    |    |           |              |   "totalTime": "407(us)",             |   "name": "__Start_1"             |
    |    |           |              |   "version": 0                        | }                                 |
    |    |           |              | }                                     |                                   |
    -----+-----------+--------------+---------------------------------------+------------------------------------