Querydsl compare tuples

46 Views Asked by At

I'm trying to build a Querydsl expression in Java. I'm trying to get to:

where (last_name, first_name, actor_id) < ('Allen', 'Meryl', 194)

Where we're doing the tuple comparison. This is supported by mysql and postgres.

I've got all my ComparablePaths in:

List<ComparablePath> paths = new ArrayList<>();

You can assume this list is correctly populated (it is). So, I'm trying to do:

BooleanBuilder pred = new BooleanBuilder(Expressions.list(paths.toArray(new ComparablePath[0])).???);

But ??? does not have the lt operator. Just eq, ne, in, not in, etc. None of the comparison ones.

How can we generate the tuple comparison in querydsl?

1

There are 1 best solutions below

4
VIGEEDUN On

If we assume that the paths list is ordered the same way as the fields in the tuple we can do :

var pred = new BooleanBuilder();
pred.and(paths.get(0).lt("Allen"))
.and(paths.get(1).lt("Meryl"))
.and(paths.get(2).lt(194));