当前位置:网站首页>APOC custom functions and procedures
APOC custom functions and procedures
2022-07-04 16:41:00 【Ma Chao's blog】
@TOC[1]
specifies
APOC Provide related procedures to create user-defined functions and procedures . These functions and procedures are actually parameterized Cypher Language query , Similar macro (Macro) The concept of . In the following case, the library version is ongdb-3.5.22. Baidu concept explanation [2] macro ( English :Macro) It is a title of batch processing . The macro in computer science is an abstraction (Abstraction), It replaces certain text patterns according to a set of predefined rules . The interpreter or the compiler automatically performs the first mock exam when it meets macros . For compiled languages , Macro expansion occurs at compile time , The tool for macro development is often called macro developer . The term macro is often used in many similar environments , They are concepts derived from macro expansion , This includes keyboard macros and macro languages . In most cases ,“ macro ” The use of this word implies the conversion of small commands or actions into a series of instructions .
View custom functions and procedures
CALL dbms.functions() YIELD name,signature,description,roles WHERE name CONTAINS 'custom' RETURN name,signature,description,roles
UNION
CALL dbms.procedures() YIELD name,signature,description,roles WHERE name CONTAINS 'custom' RETURN name,signature,description,roles
View the stored procedures for building custom functions and procedures
CALL dbms.functions() YIELD name,signature,description,roles WHERE name CONTAINS 'apoc.custom' RETURN name,signature,description,roles
UNION
CALL dbms.procedures() YIELD name,signature,description,roles WHERE name CONTAINS 'apoc.custom' RETURN name,signature,description,rolesRegister a custom function
# Input and output fields and their types , The format is as follows :
[ ['item1','type1'],
['item2','type2'],
…
]
# String::output
# List<List<String>>::inputs
# String::description
apoc.custom.asFunction(name, statement, outputs, inputs, forceSingle, description)
apoc.custom.declareFunction(signature, statement, forceSingle, description)Register a custom process
• Support to return more complex data types
# Input and output fields and their types , The format is as follows :
[ ['item1','type1'],
['item2','type2'],
…
]
# List<List<String>>::output
# List<List<String>>::inputs
# String::description
# mode Patterns supported by the process :
/** This procedure will only perform read operations against the graph */
READ,
/** This procedure may perform both read and write operations against the graph */
WRITE,
/** This procedure will perform operations against the schema */
SCHEMA,
/** This procedure will perform system operations - i.e. not against the graph */
DBMS,
/** This procedure will only perform read operations against the graph */
DEFAULT
apoc.custom.asProcedure(name, statement, mode, outputs, inputs, description)
apoc.custom.declareProcedure(signature, statement, mode, description)Data types supported by input and output parameters
case "ANY": return NTAny;
case "MAP": return NTMap;
case "NODE": return NTNode;
case "REL": return NTRelationship;
case "RELATIONSHIP": return NTRelationship;
case "EDGE": return NTRelationship;
case "PATH": return NTPath;
case "NUMBER": return NTNumber;
case "LONG": return NTInteger;
case "INT": return NTInteger;
case "INTEGER": return NTInteger;
case "FLOAT": return NTFloat;
case "DOUBLE": return NTFloat;
case "BOOL": return NTBoolean;
case "BOOLEAN": return NTBoolean;
case "DATE": return NTDate;
case "TIME": return NTTime;
case "LOCALTIME": return NTLocalTime;
case "DATETIME": return NTDateTime;
case "LOCALDATETIME": return NTLocalDateTime;
case "DURATION": return NTDuration;
case "POINT": return NTPoint;
case "GEO": return NTGeometry;
case "GEOMETRY": return NTGeometry;
case "STRING": return NTString;
case "TEXT": return NTString;
default: return NTString;Check the list of functions and procedures
apoc.custom.list()Delete function
apoc.custom.removeFunction(name, type)Delete process
apoc.custom.removeProcedure(name)Use case 1
• Custom function
CALL apoc.custom.asFunction(
'double',
'RETURN $input*2 as answer',
'long',
[['input','number']]
);
RETURN custom.double(12) AS value;• Custom process
CALL apoc.custom.asProcedure('answer','RETURN $input as answer','read',[['answer','number']],[['input','int','42']])
CALL custom.answer() YIELD answer RETURN answer
CALL custom.answer(13) YIELD answer RETURN answer
Use case 2
• Functions and procedures need to be used for publishing to other users admin structure • Based on the length of time distance, add up the number of effective shares
WITH 20160630000000 AS endTime,' Shenzhen Investment Holding Co., Ltd ' AS name
// Filter out the edge of the effective number of shares and find the nearest shareholding relationship based on the length of time distance
// First filter out the effective number of shares holdAmontCalc>0 The edge of , Then the number of shares is selected from the side based on the length of time distance detail
MATCH (n:HORGShareHoldV002 {name:name})-[r: holding ]->(m:HORGShareHoldV002) WHERE ANY(detail IN apoc.convert.fromJsonList(r.shareholding_detail) WHERE detail.holdAmontCalc>0) WITH apoc.convert.fromJsonMap(olab.samplingByDate.dis.jsonArray(olab.convert.json(FILTER(detail IN apoc.convert.fromJsonList(r.shareholding_detail) WHERE detail.holdAmontCalc>0)),'defineDate',endTime)) AS detail
// Total shares
RETURN SUM(detail.holdAmontCalc) AS holdTotal• Based on the length of time distance, add up the number of effective shares - Defined function
CALL apoc.custom.asFunction(
'sum.hold',
'WITH $endTime AS endTime,$name AS name MATCH (n:HORGShareHoldV002 {name:name})-[r: holding ]->(m:HORGShareHoldV002) WHERE ANY(detail IN apoc.convert.fromJsonList(r.shareholding_detail) WHERE detail.holdAmontCalc>0) WITH apoc.convert.fromJsonMap(olab.samplingByDate.dis.jsonArray(olab.convert.json(FILTER(detail IN apoc.convert.fromJsonList(r.shareholding_detail) WHERE detail.holdAmontCalc>0)),\'defineDate\',endTime)) AS detail RETURN SUM(detail.holdAmontCalc) AS holdTotal',
'LONG',
[['endTime','LONG'],['name','STRING']],
false,
' Total effective holdings '
);• Use the function to query the total number of effective holdings
RETURN custom.sum.hold(20160630000000,' Shenzhen Investment Holding Co., Ltd ')Use case 3
• Functions and procedures need to be used for publishing to other users admin structure • Query the basic information of the company and the actual controller
// 1、 Define company name
WITH [' Energy Technology Co., Ltd ',' Hkust xunfei ',' COFCO Group Co., Ltd ',' Harvest Fund ',' Wuhan Contemporary Technology Industry Group Co., Ltd '] AS nameList
UNWIND nameList AS companyName
// 2、 Definition GraphQL Inquire about
// # Standard name of the company name
// # company HCODE hcode
// # Tag information Tag
// # Source code SrcCompanyCode source # Source main table code -code # Main table name -table
// legal_person_repr # Legal representative reg_capital # The registered capital ( element ) establishment_date # Date of establishment biz_scope # Scope of business business_major # Main business
WITH REPLACE('{\"query\":\"query myConcernedCompany($name: String) { horgByName(name: $name) {name hcode Tag SrcCompanyCode { source code table Hold_Controller { name ratio } } HOrgInfo {legal_person_repr reg_capital establishment_date biz_scope business_major } }}\","variables":{\"name\":\"company-name\"},\"operationName\":\"myConcernedCompany\"}','company-name',companyName) AS query
WITH apoc.convert.fromJsonMap(olab.http.post('http://10.20.13.130/ongdb/graphql',query)) AS result
// 3、 Obtain the company legal person 、 The registered capital 、 Date of establishment 、 Business scope information also Get Wande code and Caihui code
WITH result.data.horgByName[0].hcode AS hcode,result.data.horgByName[0].name AS name,result.data.horgByName[0].Tag AS Tag,result.data.horgByName[0].SrcCompanyCode AS SrcCompanyCode,result.data.horgByName[0].HOrgInfo AS HOrgInfo
// Analyze the code of Wande and Caihui as well as Main business information Analyze the object of the actual controller
WITH hcode,name,Tag,FILTER(source IN SrcCompanyCode WHERE source.table='TCR0001')[0].code AS ciahuiCode,FILTER(source IN SrcCompanyCode WHERE source.table='CompIntroduction')[0].code AS windCode,HOrgInfo,FILTER(holdCont IN SrcCompanyCode WHERE holdCont.Hold_Controller<>[])[0].Hold_Controller[0] AS holdController
WITH hcode,name,Tag,REPLACE(ciahuiCode,'api','') AS caihuiCode,windCode,HOrgInfo[0].reg_capital AS reg_capital,HOrgInfo[0].legal_person_repr AS legal_person_repr,HOrgInfo[0].business_major AS business_major,HOrgInfo[0].biz_scope AS biz_scope,HOrgInfo[0].establishment_date AS establishment_date,holdController.name AS holdShareController,holdController.ratio AS holdShareControllerRatio
CALL apoc.case([business_major IS NOT NULL,'RETURN $business_major AS scope',biz_scope IS NOT NULL,'RETURN $biz_scope AS scope'],'',{business_major:business_major,biz_scope:biz_scope}) YIELD value
// Scope of business The main body of code Standard name Array of tags Caihui code WIND Code The registered capital legal person Date of establishment Real controller Shareholding ratio of actual controller
RETURN value.scope AS scope ,hcode,name,Tag,caihuiCode,windCode,reg_capital,legal_person_repr,establishment_date,holdShareController,holdShareControllerRatio• Use the process to query the basic information of the company and the actual controller - The build process
CALL apoc.custom.asProcedure(
'org.basicinfo',
'WITH $name AS companyName WITH REPLACE(\'{\\\"query\\\":\\\"query myConcernedCompany($name: String) { horgByName(name: $name) {name hcode Tag SrcCompanyCode { source code table Hold_Controller { name ratio } } HOrgInfo {legal_person_repr reg_capital establishment_date biz_scope business_major } }}\\\","variables":{\\\"name\\\":\\\"company-name\\\"},\\\"operationName\\\":\\\"myConcernedCompany\\\"}\',\'company-name\',companyName) AS query WITH apoc.convert.fromJsonMap(olab.http.post(\'http://10.20.13.130/ongdb/graphql\',query)) AS result WITH result.data.horgByName[0].hcode AS hcode,result.data.horgByName[0].name AS name,result.data.horgByName[0].Tag AS Tag,result.data.horgByName[0].SrcCompanyCode AS SrcCompanyCode,result.data.horgByName[0].HOrgInfo AS HOrgInfo WITH hcode,name,Tag,FILTER(source IN SrcCompanyCode WHERE source.table=\'TCR0001\')[0].code AS ciahuiCode,FILTER(source IN SrcCompanyCode WHERE source.table=\'CompIntroduction\')[0].code AS windCode,HOrgInfo,FILTER(holdCont IN SrcCompanyCode WHERE holdCont.Hold_Controller<>[])[0].Hold_Controller[0] AS holdController WITH hcode,name,Tag,REPLACE(ciahuiCode,\'api\',\'\') AS caihuiCode,windCode,HOrgInfo[0].reg_capital AS reg_capital,HOrgInfo[0].legal_person_repr AS legal_person_repr,HOrgInfo[0].business_major AS business_major,HOrgInfo[0].biz_scope AS biz_scope,HOrgInfo[0].establishment_date AS establishment_date,holdController.name AS holdShareController,holdController.ratio AS holdShareControllerRatio CALL apoc.case([business_major IS NOT NULL,\'RETURN $business_major AS scope\',biz_scope IS NOT NULL,\'RETURN $biz_scope AS scope\'],\'\',{business_major:business_major,biz_scope:biz_scope}) YIELD value RETURN value.scope AS scope ,hcode,name,olab.convert.json(Tag) as Tag,caihuiCode,windCode,reg_capital,legal_person_repr,establishment_date,holdShareController,holdShareControllerRatio',
'READ',
[['scope','STRING'],['hcode','STRING'],['name','STRING'],['Tag','STRING'],['caihuiCode','STRING'],['windCode','STRING'],['reg_capital','STRING'],['legal_person_repr','STRING'],['establishment_date','STRING'],['holdShareController','STRING'],['holdShareControllerRatio','STRING']],
[['name','STRING']],
' Use the process to query the basic information of the company and the return of the actual controller 【 Scope of business The main body of code Standard name Array of tags Caihui code WIND Code The registered capital legal person Date of establishment Real controller Shareholding ratio of actual controller 】'
);• View the defined process
CALL dbms.procedures() YIELD name,signature,description,roles WHERE name CONTAINS 'org.basicinfo' RETURN name,signature,description,roles• Use the process to query the basic information of the company and the actual controller
WITH [' Energy Technology Co., Ltd ',' Hkust xunfei ',' COFCO Group Co., Ltd ',' Harvest Fund ',' Wuhan Contemporary Technology Industry Group Co., Ltd '] AS nameList
UNWIND nameList AS companyName
CALL custom.org.basicinfo(companyName) YIELD scope,hcode,name,Tag,caihuiCode,windCode,reg_capital,legal_person_repr,establishment_date,holdShareController,holdShareControllerRatio RETURN scope,hcode,name,apoc.convert.fromJsonList(Tag) AS tag,caihuiCode,windCode,reg_capital,legal_person_repr,establishment_date,holdShareController,holdShareControllerRatioUse case 4
• Chinese function name
CALL apoc.custom.asFunction(
' Digital printing function ',
'RETURN $input*2 as answer',
'long',
[['input','number']]
);
RETURN custom. Digital printing function (12) AS value;• Chinese process name
CALL apoc.custom.asProcedure(' Digital printing process ','RETURN $input as answer','read',[['answer','number']],[['input','int','42']]);CALL custom. Digital printing process (12) YIELD answer RETURN answer;Custom function and procedure storage location
• New properties
KEY::apoc.custom
KEY::apoc.custom.updateComponent download
•apoc-3.5.0.15-all
https://github.com/ongdb-contrib/neo4j-apoc-procedures/releases/tag/3.5.0.15.1•ongdb-lab-apoc-3.5.22
https://github.com/ongdb-contrib/ongdb-lab-apoc/releases/tag/3.5.22.x•ongdb-enterprise-3.5.22
https://github.com/graphfoundation/ongdb/releases/tag/3.5.22
References
[1] TOC: ONgDB-APOC Custom functions and procedures [2] Baidu concept explanation : https://baike.baidu.com/item/%E5%AE%8F/2648286?fr=aladdin
边栏推荐
- Explore mongodb - mongodb compass installation, configuration and usage introduction | mongodb GUI
- Move, say goodbye to the past again
- Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
- [tutorial] yolov5_ DeepSort_ The whole process of pytoch target tracking and detection
- 《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
- [North Asia data recovery] a database data recovery case where the disk on which the database is located is unrecognized due to the RAID disk failure of HP DL380 server
- 基于check-point机制的任务状态回滚和数据分块任务
- Essential basic knowledge of digital image processing
- What is torch NN?
- 2021 Google vulnerability reward program review
猜你喜欢
![[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded](/img/c5/f933ad4a7bc903f15beede62c6d86f.jpg)
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded

AutoCAD - set color

对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平

~88 running people practice

Move, say goodbye to the past again
![[North Asia data recovery] a database data recovery case where the disk on which the database is located is unrecognized due to the RAID disk failure of HP DL380 server](/img/79/3fab19045e1ab2f5163033afaa4309.jpg)
[North Asia data recovery] a database data recovery case where the disk on which the database is located is unrecognized due to the RAID disk failure of HP DL380 server

Cut! 39 year old Ali P9, saved 150million

Function test - knowledge points and common interview questions

Detailed process of DC-2 range construction and penetration practice (DC range Series)

Position encoding practice in transformer
随机推荐
Expression #1 of ORDER BY clause is not in SELECT list, references column ‘d.dept_ no‘ which is not i
Will the memory of ParticleSystem be affected by maxparticles
Audio and video technology development weekly | 252
Summary of database 2
QT graphical view frame: element movement
Accounting regulations and professional ethics [7]
The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it
[flask] ORM one to many relationship
What is the catalog of SAP commerce cloud
%F format character
Accounting regulations and professional ethics [11]
[North Asia data recovery] a database data recovery case where the partition where the database is located is unrecognized due to the RAID disk failure of HP DL380 server
ONgDB图数据库与Spark的集成
AI system content recommendation issue 24
TypeError: not enough arguments for format string
Overview of convolutional neural network structure optimization
How to decrypt worksheet protection password in Excel file
线程池的使用和原理
Preliminary practice of niuke.com (10)
如何为ONgDB核心项目源码做贡献