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

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

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

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

velo opened this issue Dec 17, 2012 · 4 comments
Milestone

Comments

@velo
Copy link
Contributor

@velo 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
Copy link
Member

@timowest timowest commented Dec 17, 2012

Aggregation operations are currently not supported in Querydsl Collections.

@velo
Copy link
Contributor Author

@velo velo commented Dec 17, 2012

Is that something on the roadmap?

Can I help on that?

@timowest
Copy link
Member

@timowest 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
Copy link
Member

@timowest 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
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants