Skip to content

Schema-related functions

This topic describes the schema-related functions supported by NebulaGraph. There are two types of schema-related functions, one for native nGQL statements and the other for openCypher-compatible statements.

For nGQL statements

The following functions are available in YIELD and WHERE clauses of nGQL statements.

Note

Since vertex, edge, vertices, edges, and path are keywords, you need to use AS <alias> to set the alias, such as GO FROM "player100" OVER follow YIELD edge AS e;.

id(vertex)

id(vertex) returns the ID of a vertex.

Syntax: id(vertex)

  • Result type: Same as the vertex ID.

Example:

nebula> LOOKUP ON player WHERE player.age  > 45 YIELD id(vertex);
+-------------+
| id(VERTEX)  |
+-------------+
| "player144" |
| "player140" |
+-------------+

properties(vertex)

properties(vertex) returns the properties of a vertex.

Syntax: properties(vertex)

  • Result type: Map

Example:

nebula> LOOKUP ON player WHERE player.age  > 45 \
        YIELD properties(vertex);
+-------------------------------------+
| properties(VERTEX)                  |
+-------------------------------------+
| {age: 47, name: "Shaquille O'Neal"} |
| {age: 46, name: "Grant Hill"}       |
+-------------------------------------+

You can also use the property reference symbols ($^ and $$) instead of the vertex field in the properties() function to get all properties of a vertex.

  • $^ represents the data of the starting vertex at the beginning of exploration. For example, in GO FROM "player100" OVER follow reversely YIELD properties($^), $^ refers to the vertex player100.
  • $$ represents the data of the end vertex at the end of exploration.

properties($^) and properties($$) are generally used in GO statements. For more information, see Property reference.

Caution

You can use properties().<property_name> to get a specific property of a vertex. However, it is not recommended to use this method to obtain specific properties because the properties() function returns all properties, which can decrease query performance.

properties(edge)

properties(edge) returns the properties of an edge.

Syntax: properties(edge)

  • Result type: Map

Example:

nebula> GO FROM "player100" OVER follow \
        YIELD properties(edge);
+------------------+
| properties(EDGE) |
+------------------+
| {degree: 95}     |
| {degree: 95}     |
+------------------+

Caution

You can use properties(edge).<property_name> to get a specific property of an edge. However, it is not recommended to use this method to obtain specific properties because the properties(edge) function returns all properties, which can decrease query performance.

type(edge)

type(edge) returns the edge type of an edge.

Syntax: type(edge)

  • Result type: String

Example:

nebula> GO FROM "player100" OVER follow \
        YIELD src(edge), dst(edge), type(edge), rank(edge);
+-------------+-------------+------------+------------+
| src(EDGE)   | dst(EDGE)   | type(EDGE) | rank(EDGE) |
+-------------+-------------+------------+------------+
| "player100" | "player101" | "follow"   | 0          |
| "player100" | "player125" | "follow"   | 0          |
+-------------+-------------+------------+------------+

src(edge)

src(edge) returns the source vertex ID of an edge.

Syntax: src(edge)

  • Result type: Same as the vertex ID.

Example:

nebula> GO FROM "player100" OVER follow \
        YIELD src(edge), dst(edge);
+-------------+-------------+
| src(EDGE)   | dst(EDGE)   |
+-------------+-------------+
| "player100" | "player101" |
| "player100" | "player125" |
+-------------+-------------+

Note

The semantics of the query for the starting vertex with src(edge) and properties($^) are different. src(edge) indicates the starting vertex ID of the edge in the graph database, while properties($^) indicates the data of the starting vertex where you start to expand the graph, such as the data of the starting vertex player100 in the above GO statement.

dst(edge)

dst(edge) returns the destination vertex ID of an edge.

Syntax: dst(edge)

  • Result type: Same as the vertex ID.

Example:

nebula> GO FROM "player100" OVER follow \
        YIELD src(edge), dst(edge);
+-------------+-------------+
| src(EDGE)   | dst(EDGE)   |
+-------------+-------------+
| "player100" | "player101" |
| "player100" | "player125" |
+-------------+-------------+

Note

dst(edge) indicates the destination vertex ID of the edge in the graph database.

rank(edge)

rank(edge) returns the rank value of an edge.

Syntax: rank(edge)

  • Result type: Int

Example:

nebula> GO FROM "player100" OVER follow \
        YIELD src(edge), dst(edge), rank(edge);
+-------------+-------------+------------+
| src(EDGE)   | dst(EDGE)   | rank(EDGE) |
+-------------+-------------+------------+
| "player100" | "player101" | 0          |
| "player100" | "player125" | 0          |
+-------------+-------------+------------+

vertex

vertex returns the information of vertices, including VIDs, tags, properties, and values. You need to use AS <alias> to set the alias.

