Reference to properties¶
nGQL provides property references to allow you to refer to the properties of the source vertex, the destination vertex, and the edge in the GO
statement, and to refer to the output results of the statement in composite queries. This topic describes how to use these property references in nGQL.
Note
This function applies to native nGQL only.
Property references for vertexes¶
Parameter | Description |
---|---|
$^ |
Used to get the property of the source vertex. |
$$ |
Used to get the property of the destination vertex. |
Property reference syntax¶
$^.<tag_name>.<prop_name> # Source vertex property reference
$$.<tag_name>.<prop_name> # Destination vertex property reference
tag_name
: The tag name of the vertex.prop_name
: The property name within the tag.
Property references for edges¶
Parameter | Description |
---|---|
_src |
The source vertex ID of the edge |
_dst |
The destination vertex ID of the edge |
_type |
The internal encoding of edge types that uses sign to indicate direction. Positive numbers represent forward edges, while negative numbers represent backward edges. |
_rank |
The rank value for the edge |
Property reference syntax¶
nGQL allows you to reference edge properties, including user-defined edge properties and four built-in edge properties.
<edge_type>.<prop_name> # User-defined edge property reference
<edge_type>._src|_dst|_type|_rank # Built-in edge property reference
edge_type
: The edge type.prop_name
: The property name within the edge type.
Property references for composite queries¶
Parameter | Description |
---|---|
$- |
Used to get the output results of the statement before the pipe in the composite query. For more information, see Pipe. |
Examples¶
Use property references for vertexes¶
The following query returns the name
property of the player
tag on the source vertex and the age
property of the player
tag on the destination vertex.
nebula> GO FROM "player100" OVER follow YIELD $^.player.name AS startName, $$.player.age AS endAge;
+--------------+--------+
| startName | endAge |
+--------------+--------+
| "Tim Duncan" | 36 |
| "Tim Duncan" | 41 |
+--------------+--------+
Legacy version compatibility
Starting from NebulaGraph 2.6.0, Schema-related functions are supported. The preceding example can be rewritten as follows in NebulaGraph 3.8.0 to produce the same results:
GO FROM "player100" OVER follow YIELD properties($^).name AS startName, properties($$).age AS endAge;
NebulaGraph 3.8.0 is compatible with both new and old syntax.
Use property references for edges¶
The following query returns the degree
property of the edge type follow
.
nebula> GO FROM "player100" OVER follow YIELD follow.degree;
+---------------+
| follow.degree |
+---------------+
| 95 |
+---------------+
The following query returns the source vertex, the destination vertex, the edge type, and the edge rank value of the edge type follow
.
nebula> GO FROM "player100" OVER follow YIELD follow._src, follow._dst, follow._type, follow._rank;
+-------------+-------------+--------------+--------------+
| follow._src | follow._dst | follow._type | follow._rank |
+-------------+-------------+--------------+--------------+
| "player100" | "player101" | 17 | 0 |
| "player100" | "player125" | 17 | 0 |
+-------------+-------------+--------------+--------------+
Legacy version compatibility
Starting from NebulaGraph 2.6.0, Schema-related functions are supported. The preceding example can be rewritten as follows in NebulaGraph 3.8.0 to produce the same results:
GO FROM "player100" OVER follow YIELD properties(edge).degree;
GO FROM "player100" OVER follow YIELD src(edge), dst(edge), type(edge), rank(edge);
NebulaGraph 3.8.0 is compatible with both new and old syntax.
Use property references for composite queries¶
The following composite query performs the following actions:
- Uses the property reference
$-.id
to get the results of the statementGO FROM "player100" OVER follow YIELD dst(edge) AS id
, which returns the destination vertex ID of thefollow
edge type. - Uses the
properties($^)
function to get the name property of the player tag on the source vertex of theserve
edge type. - Uses the
properties($$)
function to get the name property of the team tag on the destination vertex of theserve
edge type.
nebula> GO FROM "player100" OVER follow \
YIELD dst(edge) AS id | \
GO FROM $-.id OVER serve \
YIELD properties($^).name AS Player, properties($$).name AS Team;
+-----------------+-----------+
| Player | Team |
+-----------------+-----------+
| "Tony Parker" | "Spurs" |
| "Tony Parker" | "Hornets" |
| "Manu Ginobili" | "Spurs" |
+-----------------+-----------+