当前位置:网站首页>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
边栏推荐
- 科普达人丨一文看懂阿里云的秘密武器“神龙架构”
- [Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
- 表单传递时,如何隐式将值传过去
- The four most common errors when using pytorch
- What is the catalog of SAP commerce cloud
- Model fusion -- stacking principle and Implementation
- Recommend 10 excellent mongodb GUI tools
- Digital recognition system based on OpenCV
- Overview of convolutional neural network structure optimization
- Practice: fabric user certificate revocation operation process
猜你喜欢
一图看懂ThreadLocal
Software Engineer vs Hardware Engineer
Audio and video technology development weekly | 252
~89 deformation translation
Function test - knowledge points and common interview questions
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
Ten clothing stores have nine losses. A little change will make you buy every day
Common knowledge of unity Editor Extension
Preliminary practice of niuke.com (10)
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
随机推荐
程序员怎么才能提高代码编写速度?
Application of clock wheel in RPC
Audio and video technology development weekly | 252
Essential basic knowledge of digital image processing
Research Report on plastic recycling machine industry - market status analysis and development prospect forecast
函數式接口,方法引用,Lambda實現的List集合排序小工具
Proxifier global agent software, which provides cross platform port forwarding and agent functions
What is torch NN?
ECCV 2022放榜了:1629篇论文中选,录用率不到20%
Will the memory of ParticleSystem be affected by maxparticles
Application and Optimization Practice of redis in vivo push platform
What does IOT engineering learn and work for?
[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
Book of night sky 53 "stone soup" of Apache open source community
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
Research Report on market supply and demand and strategy of tetramethylpyrazine industry in China
Filtered off site request to
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
D3D11_ Chili_ Tutorial (2): draw a triangle
2021 Google vulnerability reward program review