Code Monkey home page Code Monkey logo

apoc's Introduction

Discourse users Discord

Awesome Procedures for Neo4j 5.0.x

Introduction

apoc

Neo4j 3.x introduced the concept of user-defined procedures and functions. Those are custom implementations of certain functionality, that can’t be (easily) expressed in Cypher itself. They are implemented in Java and can be easily deployed into your Neo4j instance, and then be called from Cypher directly.

As of 5.0 APOC has been split into separate repositories, one being the main, officially supported, APOC Library. The other belonging to APOC Extended. This repository handles the core part of APOC.

There are over 400 different procedures and functions in the APOC library. Their purpose is to increase functionality in areas such as data integration, graph algorithms and data conversion.

License

Apache License 2.0

"APOC" Name history

Apoc was the technician and driver on board of the Nebuchadnezzar in the Matrix movie. He was killed by Cypher.

APOC was also the first bundled A Package Of Component for Neo4j in 2009.

APOC also stands for "Awesome Procedures On Cypher"

Installation: With Neo4j Desktop

APOC can be installed with Neo4j Desktop, after creating your database, by going to the Manage screen, and then the Plugins tab. Click Install in the APOC box and wait until you see a green check mark near "APOC".

desktop apoc

Feedback

Please provide feedback and report bugs as GitHub issues or join the Neo4j Community Forum and ask in the APOC & Procedures category.

Calling Procedures & Functions within Cypher

User defined Functions can be used in any expression or predicate, just like built-in functions.

Procedures can be called stand-alone with CALL procedure.name();

But you can also integrate them into your Cypher statements which makes them so much more powerful.

Load JSON example
WITH 'https://raw.githubusercontent.com/neo4j/apoc/5.0/core/src/test/resources/person.json' AS url

CALL apoc.load.json(url) YIELD value as person

MERGE (p:Person {name:person.name})
   ON CREATE SET p.age = person.age, p.children = size(person.children)

APOC Procedures & Functions Overview

All included procedures are listed in the overview in the documentation and detailed in subsequent sections.

Built in Help

apoc help apoc

call apoc.help('keyword')

lists name, description, signature, roles, based on keyword

Detailed Feature Documentation

See the APOC User Guide for documentation of each of the major features of the library, including data import/export, graph refactoring, data conversion, and more.

Procedure & Function Signatures

To call procedures correctly, you need to know their parameter names, types and positions. And for YIELDing their results, you have to know the output column names and types.

INFO:The signatures are shown in error messages, if you use a procedure incorrectly.

You can see the procedure’s signature in the output of CALL apoc.help("name")

CALL apoc.help("dijkstra")

The signature is always name : : TYPE, so in this case:

apoc.algo.dijkstra
 (startNode :: NODE?, endNode :: NODE?,
   relationshipTypesAndDirections :: STRING?, weightPropertyName :: STRING?)
:: (path :: PATH?, weight :: FLOAT?)
Table 1. Parameter Explanation
Name Type

Procedure Parameters

startNode

Node

endNode

Node

relationshipTypesAndDirections

String

weightPropertyName

String

Output Return Columns

path

Path

weight

Float

Manual Installation: Download the latest release

Since APOC relies on Neo4j’s internal APIs you need to use the matching APOC version for your Neo4j installation. Make sure that the first two version numbers match between Neo4j and APOC.

Go to the latest release for Neo4j version 5.0 and download the binary jar to place into your $NEO4J_HOME/plugins folder.

You can find all releases here.

Manual Configuration

Warning

For security reasons, procedures that use internal APIs are disabled by default. They can be enabled by specifying config in $NEO4J_HOME/conf/neo4j.conf e.g. dbms.security.procedures.unrestricted=apoc.*

If you want to do this when using the Neo4j Docker container, you need to amend -e NEO4J_dbms_security_procedures_unrestricted=apoc.\\\* to your docker run …​ command. The three backslashes are necessary to prevent wildcard expansions.

You can also allow procedures and functions in general to be loaded using: dbms.security.procedures.allowlist=apoc.coll.*,apoc.load.*

Version Compatibility Matrix

Since APOC relies in some places on Neo4j’s internal APIs you need to use the right APOC version for your Neo4j installation.

APOC uses a consistent versioning scheme: <neo4j-version>.<apoc> version. The trailing <apoc> part of the version number will be incremented with every apoc release.

apoc version neo4j version

5.1.0

5.1.0 (5.1.x)

5.0.0

5.0.0 (5.0.x)

4.4.0.1

4.4.0 (4.3.x)

