Collections: Not able to get .max() OR .count() and potentially others #315

Closed
velo opened this Issue Dec 17, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@velo
Contributor

velo commented Dec 17, 2012

Hi,

I was trying to a the max() value for a give object and got a CodeGen Compilation error:

com.mysema.codegen.CodegenException: Compilation of return max(animal.getBodyWeight()); failed.
/Q_0875751067_02056817302_2007665258.java:4: cannot find symbol
symbol  : method max(int)
location: class Q_0875751067_02056817302_2007665258
return max(animal.getBodyWeight());    }
       ^
1 error

I created a really simple test to show the problem.

    @Test
    public void test_max() {
        QAnimal a = QAnimal.animal;

        Animal lion = new Animal();
        lion.setBodyWeight(50);
        List<? extends Animal> animals = Arrays.asList(lion);
        long haviest = new CollQuery().from(a, animals).singleResult(a.count());
        assertEquals(1, haviest);
    }

With some instructions on where to start I'm willing to fix this myself.

VELO

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Dec 17, 2012

Member

Aggregation operations are currently not supported in Querydsl Collections.

Member

timowest commented Dec 17, 2012

Aggregation operations are currently not supported in Querydsl Collections.

@velo

This comment has been minimized.

Show comment
Hide comment
@velo

velo Dec 17, 2012

Contributor

Is that something on the roadmap?

Can I help on that?

Contributor

velo commented Dec 17, 2012

Is that something on the roadmap?

Can I help on that?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Dec 17, 2012

Member

It's not on the roadmap, since there hasn't been much demand for it. It could be implemented via the GroupBy functionality of querydsl-core.

But it's not quite trivial. It means that aggregation projections need to be detected and treated differently.

You could take a look at the code of querydsl-collections and see if you understand it.

These are good starting points :
https://github.com/mysema/querydsl/blob/master/querydsl-collections/src/main/java/com/mysema/query/collections/AbstractCollQuery.java

https://github.com/mysema/querydsl/blob/master/querydsl-collections/src/main/java/com/mysema/query/collections/DefaultQueryEngine.java

The logic of querydsl collections is actually quite simple.

It just serializes parts of the query (select, where, order) into Java source code, compiles it internally, caches it, runs the parts against the dynamic parts of the query and returns the results.

Member

timowest commented Dec 17, 2012

It's not on the roadmap, since there hasn't been much demand for it. It could be implemented via the GroupBy functionality of querydsl-core.

But it's not quite trivial. It means that aggregation projections need to be detected and treated differently.

You could take a look at the code of querydsl-collections and see if you understand it.

These are good starting points :
https://github.com/mysema/querydsl/blob/master/querydsl-collections/src/main/java/com/mysema/query/collections/AbstractCollQuery.java

https://github.com/mysema/querydsl/blob/master/querydsl-collections/src/main/java/com/mysema/query/collections/DefaultQueryEngine.java

The logic of querydsl collections is actually quite simple.

It just serializes parts of the query (select, where, order) into Java source code, compiles it internally, caches it, runs the parts against the dynamic parts of the query and returns the results.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 29, 2013

Member

Released in 3.2.2

Member

timowest commented Jul 29, 2013

Released in 3.2.2

@timowest timowest closed this Jul 29, 2013

@timowest timowest added this to the 3.2.2 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment