如何获取图谱对象的高级清单 (第二部分)
继关于如何获取图谱对象的高级清单的知识库文章之后,本文将介绍如何获取图谱对象的更详细的高级清单。
第一篇文章展示了通过运行
match (n) return 'Number of Nodes: ' + count(n) as output UNION
match ()-[]->() return 'Number of Relationships: ' + count(*) as output UNION
CALL db.labels() YIELD label RETURN 'Number of Labels: ' + count(*) AS output UNION
CALL db.relationshipTypes() YIELD relationshipType RETURN 'Number of Relationships Types: ' + count(*) AS output UNION
CALL db.propertyKeys() YIELD propertyKey RETURN 'Number of Property Keys: ' + count(*) AS output UNION
CALL db.constraints() YIELD description RETURN 'Number of Constraints:' + count(*) AS output UNION
CALL db.indexes() YIELD description RETURN 'Number of Indexes: ' + count(*) AS output UNION
CALL dbms.procedures() YIELD name RETURN 'Number of Procedures: ' + count(*) AS output
您将获得节点、关系、标签、关系类型、属性键、约束、索引和过程的所有计数。
如果您正在运行 3.2.x 或更早版本,并且想深入查看这些对象的更详细信息,您可以在 $NEO4J_HOME
目录下运行以下命令
$ java -cp "lib/*" org.neo4j.kernel.impl.util.dbstructure.DbStructureTool MyDatabaseStats.java /data/databases/graph.db > ./MyDatabaseStats.java
与另一篇文章中提到的查询不同,您不能在运行中的数据库上执行此命令。但是,您可以将其指向备份文件,并获取所有信息。 |
这将生成一个名为 MyDatabaseStats.java
的文件,其内容将提供给您
1. 图谱中的标签
visitor.visitLabel( 0, "Label" );
2. 图谱中的属性键
visitor.visitPropertyKey( 0, "property" );
3. 图谱中的关系类型
visitor.visitRelationshipType( 0, "REL" );
4. 图谱中的索引
visitor.visitIndex( IndexDescriptorFactory.forLabel( 0, 0 ), ":Label(property)", 1.0d, 1053000L );
5. 图谱中的约束
visitor.visitUniqueConstraint( ConstraintDescriptorFactory.uniqueForLabel( 0, 1 ), "CONSTRAINT ON ( label:Label ) ASSERT label.property IS UNIQUE" );
6. 节点计数
6.1. 图谱中所有节点的计数
visitor.visitAllNodesCount( 49625435L );
6.2. 图谱中所有 :Label
节点的计数
visitor.visitNodeCount( 0, "Label", 1053000L );
7. 关系计数 您可以按如下方式找到关系总数以及所有入站/出站关系组合的数量
7.1. 图谱中所有关系的计数
visitor.visitRelCount( -1, -1, -1, "MATCH ()-[]->() RETURN count(*)", 910243L );
7.2. 从 :Label
出站的所有关系的计数
visitor.visitRelCount( 0, -1, -1, "MATCH (:Label)-[]->() RETURN count(*)", 10600L );
7.3. 到 :Label
入站的所有关系的计数
visitor.visitRelCount( -1, -1, 0, "MATCH ()-[]->(:Label) RETURN count(*)", 0L );
7.4. 所有 :REL
关系的计数
visitor.visitRelCount( -1, 0, -1, "MATCH ()-[:REL]->() RETURN count(*)", 10600L );
7.5. 从 :Label
出站的所有 :REL
关系的计数
visitor.visitRelCount( 0, 0, -1, "MATCH (:Label)-[:REL]->() RETURN count(*)", 10600L );
7.6. 到 :Label
入站的所有 :REL
关系的计数
visitor.visitRelCount( -1, 0, 0, "MATCH ()-[:REL]->(:Label) RETURN count(*)", 0L );
在一个由以下元素组成的图谱中
-
3 个标签:User, Device, Accessory
-
3 个属性键:uuid, name, state
-
3 个关系:OWNS, BELONGS, HAS
-
3 个索引:User(name), Device(uuid), Accessory(uuid)
-
1 个约束:user.uuid 是唯一的
MyDatabaseStats.java
将有以下输出
package MyDatabaseStats;
import org.neo4j.helpers.collection.Visitable;
import org.neo4j.kernel.impl.util.dbstructure.DbStructureVisitor;
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory;
import org.neo4j.kernel.api.schema.constaints.UniquenessConstraintDescriptor;
import org.neo4j.kernel.api.schema.constaints.RelExistenceConstraintDescriptor;
import org.neo4j.kernel.api.schema.constaints.NodeExistenceConstraintDescriptor;
import org.neo4j.kernel.api.schema.constaints.NodeKeyConstraintDescriptor;
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory;
//
// GENERATED FILE. DO NOT EDIT.
//
// This has been generated by:
//
// org.neo4j.kernel.impl.util.dbstructure.DbStructureTool MyDatabaseStats.java [<output source root>] <db-dir>
//
// (using org.neo4j.kernel.impl.util.dbstructure.InvocationTracer)
//
public enum java
implements Visitable<DbStructureVisitor>
{
INSTANCE;
public void accept( DbStructureVisitor visitor )
{
visitor.visitLabel( 0, "User" );
visitor.visitLabel( 1, "Device" );
visitor.visitLabel( 2, "Accessory" );
visitor.visitPropertyKey( 0, "uuid" );
visitor.visitPropertyKey( 1, "name" );
visitor.visitPropertyKey( 2, "state" );
visitor.visitRelationshipType( 0, "OWNS" );
visitor.visitRelationshipType( 1, "BELONGS" );
visitor.visitRelationshipType( 2, "HAS" );
visitor.visitIndex( IndexDescriptorFactory.forLabel( 0, 0 ), ":User(name)", 1.0d, 1053000L );
visitor.visitIndex( IndexDescriptorFactory.forLabel( 1, 0 ), ":Device(uuid)", 1.0d, 2029998L );
visitor.visitIndex( IndexDescriptorFactory.forLabel( 2, 0 ), ":Accessory(uuid)", 0.8502996093642793d, 6011998L );
visitor.visitUniqueConstraint( ConstraintDescriptorFactory.uniqueForLabel( 15, 1 ), "CONSTRAINT ON ( user:User ) ASSERT user.uuid IS UNIQUE" );
visitor.visitAllNodesCount( 49625435L );
visitor.visitNodeCount( 0, "User", 1053000L );
visitor.visitNodeCount( 1, "Device", 2106000L );
visitor.visitNodeCount( 2, "Accessory", 6318000L );
visitor.visitRelCount( -1, -1, -1, "MATCH ()-[]->() RETURN count(*)", 910243L );
visitor.visitRelCount( 0, -1, -1, "MATCH (:User)-[]->() RETURN count(*)", 10600L );
visitor.visitRelCount( -1, -1, 0, "MATCH ()-[]->(:User) RETURN count(*)", 0L );
visitor.visitRelCount( 1, -1, -1, "MATCH (:Device)-[]->() RETURN count(*)", 31800L );
visitor.visitRelCount( -1, -1, 1, "MATCH ()-[]->(:Device) RETURN count(*)", 10600L );
visitor.visitRelCount( 2, -1, -1, "MATCH (:Accessory)-[]->() RETURN count(*)", 42400L );
visitor.visitRelCount( -1, -1, 2, "MATCH ()-[]->(:Accessory) RETURN count(*)", 31800L );
visitor.visitRelCount( -1, 0, -1, "MATCH ()-[:OWNS]->() RETURN count(*)", 10600L );
visitor.visitRelCount( 0, 0, -1, "MATCH (:User)-[:OWNS]->() RETURN count(*)", 10600L );
visitor.visitRelCount( -1, 0, 0, "MATCH ()-[:OWNS]->(:User) RETURN count(*)", 0L );
visitor.visitRelCount( 1, 0, -1, "MATCH (:Device)-[:OWNS]->() RETURN count(*)", 0L );
visitor.visitRelCount( -1, 0, 1, "MATCH ()-[:OWNS]->(:Device) RETURN count(*)", 10600L );
visitor.visitRelCount( 2, 0, -1, "MATCH (:Accessory)-[:OWNS]->() RETURN count(*)", 0L );
visitor.visitRelCount( -1, 0, 2, "MATCH ()-[:OWNS]->(:Accessory) RETURN count(*)", 0L );
visitor.visitRelCount( -1, 1, -1, "MATCH ()-[:BELONGS]->() RETURN count(*)", 31800L );
visitor.visitRelCount( 0, 1, -1, "MATCH (:User)-[:BELONGS]->() RETURN count(*)", 0L );
visitor.visitRelCount( -1, 1, 0, "MATCH ()-[:BELONGS]->(:User) RETURN count(*)", 0L );
visitor.visitRelCount( 1, 1, -1, "MATCH (:Device)-[:BELONGS]->() RETURN count(*)", 31800L );
visitor.visitRelCount( -1, 1, 1, "MATCH ()-[:BELONGS]->(:Device) RETURN count(*)", 0L );
visitor.visitRelCount( 2, 1, -1, "MATCH (:Accessory)-[:BELONGS]->() RETURN count(*)", 0L );
visitor.visitRelCount( -1, 1, 2, "MATCH ()-[:BELONGS]->(:Accessory) RETURN count(*)", 31800L );
visitor.visitRelCount( -1, 2, -1, "MATCH ()-[:HAS]->() RETURN count(*)", 10600L );
visitor.visitRelCount( 0, 2, -1, "MATCH (:User)-[:HAS]->() RETURN count(*)", 0L );
visitor.visitRelCount( -1, 2, 0, "MATCH ()-[:HAS]->(:User) RETURN count(*)", 0L );
visitor.visitRelCount( 1, 2, -1, "MATCH (:Device)-[:HAS]->() RETURN count(*)", 0L );
visitor.visitRelCount( -1, 2, 1, "MATCH ()-[:HAS]->(:Device) RETURN count(*)", 0L );
visitor.visitRelCount( 2, 2, -1, "MATCH (:Accessory)-[:HAS]->() RETURN count(*)", 10600L );
visitor.visitRelCount( -1, 2, 2, "MATCH ()-[:HAS]->(:Accessory) RETURN count(*)", 0L );
}
}
/* END OF GENERATED CONTENT */
本页有帮助吗?