我正在开发依赖关系分析工具,并且我已经提出了以下Cypher查询,该查询表示拥有引用彼此的对象的SCHEMA,推断从架构到架构的依赖关系,如下所示:
MATCH (sourceSchema:SCHEMA)-[:OWNS]->(objectOwnedBySource)-[:REFERENCES*..]->(objectOwnedByTarget)<-[:OWNS]-(targetSchema:SCHEMA)
WHERE sourceSchema.name <> targetSchema.name
WITH sourceSchema, targetSchema
ORDER BY targetSchema.name
RETURN sourceSchema.name AS schema,
collect(distinct targetSchema.name) AS dependsOn
ORDER BY sourceSchema.name
上面的查询返回了一个非常棒的模式列表及其依赖项,如下所示:
schema dependsOn
FOO [BAR, BAZ, PUBLIC, SYS]
BAR [SYS]
BAZ [PUBLIC, SYS]
(etc)
在一些帮助下,我还设法创建了一个查询,它给出了一个类型(标签)列表及其在图表中每个模式的计数:
MATCH (sourceSchema:SCHEMA)-[:OWNS]->(objectOwnedBySource)
RETURN DISTINCT sourceSchema.name AS schema,
filter(x IN (labels(objectOwnedBySource)) WHERE NOT x="ENTITY")[0] AS type,
count(*) AS count
ORDER BY schema,type
上面的输出类似于:
schema type count
FOO TABLE 14
FOO SYNONYM 1
BAR FUNCTION 3
我的问题是:我如何以某种方式将此组合并获取导致架构依赖于架构的标签数量?我的意图是:
Schema DependsOnSchema ThroughLabelOnReferencedObject Count
FOO BAR TABLE 101
FOO BAR VIEW 10
FOO BAZ TABLE 6
(etc)
传入和传出引用的单独计数器的奖励积分:-)。非常感谢您的任何提示!
答案 0 :(得分:1)
我想出了:
MATCH (sourceSchema:SCHEMA)-[:OWNS]->(objectOwnedBySource)-[:REFERENCES*..]->(objectOwnedByTarget)<-[:OWNS]-(targetSchema)
WHERE sourceSchema <> targetSchema
RETURN DISTINCT sourceSchema.name AS source,
filter(x IN (labels(objectOwnedBySource)) WHERE NOT x="ENTITY")[0] AS sourceType,
targetSchema.name AS target,
filter(x IN (labels(objectOwnedByTarget)) WHERE NOT x="ENTITY")[0] AS targetType,
count(*) AS references
ORDER BY source,sourceType,target,targetType
这给了我:
source sourceType target targetType references
FOO TABLE BAR SEQUENCE 3
BAR FUNCTION BAZ PACKAGE 10
(etc)