Dropping parts of the graph

Dropping parts of the graph is useful to free up memory or remove previously mutated algorithms results.

Syntax

Syntax descriptions of the different drop operations over a graph
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
Table 1. Parameters
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.

Table 2. Configuration
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.

Table 3. Results
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
Table 4. Parameters
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.

Table 5. Results
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.

The following Cypher statement will create the example graph in the Neo4j database:
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)
Project the small social network graph:
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)
  }
)
Compute the Degree Centrality in our social graph:
CALL gds.degree.mutate('socialGraph', {mutateProperty: 'score'})

Dropping node properties

Drop the score property from all projected nodes in the socialGraph:
CALL gds.graph.nodeProperties.drop('socialGraph', ['score'])
YIELD propertiesRemoved
Table 6. Results
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.

Attempt to drop the missing_score property from all projected nodes in the socialGraph:
CALL gds.graph.nodeProperties.drop('socialGraph', ['missing_score'], {failIfMissing: false})
YIELD propertiesRemoved, nodeProperties
Table 7. Results
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.

Drop all relationships of type 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.
Table 8. Results
graphName relationshipType deletedRelationships deletedProperties

"socialGraph"

"READ"

1

{}