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

select in scala only works with up to 5 fields #203

Closed
khoran opened this issue Jul 27, 2012 · 7 comments
Closed

select in scala only works with up to 5 fields #203

khoran opened this issue Jul 27, 2012 · 7 comments

Comments

@khoran
Copy link

@khoran khoran commented Jul 27, 2012

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)]

and

 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:

Exception occured while processing /language/all<pre>Message: java.lang.NullPointerException
        com.mysema.query.DefaultQueryMetadata.validate(DefaultQueryMetadata.java:306)
        com.mysema.query.DefaultQueryMetadata.addProjection(DefaultQueryMetadata.java:140)
        com.mysema.query.support.QueryMixin.addToProjection(QueryMixin.java:75)
        com.mysema.query.sql.AbstractSQLQuery.iterate(AbstractSQLQuery.java:343)
        com.mysema.query.sql.AbstractSQLQuery.list(AbstractSQLQuery.java:464)
        com.mysema.query.scala.RichProjectable.select(Helpers.scala:64)
        net.globalrecordings.LanguageFactory$$anonfun$21.apply(DataObjects.scala:363)
        net.globalrecordings.LanguageFactory$$anonfun$21.apply(DataObjects.scala:363)
        net.globalrecordings.GrDatabaseUtils$$anonfun$querySingle$1.apply(GrDatabaseUtils.scala:18)
        net.globalrecordings.GrDatabaseUtils$$anonfun$querySingle$1.apply(GrDatabaseUtils.scala:18)
        net.globalrecordings.LiftUtils$$anonfun$useConnection$1.apply(LiftUtils.scala:8)
        net.globalrecordings.LiftUtils$$anonfun$useConnection$1.apply(LiftUtils.scala:8)
        net.liftweb.db.DB$$anonfun$use$1.apply(DB.scala:639)
        net.liftweb.util.DynoVar$class.run(ThreadGlobal.scala:95)
        net.liftweb.db.DB$class.use(DB.scala:636)
        net.liftweb.db.DB$$anon$1.use(DB.scala:38)
        net.globalrecordings.LiftUtils$.useConnection(LiftUtils.scala:8)
        net.globalrecordings.LanguageFactory$$anonfun$22.apply(DataObjects.scala:363)
        net.globalrecordings.LanguageFactory$$anonfun$22.apply(DataObjects.scala:363)
        net.globalrecordings.GrDatabaseUtils$.querySingle(GrDatabaseUtils.scala:18)
        net.globalrecordings.LanguageFactory$.allLanguages(DataObjects.scala:363)
        net.globalrecordings.snippet.LocationFeed$$anonfun$1.apply(Feeds.scala:46)
        net.globalrecordings.snippet.LocationFeed$$anonfun$1.apply(Feeds.scala:23)
        scala.PartialFunction$$anon$2.apply(PartialFunction.scala:58)
        net.liftweb.http.rest.RestHelper$$anon$11$$anonfun$apply$1.apply(RestHelper.scala:337)
        net.liftweb.http.rest.RestHelper$$anon$11$$anonfun$apply$1.apply(RestHelper.scala:336)
        net.liftweb.http.LiftServlet$$anonfun$liftedTree1$1$1.apply(LiftServlet.scala:343)
        net.liftweb.http.LiftServlet$$anonfun$liftedTree1$1$1.apply(LiftServlet.scala:343)
        net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
        net.liftweb.http.S$class.functionLifespan(S.scala:1626)
        net.liftweb.http.LiftServlet.liftedTree1$1(LiftServlet.scala:342)
        net.liftweb.http.LiftServlet.net$liftweb$http$LiftServlet$$dispatchStatefulRequest(LiftServlet.scala:329)
        net.liftweb.http.LiftServlet$$anonfun$doSession$1$1.apply(LiftServlet.scala:279)
        net.liftweb.http.LiftServlet$$anonfun$doSession$1$1.apply(LiftServlet.scala:279)
        net.liftweb.http.S$class.net$liftweb$http$S$$wrapQuery(S.scala:1371)
        net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit$1$$anonfun$apply$34.apply(S.scala:1519)
        net.liftweb.http.S$class.net$liftweb$http$S$$doAround(S.scala:1300)
        net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit$1.apply(S.scala:1517)
        net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
        net.liftweb.http.S$class.net$liftweb$http$S$$_nest2InnerInit(S.scala:1516)
        < the rest truncated >

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:

               View "websites.feed_programs"
         Column         |         Type          | Modifiers 
