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

Add stream() method to QueryResult / RepositoryResult #1808

Closed
jeenbroekstra opened this issue Jan 4, 2020 · 0 comments · Fixed by #1881
Closed

Add stream() method to QueryResult / RepositoryResult #1808

jeenbroekstra opened this issue Jan 4, 2020 · 0 comments · Fixed by #1881
Assignees
Labels
Projects
Milestone

Comments

@jeenbroekstra
Copy link
Contributor

@jeenbroekstra jeenbroekstra commented Jan 4, 2020

As an RDF4J user, I want to directly stream query results, so that I can use Java stream processing directly without having to know about the appropriate utility class.

Folloup of #1747

Currently, RDF4J allows processing a query result as a Java stream by means of a utility function: QueryResults.stream. This means that when you wish to use stream functionality (e.g. using it to map a stream of statements to something), you need to write code like the following:

List<Statement> result = QueryResults.stream(conn.getStatements(null, RDF.TYPE, null))
			.map(s -> vf.createStatement(s.getSubject(), RDFS.LABEL, vf.createLiteral("bar")))
			.collect(Collectors.toList());

To increase discoverability we can add the stream() method directly on the QueryResult and RepositoryResult interface, so that the following is possible:

List<Statement> result = conn.getStatements(null, RDF.TYPE, null).stream()
			.map(s -> vf.createStatement(s.getSubject(), RDFS.LABEL, vf.createLiteral("bar")))
			.collect(Collectors.toList());  

Although this is only marginally shorter code, it is far easier for an RDF4J end user to discover this method than the corresponding utility.

hmottestad added a commit that referenced this issue Jan 28, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Jan 28, 2020
…t more universably available

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Jan 28, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Jan 28, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Jan 28, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
@hmottestad hmottestad added this to the 3.1.0 milestone Jan 28, 2020
@jeenbroekstra jeenbroekstra added this to To do in Progress via automation Jan 29, 2020
@jeenbroekstra jeenbroekstra moved this from To do to In progress in Progress Jan 29, 2020
hmottestad added a commit that referenced this issue Feb 1, 2020
…streams with how finally works

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Feb 1, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Feb 1, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Feb 1, 2020
…t more universably available

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Feb 1, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Feb 1, 2020
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
hmottestad added a commit that referenced this issue Feb 1, 2020
…streams with how finally works

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
Progress automation moved this from In progress to Done Feb 2, 2020
hmottestad added a commit that referenced this issue Feb 2, 2020
* #1808 add methods for .stream()

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>

* #1808 use .stream where Iterations.stream was used before

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>

* #1808 simplified QueryResults slightly

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>

* #1808 align the automatic closing of failing streams with how finally works

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>

* #1808 benchmark

Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Progress
  
Done
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.