4.3.0.4

4.3.7 (4.3.x)

4.2.0.9

4.2.11 (4.2.x)

4.1.0.10

4.1.11 (4.1.x)

4.0.0.18

4.0.12 (4.0.x)

3.5.0.15

3.5.30 (3.5.x)

3.4.0.8

3.4.18 (3.4.x)

3.3.0.4

3.3.9 (3.3.x)

3.2.3.6

3.2.14 (3.2.x)

3.1.3.9

3.1.9 (3.1.x)

3.0.8.6

3.0.12 (3.0.x)

3.5.0.0

3.5.0-beta01

3.4.0.2

3.4.5

3.3.0.3

3.3.5

3.2.3.5

3.2.3

3.1.3.8

3.1.5

Get APOC Version

To know your current apoc version you can use the function :

RETURN apoc.version();

Using APOC with the Neo4j Docker image

APOC can be used with the Neo4j Docker image via the NEO4JLABS_PLUGINS environment variable. If we use this environment variable, the APOC plugin will be downloaded and configured at runtime.

Note

This feature is intended to facilitate using APOC in development environments, but it is not recommended for use in production environments.

The following runs Neo4j 5.0 in a Docker container with the latest version of the APOC Library
docker run \
    -p 7474:7474 -p 7687:7687 \
    -v $PWD/data:/data -v $PWD/plugins:/plugins \
    --name neo4j-apoc \
    -e apoc.export.file.enabled=true \
    -e apoc.import.file.enabled=true \
    -e apoc.import.file.use_neo4j_config=true \
    -e NEO4JLABS_PLUGINS=\[\"apoc\"\] \
    neo4j:5.0

We should see the following two lines in the output after running this command:

Fetching versions.json for Plugin 'apoc' from https://neo4j.github.io/apoc/versions.json
Installing Plugin 'apoc' from https://github.com/neo4j/apoc/releases/download/5.4.0/5.4.0.jar to /plugins/apoc.jar

In a production environment we should download the APOC release matching our Neo4j version and, copy it to a local folder, and supply it as a data volume mounted at /plugins.

The following downloads the APOC Library into the plugins directory and then mounts that folder to the Neo4j Docker container
mkdir plugins
pushd plugins
wget https://github.com/neo4j/apoc/releases/download/5.4.0/apoc-5.4.0.jar
popd
docker run --rm -e NEO4J_AUTH=none -p 7474:7474 -v $PWD/plugins:/plugins -p 7687:7687 neo4j:5.0

If you want to pass custom apoc config to your Docker instance, you can use environment variables, like here:

docker run \
    -p 7474:7474 -p 7687:7687 \
    -v $PWD/data:/data -v $PWD/plugins:/plugins \
    --name neo4j-apoc \
    -e apoc.export.file.enabled=true \
    -e apoc.import.file.enabled=true \
    -e apoc.import.file.use_neo4j_config=true \
    neo4j

To then use Neo4j with Docker, it is possible to run the Cypher-shell like so:

docker exec -it neo4j-apoc bin/cypher-shell

Build & install the current development branch from source

git clone https://github.com/neo4j/apoc
cd apoc
./gradlew shadow
cp build/extended/libs/apoc-<version>.jar $NEO4J_HOME/plugins/
$NEO4J_HOME/bin/neo4j restart

A full build including running the tests can be run by ./gradlew build.

You can either copy the jar (build/libs) into the neo4j target folder (target/neo4j/plugins folder) or launch it in a dockerized neo4j by mounting the directory containing the apoc-procedures jar as a volume.

Running APOC tests

With intellij - right-click on the test folder, and you will be able to run all tests from there With gradle - ./gradlew test

Or as normal, click the play button on the test you would like to run. === Applying Code-style

./gradlew spotlessApply

To apply the spotless code-style, run the above gradle command, this will remove all unused imports

apoc's People

Contributors

jexp avatar mneedham avatar sarmbruster avatar conker84 avatar vga91 avatar angelobusato avatar github-actions[bot] avatar ncordon avatar mishademianenko avatar inversefalcon avatar lojjs avatar neo4j-oss-build avatar gem-neo4j avatar azuobs avatar albertodelazzari avatar fbiville avatar ikwattro avatar szarnyasg avatar jmhreif avatar adtc avatar zimmre avatar adam-cowley avatar alexiudice avatar tomasonjo avatar burqen avatar moxious avatar klaren avatar kvegter avatar bradnussbaum avatar vboulaye avatar

Stargazers

Hadj H. avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.