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

Interopoptimizer should only squash adjacent filters and sorts that uses the JPAStreamer metamodel #355

Closed
julgus opened this issue Jul 10, 2023 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@julgus
Copy link
Member

julgus commented Jul 10, 2023

Describe the bug
Adjacent operators of the same type that preserve {Order, Type, State, Side Effect} can be squashed into one single equivalent operator:

stream().filter(predicate1) .filter(predicate2) =
stream.filter(predicate1.and(predicate2))

This allows JPAStreamer to combine many filters into one WHERE clause. However, as a filters can only be applied to the SQL query if it uses a JPAStreamer predicate, the squashed predicate must also be a combination of JPAStreamer predicates to be applied on the query. As of now, JPAStreamer squashes all predicates, resulting in more operations being executed on the JVM side.

Expected behavior
Only adjacent filters using JPAStreamer predicates should be squashed.

Actual behavior
Predicates are merged regardless of the predicate type.

How To Reproduce
Run a query with two filters, one using a JPAStreamer predicate and one with an anonymous lambda. Observe in the Hibernate log that the first filter is not merged to the query. This happens as both filters are firsts squashed into an operator that cannot be merged into the query.

final List<Film> films = jpaStreamer.stream(Film.class)
                    .filter(Film$.length.greaterThan(120))
                    .filter(f -> f.getTitle().endsWith("A"))
                    .collect(Collectors.toList()); 

Build tool
e.g. Maven 3.9.0

JPAStreamer version
e.g. JPAStreamer 3.0.2

@julgus julgus added the bug Something isn't working label Jul 10, 2023
@julgus julgus added this to the 3.0.3 milestone Jul 10, 2023
@julgus julgus self-assigned this Jul 10, 2023
@julgus julgus changed the title Incorrect merge of filter()-operator Incorrect squash of filter() and sorted()-operator Jul 10, 2023
@julgus julgus changed the title Incorrect squash of filter() and sorted()-operator Merger should only squash adjacent filters and sorts that uses the JPAStreamer metamodel Jul 10, 2023
@julgus julgus changed the title Merger should only squash adjacent filters and sorts that uses the JPAStreamer metamodel Interopoptimizer should only squash adjacent filters and sorts that uses the JPAStreamer metamodel Jul 10, 2023
@julgus julgus closed this as completed in fd1ca5f Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant