neo4j / graph-data-science

Source code for the Neo4j Graph Data Science library of graph algorithms.
https://neo4j.com/docs/graph-data-science/current/
Other
596 stars 157 forks source link

Canno't load "write-enabled" procedures in an embedded context #288

Closed contrebande-labs closed 9 months ago

contrebande-labs commented 9 months ago

Describe the bug

None of the write-enabled procedures will load because of exception of type Unable to set up injection for procedure XXXXXX, the field YYYYYYYYYhas type ZZZZZZZ which is not a known injectable component.. Here is a list of the unknown injectable components which prevent loading:

Here is how I'm loading the procedures:

final var managementService = new DatabaseManagementServiceBuilder(databaseDirectory)
 setConfig(procedure_unrestricted,  List.of("gds.*"))
.setConfig(procedure_allowlist,  List.of("gds.*"))
.build();

final var procedures = ((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency(GlobalProcedures.class);

for(final var clazz: new Reflections("org.neo4j.gds").getSubTypesOf(BaseProc.class)) procedures.registerProcedure(clazz);

To Reproduce

Here are the maven-loaded dependencies

<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
<dependency>
    <groupId>org.reflections</groupId>
    <artifactId>reflections</artifactId>
    <version>0.10.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.neo4j.gds/core -->
<dependency>
    <groupId>org.neo4j.gds</groupId>
    <artifactId>core</artifactId>
    <version>2.4.6</version>
    <scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.neo4j.gds/proc -->
<dependency>
    <groupId>org.neo4j.gds</groupId>
    <artifactId>proc</artifactId>
    <version>2.4.6</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.neo4j.gds/open-model-catalog -->
<dependency>
    <groupId>org.neo4j.gds</groupId>
    <artifactId>open-model-catalog</artifactId>
    <version>2.4.6</version>
    <scope>runtime</scope>
</dependency>

GDS version: 2.4.6 Neo4j version: 5.12.0 Operating system: Java 21, Ubuntu 22.04

Anyone knows how to make this work? Thanks!

contrebande-labs commented 9 months ago

Might not be the most elegant way, but I solved my problem by doing this:

procedures.registerComponent(
    RelationshipExporterBuilder.class,
    kernelContext -> kernelContext.dependencyResolver().resolveDependency(RelationshipExporterBuilder.class),
    true
);

procedures.registerComponent(
    RelationshipStreamExporterBuilder.class,
    kernelContext -> kernelContext.dependencyResolver().resolveDependency(RelationshipStreamExporterBuilder.class),
    true
);

procedures.registerComponent(
    RelationshipPropertiesExporterBuilder.class,
    kernelContext -> kernelContext.dependencyResolver().resolveDependency(RelationshipPropertiesExporterBuilder.class),
    true
);

procedures.registerComponent(
    NodePropertyExporterBuilder.class,
    kernelContext -> kernelContext.dependencyResolver().resolveDependency(NodePropertyExporterBuilder.class),
    true
);

procedures.registerComponent(
    NodeLabelExporterBuilder.class,
    kernelContext -> kernelContext.dependencyResolver().resolveDependency(NodeLabelExporterBuilder.class),
    true
);

If someone could show me a better way I'd be happy to simplify my code.

vnickolov commented 9 months ago

@contrebande-labs thank you for raising this.

The issue is that you'd need to declare dependency to open-write-services too (see https://github.com/neo4j/graph-data-science#developing-with-opengds):

<!-- Required by the write execution modes, this artifact is responsible for providing the various exporters -->
<dependency>
  <groupId>org.neo4j.gds</groupId>
  <artifactId>open-write-services</artifactId>
  <version>2.4.6</version>
</dependency>
contrebande-labs commented 9 months ago

thanks @vnickolov, it works!

vnickolov commented 9 months ago

Happy to help @contrebande-labs, I will close this issue now.

Thank you for using the library and please let us know if you have any issues or questions.