Skip to content

Performing coalesce on NumberPath in from or where clause #1376

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

Closed
robertandrewbain opened this issue May 14, 2015 · 2 comments · Fixed by #2737
Closed

Performing coalesce on NumberPath in from or where clause #1376

robertandrewbain opened this issue May 14, 2015 · 2 comments · Fixed by #2737
Assignees
Labels
Milestone

Comments

@robertandrewbain
Copy link
Member

ComparableExpressionBase's public final Coalesce<T> coalesce(Expression<?>...exprs) returns a Coalesce<T>. Coalesce does not have SimpleExpression's public BooleanExpression eq(T right) method, so I assume the idea is to use Coalesce's public NumberExpression<?> asNumber(). However if you try to E.G: (I know the query is nonsense)

query()
.from(someRelationalPathBase)
.innerJoin(someOtherRelationalPathBase)
.on(someRelationalPathBase.id.coalesce(someOtherRelationalPathBase.id).asNumber().eq(someRelationalPathBase.id));

you receive the compiler error The method eq(capture#2-of ?) in the type SimpleExpression<capture#2-of ?> is not applicable for the arguments (NumberPath<Long>). I'm working around this with the following code:

 @SuppressWarnings("unchecked")
 public static <T extends Number & Comparable<T>> NumberOperation<T> coalesceNumbers(NumberPath<T> arg0, NumberPath<T> arg1) {
   return ((NumberOperation<T>) arg0.coalesce(arg1).asNumber());
 }
@cenobyte321
Copy link

Is there a workaround for this particular issue?

@jwgmeligmeyling
Copy link
Member

jwgmeligmeyling commented Jan 26, 2021

The current workaround is a cast: (NumberExpression<Long>) someRelationalPathBase.id.coalesce(someOtherRelationalPathBase.id).asNumber(). Alternatively: Expressions.asNumber(someRelationalPathBase.id.coalesce(someOtherRelationalPathBase.id)).

@jwgmeligmeyling jwgmeligmeyling self-assigned this Jun 8, 2021
@jwgmeligmeyling jwgmeligmeyling added this to the 5.0 milestone Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants