当前位置:网站首页>Quickly obtain the attributes of the sub graph root node
Quickly obtain the attributes of the sub graph root node
2022-06-13 03:18:00 【Tnoy. Ma】
Quickly get the attributes of the sub graph root node
Here’s the table of contents:
Quickly get the attributes of the sub graph root node
Subgraph matching is a very complicated problem , There are mainly
Determine the subgraph matching of the pattern
andSubgraph matching of uncertain patterns
【 for example : Search by graph pattern similarity 】. This paper mainly describes a sub graph query method for determining patterns , For the data model with many subgraphs, you can also use the way that community members ask questions in the screenshot of this article to model the data, which can achieve the purpose of saving resources and space ; However, specific modeling scenarios need to be combined with business scenarios to be feasible . Known subgraphs can be used to find problems APOC To achieve ,apoc.path Related input / output query ; After specifying the node, get the child graph to which the node belongs , Then extract from the subgraph ROOT Properties of a node .
One 、 The problem background
Two 、 Build sample multi subgraph data
structure a、b、c、d、e、f Six nodes , And use
Follow
Relationships tie nodes together , Form a self defined subgraph . It specifies a The node is ROOT The node is the root node of the subgraph .
MERGE (a:Child {name:'a'}) SET a.subname='root'
MERGE (b:Child {name:'b'})
MERGE (c:Child {name:'c'})
MERGE (d:Child {name:'d'})
MERGE (e:Child {name:'e'})
MERGE (f:Child {name:'f'})
MERGE (a)-[:Follow]->(b)
MERGE (a)-[:Follow]->(c)
MERGE (b)-[:Follow]->(d)
MERGE (b)-[:Follow]->(e)
MERGE (c)-[:Follow]->(f)
3、 ... and 、 Implement the attribute lookup of the root node
stay
Two
Sample graph data is constructed in , The following implementation starts from any node in the sample graphROOT
node .
MATCH (n:Child) WHERE n.name='e'
CALL apoc.path.expand(n,'Follow',NULL,0,6) YIELD path WITH COLLECT(path) AS subGraph
UNWIND subGraph AS p
WITH nodes(p) AS nodes
UNWIND nodes AS node
WITH node
WHERE EXISTS(node.subname)
RETURN node
The query results are as follows , We successfully found our pre-designed a node , That is, what we need to find
ROOT
node .
Four 、 Search the subgraph GQL Encapsulate as a function
For a complex query , It is usually necessary to hide its implementation details to facilitate business invocation . Pass below
apoc.custom.asFunction
This process , The realization of will3、 ... and
The purpose of further encapsulating complex queries in . You only need to usecustom.subGraphRootName($para)
This function can .
CALL apoc.custom.asFunction(
'subGraphRootName',
'MATCH (n:Child) WHERE n.name=$nodeName CALL apoc.path.expand(n,\'Follow\',NULL,0,6) YIELD path WITH COLLECT(path) AS subGraph UNWIND subGraph AS p WITH nodes(p) AS nodes UNWIND nodes AS node WITH node WHERE EXISTS(node.subname) RETURN node',
'STRING',
[['nodeName','STRING']],
FALSE,
' Get the root node to which the specified node belongs , And return the root node's subname attribute '
);
RETURN custom.subGraphRootName('e') AS rootSubName;
5、 ... and 、 summary
This article uses a very simple scenario , A method of subgraph analysis is introduced . The problems faced in actual production may be more complicated than this , Data writing performance needs to be comprehensively considered 、 Data query performance 、 Data service usability and other factors . Data optimization in this article is just
The tip of the iceberg , A drop in the bucket
, It is necessary to constantly polish and practice in actual combat .
边栏推荐
- MySQL transactions and locks (V)
- Linked list: palindrome linked list
- Vs 2022 new features_ What's new in visual studio2022
- Six special GPU products for domestic aircraft passed the appraisal and review
- MySQL 8.0 installation free configuration method
- PostgreSQL common SQL
- Few-shot Unsupervised Domain Adaptation with Image-to-Class Sparse Similarity Encoding
- 2022 qianle micro cloud technology learning task plan
- Keil removes annoying st link update tips
- Explode and implode in PHP
猜你喜欢
[JVM Series 5] performance testing tool
Wechat applet switch style rewriting
Wechat applet coordinate location interface usage (II) map interface
JVM class loading (I)
Linked list: palindrome linked list
Operating principle of JS core EventLoop
SQL execution process in MySQL (3)
MySQL index bottom layer (I)
This article takes you to learn DDD, basic introduction
Keil去掉烦人的ST-Link更新提示
随机推荐
Linked list: palindrome linked list
JVM GC (V)
Data Governance Series 1: data governance framework [interpretation and analysis]
Supervisor -- Process Manager
Delete the number of a range in the linked list
Loading process of [JVM series 3] classes
Spark UDF instance details
通过Web ETL统一调度和管理DataX任务
Summary of rust language practice
【 enregistrement pytorch】 paramètre et tampon des variables pytorch. Self. Register Buffer (), self. Register Paramètre ()
Hash table: the time complexity of insert, delete and random access is O (1)
Redis memory optimization and distributed locking
Differences between XAML and XML
Es and kibana deployment and setup
On the career crisis of programmers at the age of 35
C simple understanding - arrays and sets
Introduction to redis (using redis, common commands, persistence methods, and cluster operations)
Four ways of array traversal in PHP
Add Yum source to install php74
【同步功能】2.0.16-19 版本都有同步功能修复的更新,但未解决问题