Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traversal Framework: No public method for creating ResourceIterable #13396

Open
mcclown opened this issue Feb 8, 2024 · 3 comments
Open

Traversal Framework: No public method for creating ResourceIterable #13396

mcclown opened this issue Feb 8, 2024 · 3 comments

Comments

@mcclown
Copy link

mcclown commented Feb 8, 2024

  • Neo4j version: 5.x (tested on 5.5.0 - 5.15.0)
  • Java Driver
  • Traversal Framework

I originally outlined the issue here https://community.neo4j.com/t/traversal-framework-working-with-resourceiterables/60963

So with the un-deprecation of the Traversal Framework for Neo4j 5.x there were some changes. One of them causes an issue that I can't resolve without using the undocumented internal APIs.

In Neo4j 4.x the following expand method would have worked. I want to filter the relationships that are returned from the expand. This is a simplified version of my actual method but shows the same problem. In reality I'm doing more complex filtering and ordering of the expanded relationships that are returned from this method.

@Override
public ResourceIterable<Relationship> expand(Path path, BranchState<TraverseState> bState)
{
	TraverseState state = state.getState();

	assert path.endNode().hasLabel(Labels.Undefined);

	var concludes = path.endNode().getRelationships(Direction.OUTGOING, RelationshipTypes.CONCLUDES);
	var expansion = new HashSet<Relationship>();

	for(Relationship rel : concludes)
	{
		if(!state.traverseOnce.contains(rel))
		{
			expansion.add(rel);
			state.traverseOnce.add(rel);
		}
	}

	if(expansion.size() > 0)
		return expansion;
	
	return Collections.emptyList();
}

For this code I get errors for both return statements because they're returning Iterables. If I try casting them, then I get runtime errors as the cast fails.

The only way I have gotten this to work is to use org.neo4j.internal.helpers.collection.Iterables, so the return statements become:

  • return Iterables.asResourceIterable(expansion);
  • return Iterables.emptyResourceIterable();

Now I don't want to have to use this internal API, as it's not supported but I can't find another way with the support API.

I think these static methods should be part of the public API, or another alternative should be made available. Currently there's no way to create a ResourceIterable directly, that I have found.

@ncordon
Copy link
Contributor

ncordon commented Feb 12, 2024

Thanks for reporting @mcclown, we'll look into it

@mcclown
Copy link
Author

mcclown commented Feb 12, 2024

@ncordon Thank you.

Another related item that someone just pointed out on the forums, the documentation of the Traversal Framework API documentation is also incorrect.

The code examples for creating a PathExpander show a very similar example to my use case but the code has the incorrect return type Iterable<Relationship> and wouldn't compile/work because of this. I can't find a way of implementing the example in the documentation without using the internal class/methods mentioned in the initial ticket.

https://neo4j.com/docs/java-reference/current/traversal-framework/traversal_framework_java_api/#_pathexpanderbuilder

image

@horak90
Copy link

horak90 commented Mar 28, 2024

Hello, I am having the same issue, are there any news on this topic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants