Command insert().overwrite()
will either insert one or multiple nodes/edges into the current GraphSet, or overwrite property values (except ID) of one or multiple existing nodes/edges based on ID.
insert().overwrite()
may trigger:
- an insert operation if:
- ID is not provided
- the provided ID does not exist in the graph
- an overwrite operation if:
- the provided ID exists in the graph, and matches with schema
- a failure if:
- the provided ID exists in the graph, but does not match with schema
- FROM or TO is not provided when inserting edges
- provided FROM or TO does not exist in the graph
When insert operation is triggered: same with insert()
.
When overwrite operation is triggered:
- the missing custom properties will be
null
- the custom properties provided in the wrong data type will be using default value
It is not suggested to execute overwriting operation after streaming return of an algorithm, see details on
stream()
in document Ultipa Graph Analytics & Algorithms - Using Algorithms - Execution Method.
Syntax:
- Statement alias: supported (NODE or EDGE)
// To overwrite nodes of a certain schema in the current graphset
insert().overwrite().into(@<schema>)
.nodes([ // Square brackets can be omitted if overwrites only one node
{<property1>:<value1>, <property2>:<value2>, ...},
{<property1>:<value1>, <property2>:<value2>, ...},
...
])
// To overwrite edges of a certain schema in the current graphset, must carry _from and _to, or must carry _from_uuid and _to_uuid
insert().overwrite().into(@<schema>)
.edges([ // Square brackets can be omitted if overwrites only one edge
{<property1>:<value1>, <property2>:<value2>, ...},
{<property1>:<value1>, <property2>:<value2>, ...},
...
])
Sample graph: (to be used for the following examples)
Run below UQLs one by one in an empty graphset to create graph data:create().node_schema("account").edge_schema("follow")
create().node_property(@account, "name").edge_property(@follow, "time", datetime)
insert().into(@account).nodes([{_id:"U001", _uuid:1, name:"Jason"}, {_id:"U002", _uuid:2, name:"Tim"}, {_id:"U003", _uuid:3, name:"Grace"}, {_id:"U004", _uuid:4, name:"Ted"}])
insert().into(@follow).edges([{_uuid:1, _from_uuid:4, _to_uuid:1, time:"2021-09-10"}, {_uuid:2, _from_uuid:3, _to_uuid:2, time:"2020-03-12"}, {_uuid:3, _from_uuid:4, _to_uuid:2, time:"2023-07-30"}])
Example: Insert 3 nodes into @account, one does not carry any information, namely, the _id
and _uuid
will be generated and all custom properties are null
; the other two provide IDs matching with schema, but one carries no property which will be overwritten as null
, while the other carries a property with wrong type that will be set to default value (empty string)
insert().overwrite().into(@account).nodes([{}, {_id: "U001"}, {_id: "U002", name: [1,2,3]}]) as nodes
return nodes{*}
| _id | _uuid | name |
|------------------------|-------|--------|
| ULTIPA8000000000000001 | 5 | null |
| U001 | 1 | null |
| U002 | 2 | |
Example: Prompt error when overwriting node due to that ID does not match with schema
insert().overwrite().into(@card).nodes({_id: "U003", name: "Jack"}) as nodes
return nodes{*}
The schema: card does not match with U003!
Example: Prompt error when overwriting edge due to that FROM/TO not provided
insert().overwrite().into(@follow).edges({_uuid: 1, time: "2021-08-31"}) as edges
return edges{*}
_from_uuid must > 0!