Dropping parts of the graph
Dropping parts of the graph is useful to free up memory or remove previously mutated algorithms results.
Syntax
CALL gds.graph.nodeProperties.drop(
graphName: String,
nodeProperties: String or List of Strings,
configuration: Map
)
YIELD
propertiesRemoved: Integer,
graphName: String,
nodeProperties: String or List of String
Name | Type | Optional | Description |
---|---|---|---|
graphName |
String |
no |
The name under which the graph is stored in the catalog. |
nodeProperties |
String or List of Strings |
no |
The node properties in the graph to drop. |
configuration |
Map |
yes |
Additional parameters to configure. |
Name | Type | Default | Description |
---|---|---|---|
concurrency |
Integer |
4 |
The number of concurrent threads. Note, this procedure is always running single-threaded. |
failIfMissing |
Boolean |
true |
If false, the procedure will ignore properties that do not exist in the graph. |
Name | Type | Description |
---|---|---|
propertiesRemoved |
Integer |
Number of properties dropped. |
graphName |
String |
The name of a graph stored in the catalog. |
nodeProperties |
String or List of String |
The dropped node properties. |
CALL gds.graph.relationships.drop(
graphName: String,
relationshipType: String
)
YIELD
graphName: String,
relationshipType: String,
deletedRelationships: Integer,
deletedProperties: Map
Name | Type | Optional | Description |
---|---|---|---|
graphName |
String |
no |
The name under which the graph is stored in the catalog. |
relationshipType |
String |
no |
The relationship type in the graph to drop. |
Name | Type | Description |
---|---|---|
graphName |
String |
The name of a graph stored in the catalog. |
relationshipType |
String |
The type of the dropped relationships. |
deletedRelationships |
Integer |
Number of dropped relationships from the in-memory graph. |
deletedProperties |
Integer |
Map where the key is the name of the relationship property, and the value is the number of dropped properties under that name. |
Examples
All the examples below should be run in an empty database. The examples use Cypher projections as the norm. Native projections will be deprecated in a future release. |
In order to demonstrate the GDS capabilities over node properties, we are going to create a small social network graph in Neo4j and project it into our graph catalog.
CREATE
(florentin:Person { name: 'Florentin', age: 16 }),
(adam:Person { name: 'Adam', age: 18 }),
(veselin:Person { name: 'Veselin', age: 20 }),
(hobbit:Book { name: 'The Hobbit', numberOfPages: 310 }),
(florentin)-[:KNOWS { since: 2010 }]->(adam),
(florentin)-[:KNOWS { since: 2018 }]->(veselin),
(adam)-[:READ]->(hobbit)
MATCH (n:Person)-[r:KNOWS|READ]->(m:Person|Book)
RETURN gds.graph.project('socialGraph', n, m,
{
sourceNodeLabels: labels(n),
targetNodeLabels: labels(m),
sourceNodeProperties: n { .age },
targetNodeProperties: CASE WHEN m:Person THEN m { .age } ELSE {} END,
relationshipType: type(r)
}
)
CALL gds.degree.mutate('socialGraph', {mutateProperty: 'score'})
Dropping node properties
score
property from all projected nodes in the socialGraph
:CALL gds.graph.nodeProperties.drop('socialGraph', ['score'])
YIELD propertiesRemoved
propertiesRemoved |
---|
4 |
The above example requires all given properties to be present on at least one projected node label. |
Ignore missing properties
By default, the procedure will fail if any of the given properties do not exist in the graph.
If you want to ignore missing properties, you can set the failIfMissing
configuration option to false
.
missing_score
property from all projected nodes in the socialGraph
:CALL gds.graph.nodeProperties.drop('socialGraph', ['missing_score'], {failIfMissing: false})
YIELD propertiesRemoved, nodeProperties
propertiesRemoved | nodeProperties |
---|---|
0 |
[] |
Drop relationships of a given type
We can drop all relationships of a given type from a named graph in the catalog. This is useful to free up main memory or to drop accidentally added relationship types.
Deleting relationships of a given type is only possible if it is not the last relationship type present in the graph. If we still want to drop these relationships we need to drop the graph instead. |
SIMILAR
from a named graph:CALL gds.graph.relationships.drop(
'socialGraph', (1)
'READ' (2)
)
YIELD
graphName, relationshipType, deletedRelationships, deletedProperties
1 | The name of the projected graph. |
2 | The relationship type we want to delete from the projected graph. |
graphName | relationshipType | deletedRelationships | deletedProperties |
---|---|---|---|
"socialGraph" |
"READ" |
1 |
{} |