当前位置:网站首页>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,roles
Register 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,holdShareControllerRatio
Use 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.update
Component 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
边栏推荐
- js中的数组筛选fliter
- Will the memory of ParticleSystem be affected by maxparticles
- JS to realize the countdown function
- The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
- Summary of database 2
- 基于check-point机制的任务状态回滚和数据分块任务
- What is torch NN?
- Redis' optimistic lock and pessimistic lock for solving transaction conflicts
- @EnableAspectAutoJAutoProxy_ Exposeproxy property
- The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
猜你喜欢
D3D11_ Chili_ Tutorial (2): draw a triangle
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
Principle and general steps of SQL injection
[native JS] optimized text rotation effect
Audio and video technology development weekly | 252
Model fusion -- stacking principle and Implementation
QT graphical view frame: element movement
Object.keys()的用法
The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it
随机推荐
Interpretation of the champion scheme of CVPR 2020 night target detection challenge
基于check-point机制的任务状态回滚和数据分块任务
Sql实现Split
Object distance measurement of stereo vision
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
Final consistency of MESI cache in CPU -- why does CPU need cache
Research Report on market supply and demand and strategy of China's plastics and polymer industry
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
Lv166 turned over
js中的数组筛选fliter
PR FAQ: how to set PR vertical screen sequence?
How was MP3 born?
What is torch NN?
Communication mode based on stm32f1 single chip microcomputer
CMPSC311 Linear Device
Explore mongodb - mongodb compass installation, configuration and usage introduction | mongodb GUI
Move, say goodbye to the past again
Summary of database 2
Market trend report, technical innovation and market forecast of tetrabromophthalate (pht4 diol) in China
Accounting regulations and professional ethics [7]