Graph Query Language (GQL) supports all GoogleSQL operators, including the following GQL-specific operators:
Graph operators list
Name | Summary |
---|---|
Graph logical operators |
Tests for the truth of a condition in a graph and produces either
TRUE or FALSE .
|
Graph predicates |
Tests for the truth of a condition for a graph element and produces
TRUE , FALSE , or NULL .
|
IS DESTINATION predicate
|
In a graph, checks to see if a node is or isn't the destination of an edge. |
IS SOURCE predicate
|
In a graph, checks to see if a node is or isn't the source of an edge. |
PROPERTY_EXISTS predicate
|
In a graph, checks to see if a property exists for an element. |
SAME predicate
|
In a graph, determines if all graph elements in a list bind to the same node or edge. |
Graph logical operators
GoogleSQL supports the following logical operators in element pattern label expressions:
Name | Syntax | Description |
---|---|---|
NOT |
!X |
Returns TRUE if X is not included, otherwise,
returns FALSE .
|
OR |
X | Y |
Returns TRUE if either X or Y is
included, otherwise, returns FALSE .
|
AND |
X & Y |
Returns TRUE if both X and Y are
included, otherwise, returns FALSE .
|
Graph predicates
GoogleSQL supports the following graph-specific predicates in
graph expressions. A predicate can produce TRUE
, FALSE
, or NULL
.
IS DESTINATION
predicate
node IS [ NOT ] DESTINATION [ OF ] edge
Description
In a graph, checks to see if a node is or isn't the destination of an edge.
Can produce TRUE
, FALSE
, or NULL
.
Arguments:
node
: The graph pattern variable for the node element.edge
: The graph pattern variable for the edge element.
Examples
GRAPH FinGraph
MATCH (a:Account)-[transfer:Transfers]-(b:Account)
WHERE a IS DESTINATION of transfer
RETURN a.id AS a_id, b.id AS b_id
/*-------------+
| a_id | b_id |
+-------------+
| 16 | 7 |
| 16 | 7 |
| 20 | 16 |
| 7 | 20 |
| 16 | 20 |
+-------------*/
GRAPH FinGraph
MATCH (a:Account)-[transfer:Transfers]-(b:Account)
WHERE b IS DESTINATION of transfer
RETURN a.id AS a_id, b.id AS b_id
/*-------------+
| a_id | b_id |
+-------------+
| 7 | 16 |
| 7 | 16 |
| 16 | 20 |
| 20 | 7 |
| 20 | 16 |
+-------------*/
IS SOURCE
predicate
node IS [ NOT ] SOURCE [ OF ] edge
Description
In a graph, checks to see if a node is or isn't the source of an edge.
Can produce TRUE
, FALSE
, or NULL
.
Arguments:
node
: The graph pattern variable for the node element.edge
: The graph pattern variable for the edge element.
Examples
GRAPH FinGraph
MATCH (a:Account)-[transfer:Transfers]-(b:Account)
WHERE a IS SOURCE of transfer
RETURN a.id AS a_id, b.id AS b_id
/*-------------+
| a_id | b_id |
+-------------+
| 20 | 7 |
| 7 | 16 |
| 7 | 16 |
| 20 | 16 |
| 16 | 20 |
+-------------*/
GRAPH FinGraph
MATCH (a:Account)-[transfer:Transfers]-(b:Account)
WHERE b IS SOURCE of transfer
RETURN a.id AS a_id, b.id AS b_id
/*-------------+
| a_id | b_id |
+-------------+
| 7 | 20 |
| 16 | 7 |
| 16 | 7 |
| 16 | 20 |
| 20 | 16 |
+-------------*/
PROPERTY_EXISTS
predicate
PROPERTY_EXISTS(element, element_property)
Description
In a graph, checks to see if a property exists for an element.
Can produce TRUE
, FALSE
, or NULL
.
Arguments:
element
: The graph pattern variable for a node or edge element.element_property
: The name of the property to look for inelement
. The property name must refer to a property in the graph. If the property does not exist in the graph, an error is produced. The property name is resolved in a case-insensitive manner.
Example
GRAPH FinGraph
MATCH (n:Person|Account WHERE PROPERTY_EXISTS(n, name))
RETURN n.name
/*------+
| name |
+------+
| Alex |
| Dana |
| Lee |
+------*/
SAME
predicate
SAME (element, element[, element])
Description
In a graph, determines if all graph elements in a list bind to the same node or
edge. Can produce TRUE
, FALSE
, or NULL
.
Arguments:
element
: The graph pattern variable for a node or edge element.
Example
The following query checks to see if a
and b
are not the same person.
GRAPH FinGraph
MATCH (src:Account)<-[transfer:Transfers]-(dest:Account)
WHERE NOT SAME(src, dest)
RETURN src.id AS source_id, dest.id AS destination_id
/*----------------------------+
| source_id | destination_id |
+----------------------------+
| 7 | 20 |
| 16 | 7 |
| 16 | 7 |
| 16 | 20 |
| 20 | 16 |
+----------------------------*/