Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
select in scala only works with up to 5 fields #203
The "select" method only really works properly for the first 5 fields. If any more than that are added the result type of all the fields changes to something quite unusable, and, in this case, leads to a NullPointerException at run time. Here is my code:
val allPrograms= querySingle(QFeedPrograms)((q,t)=> q from t select(t.langno,t.progno,t.title,t.programTypeKey,t.isoMacrolanguageCode)) val allPrograms2= querySingle(QFeedPrograms)((q,t)=> q from t select(t.langno,t.progno,t.title,t.programTypeKey,t.isoMacrolanguageCode,t.sample))
The querySingle function is just a helper that I wrote. q is the query object and t is the table, QFeedPrograms. The first statement has 5 fields and the second has 6. The types of these statements are:
List[(Integer, String, String, Integer, String)]
List[(com.mysema.query.scala.NumberPath[Integer], com.mysema.query.scala.StringPath, com.mysema.query.scala.StringPath, com.mysema.query.scala.NumberPath[Integer], com.mysema.query.scala.StringPath, com.mysema.query.scala.StringPath)]
Both of these will compile, though the second one is quite useless, as far as I can tell. Is there a way to use this actually? The second statement causes a runtime error though:
The 5 field limit seems to come from the fact that select is only defined for 1,2,3,4, and 5 fields in the RichProjectable class (com/mysema/query/scala/Helpers.scala). Could this limit be pushed up to at least 20 fields? Or even an unlimited number? I've got plenty of queries that could make use of that many.
The table in question looks like:
Besides this I've really been loving querydsl in scala. Thanks.
Great! Thanks. Could you possibly deploy a build snapshot with this? I updated my git repo, but querydsl-core fails some tests. I turned tests off, but then querydsl-sql fails. No rush on this though.
As for generalizing, I'm not enough of a scala type guru to help you with that, sorry. One possible option in the future though is scala macros (http://scalamacros.org/). Its an experimental feature in scala 2.10.
This query now compiles, thanks.
However, I get the following runtime error:
I regenerated the scala code for the table with the lasted version of querydsl, but that did not help.