Skip to content

Pipe operators

Multiple queries can be combined using pipe operators in nGQL.

OpenCypher compatibility

Pipe operators apply to native nGQL only.

Syntax

One major difference between nGQL and SQL is how sub-queries are composed.

  • In SQL, sub-queries are nested in the query statements.
  • In nGQL, the shell style PIPE (|) is introduced into the sub-queries.

Examples

nebula> GO FROM "player100" OVER follow \
        YIELD follow._dst AS dstid, $$.player.name AS Name | \
        GO FROM $-.dstid OVER follow;

+-------------+
| follow._dst |
+-------------+
| "player101" |
+-------------+

If there is no YIELD clause to define the output, the destination vertex ID is returned by default. If a YIELD clause is applied, the output is defined by the YIELD clause.

Users must define aliases in the YIELD clause for the reference operator $- to use, just like $-.dstid in the preceding example.

Performance tips

In Nebula Graph 2.5.0, pipes will affect the performance. Take A | B as an example, the effects are as follows:

  1. Pipe operators operate synchronously. That is, the data can enter the pipe clause as a whole after the execution of clause A before the pipe operator is completed.

  2. Pipe operators need to be serialized and deserialized, which is executed in a single thread.

  3. If A sends a large amount of data to |, the entire query request may be very slow. You can try to split this statement.

    1. Send A from the application,

    2. Split the return results on the application,

    3. Send to multiple graphd processes concurrently,

    4. Every graphd process executes part of B.

    This is usually much faster than executing a complete A | B with a single graphd process.


Last update: August 27, 2021
Back to top