3. 在目录中列出图表
可以使用gds.graph.list()过程列出有关目录中图的信息,该过程采用一个可选参数graphName:
- 如果给出图名称,则仅列出该图的信息。
- 如果没有给出图名称,将列出所有图的信息。
- 如果给出了图名称但未在目录中找到,则将返回一个空列表。
CALL gds.graph.list(
graphName: String?
) YIELD
graphName,
database,
nodeProjection,
relationshipProjection,
nodeQuery,
relationshipQuery,
nodeFilter,
relationshipFilter,
nodeCount,
relationshipCount,
schema,
degreeDistribution,
density,
creationTime,
modificationTime,
sizeInBytes,
memoryUsage;
表 8. 结果
Name | Type | Description |
---|---|---|
| String | Name of the graph. |
| String | Name of the database in which the graph has been created. |
| Map | Node projection used to create the graph. If a Cypher projection was used, this will be a derived node projection. |
| Map | Relationship projection used to create the graph. If a Cypher projection was used, this will be a derived relationship projection. |
| String | Node query used to create the graph. If a native projection was used, this will be |
| String | Relationship query used to create the graph. If a native projection was used, this will be |
| String | The node filter used when creating this subgraph from another in-memory graph. If the graph has been created from Neo4j, this will be |
| String | The relationship filter used when creating this subgraph from another in-memory graph. If the graph has been created from Neo4j, this will be |
| Integer | Number of nodes in the graph. |
| Integer | Number of relationships in the graph. |
| Map | Node labels, Relationship types and properties contained in the in-memory graph. |
| Map | Histogram of degrees in the graph. |
| Float | Density of the graph. |
| Datetime | Time when the graph was created. |
| Datetime | Time when the graph was last modified. |
| Integer | Number of bytes used in the Java heap to store the graph. |
| String | Human readable description of |
该信息包含有关图的基本统计信息,例如节点和关系计数。结果字段creationTime 指示图何时在内存中创建。结果字段modificationTime指示图何时被以mutate模式运行的算法更新。
database列是指在其上创建相应图的数据库的名称。在过程中引用命名图只允许在它创建的数据库上。
schema包含有关存储在图中的节点和关系的信息。对于每个节点标签,模式将标签映射到其属性键及其对应的属性类型。同样,模式将关系类型映射到它们的属性键和属性类型。属性类型是Integer
, Float
, List of Integer
或者 List of Float
。
对于较大的图, degreeDistribution字段的计算可能相当耗时。 它的计算是按图缓存的,因此同一图的后续列表速度将很快。 为避免计算度分布,可以在 YIELD子句中指定忽略它。 请注意,不指定 YIELD子句与请求返回所有字段的效果是相同的。
density是relationshipCount除以具有给定nodeCount的简单图的最大关系数的结果。
3.1. 例子
// 列出所有图的基本信息
CALL gds.graph.list()
YIELD graphName, nodeCount, relationshipCount, schema;
// 列出指定名称图的详细信息
CALL gds.graph.list('my-cypher-graph')
YIELD graphName, nodeQuery, relationshipQuery, nodeCount, relationshipCount, schema, creationTime, modificationTime, memoryUsage;
// 列出指定名称的图的度分布信息
CALL gds.graph.list('my-cypher-graph')
YIELD graphName, degreeDistribution;
4. 检查目录中是否存在图
我们可以通过查找其名称来检查图是否存储在目录中。
CALL gds.graph.exists('my-store-graph') YIELD exists;
5. 从命名图中删除节点属性
我们可以从目录中的命名图中删除节点属性。 这对于释放主内存或删除意外创建的节点属性很有用。
CALL gds.graph.removeNodeProperties('my-graph', ['pageRank', 'communityId'])
上面的示例要求所有给定的属性都存在于至少一个节点投影上,并且这些属性将从所有此类投影中删除。
该过程可以配置为仅删除某些特定节点投影的属性。在下面的例子中,我们在子图上运行了一个算法,随后删除了新创建的属性。
CALL gds.graph.create('my-graph', ['A', 'B'], '*')
CALL gds.wcc.mutate('my-graph', {nodeLabels: ['A'], mutateProperty: 'componentId'})
CALL gds.graph.removeNodeProperties('my-graph', ['componentId'], ['A'])
当指定了非 * 的投影列表时,如上例所示,将应用不同的验证和执行; 然后要求所有投影都具有所有给定的属性,并且将从所有投影中删除它们。
如果任何给定的投影是“*”,则该过程的行为与第一个示例中的一样。
6. 从命名图中删除关系类型
我们可以从目录中的命名图中删除给定类型的所有关系。这对于释放主内存或删除意外创建的关系类型很有用。
CALL gds.graph.deleteRelationships('my-graph', 'T')
YIELD graphName, relationshipType, deletedRelationships, deletedProperties
7. 从目录中删除图表
使用完命名图后,我们可以将其从目录中删除以释放内存。
CALL gds.graph.drop('my-store-graph') YIELD graphName;
如果我们希望该过程在不存在的图上静默失败,我们可以将布尔标志作为第二个参数设置为 false。 对于不存在的图,这将产生一个空结果。
CALL gds.graph.drop('my-fictive-graph', false) YIELD graphName;
如果我们想删除在另一个数据库上创建的图,我们可以将数据库名称设置为第三个参数。 对于不存在的图,这也将产生一个空结果。
CALL gds.graph.drop('my-fictive-graph', false, 'my-other-db') YIELD graphName;
如果我们是 GDS 管理员并且想要删除属于另一个用户的图,我们可以将用户名设置为过程的第四个参数。 如果有多个用户具有相同名称的图,这将非常有用。
CALL gds.graph.drop('my-fictive-graph', false, '', 'another-user') YIELD graphName;
有关这方面的更多详细信息,请参阅管理页面。