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

Allow multiple named subqueries for @MappingSubquery #1896

Open
beikov opened this issue Apr 25, 2024 · 0 comments
Open

Allow multiple named subqueries for @MappingSubquery #1896

beikov opened this issue Apr 25, 2024 · 0 comments

Comments

@beikov
Copy link
Member

beikov commented Apr 25, 2024

Right now, the SubqueryProvider only allows adding one subquery, but it would be awesome if we allowed multiple named subqueries.
Maybe we can add a sub-interface for this purpose?

Possible workaround is to use a SubqueryProvider with fromValues e.g.:

public class NameAndOrgCountCorrelationProvider implements SubqueryProvider {

        @Override
        public <T> T createSubquery(SubqueryInitiator<T> subqueryBuilder) {
            return subqueryBuilder.fromValues(Integer.class, "i", List.of(1))
                .selectSubqueries("q1 + q2")
                    .with("q1")
                        .from(Name.class, "n")
                        .where("n.relationship.id").eqExpression("EMBEDDING_VIEW(relationship.id)")
                        .bind("nr").select("count(*)")
                    .end()
                    .with("q2")
                        .from(Org.class, "o")
                        .where("org.relId").eqExpression("EMBEDDING_VIEW(relationship.id)")
                        .bind("nr").select("count(*)")
                    .end()
                .end()
            .end();
        }
}
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

1 participant