Syntax: vertex

Example:

nebula> LOOKUP ON player WHERE player.age > 45 YIELD vertex AS v;
+----------------------------------------------------------+
| v                                                        |
+----------------------------------------------------------+
| ("player144" :player{age: 47, name: "Shaquille O'Neal"}) |
| ("player140" :player{age: 46, name: "Grant Hill"})       |
+----------------------------------------------------------+

edge

edge returns the information of edges, including edge types, source vertices, destination vertices, ranks, properties, and values. You need to use AS <alias> to set the alias.

Syntax: edge

Example:

nebula> GO FROM "player100" OVER follow YIELD edge AS e;
+----------------------------------------------------+
| e                                                  |
+----------------------------------------------------+
| [:follow "player100"->"player101" @0 {degree: 95}] |
| [:follow "player100"->"player125" @0 {degree: 95}] |
+----------------------------------------------------+

vertices

vertices returns the information of vertices in a subgraph. For more information, see GET SUBGRAPH.

edges

edges returns the information of edges in a subgraph. For more information, see GET SUBGRAPH.

path

path returns the information of a path. For more information, see FIND PATH.

For statements compatible with openCypher

The following functions are available in RETURN and WHERE clauses of openCypher-compatible statements.

id()

id() returns the ID of a vertex.

Syntax: id(<vertex>)

  • Result type: Same as the vertex ID.

Example:

nebula> MATCH (v:player) RETURN id(v); 
+-------------+
| id(v)       |
+-------------+
| "player129" |
| "player115" |
| "player106" |
| "player102" |
...

tags() and labels()

tags() and labels() return the Tag of a vertex.

Syntax: tags(<vertex>), labels(<vertex>)

  • Result type: List

Example:

nebula> MATCH (v) WHERE id(v) == "player100" \
        RETURN tags(v);
+------------+
| tags(v)    |
+------------+
| ["player"] |
+------------+

properties()

properties() returns the properties of a vertex or an edge.

Syntax: properties(<vertex_or_edge>)

  • Result type: Map

Example:

nebula> MATCH (v:player)-[e:follow]-() RETURN properties(v),properties(e);
+---------------------------------------+---------------+
| properties(v)                         | properties(e) |
+---------------------------------------+---------------+
| {age: 31, name: "Stephen Curry"}      | {degree: 90}  |
| {age: 47, name: "Shaquille O'Neal"}   | {degree: 100} |
| {age: 34, name: "LeBron James"}       | {degree: 13}  |
...

type()

type() returns the edge type of an edge.

Syntax: type(<edge>)

  • Result type: String

Example:

nebula> MATCH (v:player{name:"Tim Duncan"})-[e]->() \
        RETURN type(e);
+----------+
| type(e)  |
+----------+
| "serve"  |
| "follow" |
| "follow" |
+----------+

src()

src() returns the source vertex ID of an edge.

Syntax: src(<edge>)

  • Result type: Same as the vertex ID.

Example:

nebula> MATCH ()-[e]->(v:player{name:"Tim Duncan"}) \
        RETURN src(e);
+-------------+
| src(e)      |
+-------------+
| "player125" |
| "player113" |
| "player102" |
...

dst()

dst() returns the destination vertex ID of an edge.

Syntax: dst(<edge>)

  • Result type: Same as the vertex ID.

Example:

nebula> MATCH (v:player{name:"Tim Duncan"})-[e]->() \
        RETURN dst(e);
+-------------+
| dst(e)      |
+-------------+
| "team204"   |
| "player101" |
| "player125" |
+-------------+

startNode()

startNode() visits a path and returns its information of source vertex ID, including VIDs, tags, properties, and values.

Syntax: startNode(<path>)

Example:

nebula> MATCH p = (a :player {name : "Tim Duncan"})-[r:serve]-(t) \
        RETURN startNode(p);
+----------------------------------------------------+
| startNode(p)                                       |
+----------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------+

endNode()

endNode() visits a path and returns its information of destination vertex ID, including VIDs, tags, properties, and values.

Syntax: endNode(<path>)

Example:

nebula> MATCH p = (a :player {name : "Tim Duncan"})-[r:serve]-(t) \
        RETURN endNode(p);
+----------------------------------+
| endNode(p)                       |
+----------------------------------+
| ("team204" :team{name: "Spurs"}) |
+----------------------------------+

rank()

rank() returns the rank value of an edge.

Syntax: rank(<edge>)

  • Result type: Int

Example:

nebula> MATCH (v:player{name:"Tim Duncan"})-[e]->() \
        RETURN rank(e);
+---------+
| rank(e) |
+---------+
| 0       |
| 0       |
| 0       |
+---------+

Last update: February 19, 2024