Blazebit / blaze-persistence

Rich Criteria API for JPA providers
https://persistence.blazebit.com
Apache License 2.0
742 stars 90 forks source link

Support grouping by select alias #1075

Open jwgmeligmeyling opened 4 years ago

jwgmeligmeyling commented 4 years ago

Just scribbling down a couple of notes that were still lying around my desk

Description

Since Hibernate 5.4.10 (HHH-9301) Hibernate supports grouping by select aliases - similar to ordering by select aliases - for dialects that support it (AFAIK H2, MySQL and PostgreSQL).

It would be nice if we could pass these aliases through for combinations of dialects and ORMs that do support it. Do we already allow aliases from the select clause in the order by clause?

A complicating factor here might be the nullability and uniqueness checks derived from the group by expressions. This case should probably be treated specially.

Expected behavior

Actual behavior

Steps to reproduce

Environment

Version:
JPA-Provider: Hibernate 5.4.10 DBMS: PostgreSQL, H2, MySQL Application Server:

beikov commented 4 years ago

We already support select aliases for order by, yes. There are a few things for this we have to take care of though. The implicit group by generation should obviously also make use of aliases if possible. We have a de-duplication in place for group bys which should probably also work on expression level rather than alias level.

jwgmeligmeyling commented 2 years ago

I am getting back into TimescaleDB again, so I am considering to pick this issue up.

Any pointers for classes I should have a look at? (i.e. where the same behaviour for order by is currently implemented?)

beikov commented 1 year ago

com.blazebit.persistence.impl.OrderByManager#buildOrderBy is handling the rendering to aliases, but it's a bit involved 😅

You'd have to implement something similar for com.blazebit.persistence.impl.GroupByManager#buildGroupBy