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 dst(edge) AS dstid, properties($$).name AS Name | \
        GO FROM $-.dstid OVER follow YIELD dst(edge);

+-------------+
| dst(EDGE)   |
+-------------+
| "player100" |
| "player102" |
| "player125" |
| "player100" |
+-------------+

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

Performance tips

In NebulaGraph, 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. 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: January 5, 2024