- Graph Developer's Guide for Property Graph
- Getting Started with Oracle Property Graphs
- Using the In-Memory Graph Server (PGX)
- Using Custom PGX Graph Algorithms
- Compiling and Running a Custom PGX Algorithm
4.9.2 Compiling and Running a Custom PGX Algorithm
To be able to compile and run a custom PGX algorithm, you must perform the
following actions:
- Set the following two configuration parameters in the
conf/pgx.conf
file:- Set the
graph_algorithm_language
option toJAVA
. - Set the
java_home_dir
option to the path to your Java home (use<system-java-home-dir>
to have PGX infer Java home from the system properties).
{ "graph_algorithm_language": "JAVA", "java_home_dir": "<system-java-home-dir>" }
- Set the
- Create a session.
- Compile a PGX Algorithm. For example:
opg4j> var myAlgorithm = session.compileProgram("/path/to/MyAlgorithm.java") myAlgorithm ==> CompiledProgram[name=MyAlgorithm]
import oracle.pgx.algorithm.CompiledProgram; CompiledProgram myAlgorithm = session.compileProgram("/path/to/MyAlgorithm.java");
my_algorithm = session.compile_program("/path/to/MyAlgorithm.java")
- Run the algorithm. For example:
opg4j> var graph =session.readGraphWithProperties("/path/to/bank_graph_analytics.json") graph ==> PgxGraph[name=bank_graph_analytics,N=1000,E=5001,created=1633504705054] opg4j> var property = graph.createVertexProperty(PropertyType.INTEGER) property ==> VertexProperty[name=vertex_prop_integer_9,type=integer,graph=bank_graph_analytics] opg4j> myAlgorithm.run(graph, property) $6 ==> { "success" : true, "canceled" : false, "exception" : null, "returnValue" : 42, "executionTimeMs" : 0 }
import oracle.pgx.algorithm.VertexProperty; PgxGraph graph = session.readGraphWithProperties("/path/to/bank_graph_analytics.json"); VertexProperty property = graph.createVertexProperty(PropertyType.INTEGER); myAlgorithm.run(graph, property);
graph = session.read_graph_with_properties("/path/to/bank_graph_analytics.json") property = graph.create_vertex_property("integer") my_algorithm.run(graph, property) {'success': True, 'canceled': False, 'exception': None, 'return_value': 42, 'execution_time(ms)': 1}
Parent topic: Using Custom PGX Graph Algorithms