my2iu / Jinq

LINQ-style queries for Java 8
Other
659 stars 71 forks source link

can't leftOuterJoin support subquery? #114

Open phdbutbachelor opened 8 months ago

phdbutbachelor commented 8 months ago

Hello! I want to make a query like:

JinqStream<Pair<CommentEvent, User>> _query = stream(CommentEvent.class)
                .leftOuterJoin((i, session) -> session.stream(User.class), (i, j) -> j.getId().equals(i.getCreatorId()));

JinqStream<Pair<Pair<CommentEvent, User>, Pair<String, Long>>> _temp = _query.leftOuterJoin((j, source) -> source.stream(CommentEvent.class)
                                .where(k -> k.getSourceId() != null)
                                .group(k -> k.getSourceId(), (id, stream) -> stream.count()), (j, k) -> j.getOne().getId().equals(k.getOne()));

but throw a exception like 'can't thanslate to code', how to fix it?

my2iu commented 8 months ago

Do you have more extensive exception information? Usually, the exception will have additional information a few levels deeper inside explaining why the code could not be translated. When I just glance over the queries though, grouping queries are not allowed in subqueries (they're special in SQL and JPQL, so they are only supported at the top-level of a query).

my2iu commented 8 months ago

It also looks like, maybe you don't need any subqueries here. One left outer join between CommonEvent and User using CreatorId, then just use a normal join of that to CommonEvent based on SourceId. And then perform your grouping operation on everything afterwards. The subquery doesn't seem to be necessary.