Command, Parameter
Update operations can update node and edge data in a single or batch manner in the current GraphSet. UQL finds the nodes and edges to be modified according to the filtering rules before modifying its properties except the unique identifiers _id
and _uuid
.
Syntax:
- Command:
update()
- Parameter: (see the table below)
- Statement Alias: Custom alias supported, structure type is NODE or EDGE
Parameter | Type | Specification | Description | Structure Type of Custom Alias |
---|---|---|---|---|
nodes() or edges() |
Filter | Mandatory | Filtering rules of nodes or edges | Not supported |
set() |
Obj | Mandatory | An object that comprises KVs of properties to be updated | Not supported |
limit() |
Int | > 0 | The number of nodes or edges to be updated | Not supported |
Update operation will induce redundant data into the GraphSet and reduce the query efficiency. It is strongly suggested to be cleared on a regular basis, see command
compact()
in the previous chapter.
It is not suggested to execute Update operation after streaming return of an algorithm, see details on
stream()
in document Ultipa Graph Analytics & Algorithms - Using Algorithms - Execution Method.
Update Node Data
// To update nodes in the current graphset
update().nodes(<filter>)
.set({<property1>: <value1>, <property2>: <value2> ...})
.limit(<N>)
Example: Update the balance of bank card C001 to 300
update().nodes({_id == "C001"})
.set({balance: 300})
Example: Update the score of all bank cards @card to the value of level*balance
update().nodes({@card})
.set({score: level * balance})
Example: Upgrade 5,000 bank cards @card under level 2 but has balance that exceeds 200,000 to the next upper level
update().nodes({@card && level < 2 && balance > 200000})
.set({level: level + 1})
.limit(5000)
Note: When the amount of data is too large for the memory to process, parameter limit()
can be used to set the maximum quantity to handle thus to process in batches.
Update Edge Data
When updating the start/end node (_from
, _to
, _from_uuid
and _to_uuid
) of edge, the new start/end node must exist in the GraphSet, otherwise the operation will fail. Ultipa system will automatically update _from_uuid
when _from
is updated and vise versa, and same for _to
and _to_uuid
. When modifying _from
and _from_uuid
at the same time but the two do not match the correspondence in the GraphSet, Ultipa system subjects to _from_uuid
, and same for _to
and _to_uuid
.
// To update edges in the current graphset
update().edges(<filter>)
.set({<property1>: <value1>, <property2>: <value2> ...})
.limit(<N>)
Example: Update the amount of @transaction.no TRX001 to 100
update().edges({@transaction.no == "TRX001"})
.set({amount: 100})