------------------------+-----------------------+-----------
 langno                 | integer               | 
 progno                 | character varying(6)  | 
 title                  | character varying(50) | 
 program_type_key       | integer               | 
 iso_macrolanguage_code | character(3)          | 
 iso_macrolanguage_name | character varying(63) | 
 iso_language_code      | character(3)          | 
 iso_language_name      | character varying(63) | 
 youtube_url            | character varying(60) | 
 sample                 | character varying(6)  | 

Besides this I've really been loving querydsl in scala. Thanks.

Kevin

@timowest
Copy link
Member

@timowest timowest commented Jul 27, 2012

I will raise this to 20 tomorrow, any idea how this could be generalized?

@khoran
Copy link
Author

@khoran khoran commented Jul 27, 2012

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.

timowest added a commit that referenced this issue Jul 27, 2012
@timowest
Copy link
Member

@timowest timowest commented Jul 27, 2012

I just deployed 2.7.1.BUILD-SNAPSHOT to our Snapshots repository https://source.mysema.com/maven2/snapshots/

@khoran
Copy link
Author

@khoran khoran commented Jul 29, 2012

This query now compiles, thanks.

val allPrograms = querySingle(QFeedPrograms)((q,t)=> q from t select(t.langno,t.progno,t.title,t.programTypeKey,t.isoMacrolanguageCode, t.isoMacrolanguageName, t.isoLanguageCode,t.isoLanguageName,t.youtubeUrl,t.sample))

However, I get the following runtime error:

>Exception occured while processing /language/all<pre>Message: java.lang.NullPointerException
        com.mysema.query.sql.JavaTypeMapping.findType(JavaTypeMapping.java:137)
        com.mysema.query.sql.JavaTypeMapping.getType(JavaTypeMapping.java:114)
        com.mysema.query.sql.Configuration.getType(Configuration.java:123)
        com.mysema.query.sql.Configuration.get(Configuration.java:93)
        com.mysema.query.sql.AbstractSQLQuery.get(AbstractSQLQuery.java:287)
        com.mysema.query.sql.AbstractSQLQuery.newInstance(AbstractSQLQuery.java:494)
        com.mysema.query.sql.AbstractSQLQuery.access$000(AbstractSQLQuery.java:62)
        com.mysema.query.sql.AbstractSQLQuery$3.produceNext(AbstractSQLQuery.java:427)
        com.mysema.query.sql.SQLResultIterator.next(SQLResultIterator.java:81)
        com.mysema.commons.lang.IteratorAdapter.asList(IteratorAdapter.java:40)
        com.mysema.query.sql.AbstractSQLQuery.list(AbstractSQLQuery.java:469)
        com.mysema.query.scala.RichProjectable.select(Helpers.scala:99)
        net.globalrecordings.LanguageFactory$$anonfun$21.apply(DataObjects.scala:373)
        net.globalrecordings.LanguageFactory$$anonfun$21.apply(DataObjects.scala:373)
        net.globalrecordings.GrDatabaseUtils$$anonfun$querySingle$1.apply(GrDatabaseUtils.scala:18)
        net.globalrecordings.GrDatabaseUtils$$anonfun$querySingle$1.apply(GrDatabaseUtils.scala:18)
        net.globalrecordings.LiftUtils$$anonfun$useConnection$1.apply(LiftUtils.scala:8)
        net.globalrecordings.LiftUtils$$anonfun$useConnection$1.apply(LiftUtils.scala:8)
        net.liftweb.db.DB$$anonfun$use$1.apply(DB.scala:639)
        net.liftweb.util.DynoVar$class.run(ThreadGlobal.scala:95)
        net.liftweb.db.DB$class.use(DB.scala:636)
        net.liftweb.db.DB$$anon$1.use(DB.scala:38)
        <truncated>

I regenerated the scala code for the table with the lasted version of querydsl, but that did not help.

@timowest
Copy link
Member

@timowest timowest commented Jul 29, 2012

Thanks for testing. Can you create a new ticket for the last stacktrace? I will take a look tomorrow.

@khoran
Copy link
Author

@khoran khoran commented Jul 29, 2012

Sure. I should mention though that I had been using version 2.3.3 without realizing it. This doesn't affect the need for this fix, but this new issue could be related to moving to 2.7.1 as well.

@timowest
Copy link
Member

@timowest timowest commented Aug 4, 2012

Released in 2.7.2

@timowest timowest closed this Aug 4, 2012
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