It is nothing to do with your code, I think. As far as I can tell, it is at least a minor bug in the driver. It should not throw an NPE in any event. If it's being triggered by some wrong usage pattern, I don't know what it is. The code looks fine.
You could try the latest MySQL driver, and/or step through the problem with the source code and debugger to try to get more information. If you come up with a workaround, let the list know. On Sun, Nov 21, 2010 at 12:04 PM, qadro <[email protected]> wrote: > Hi there, > > I've got a MySQL table: > pub_prefeences > user_id INTEGER NOT NULL (primary) > pub_id INTEGER NOT NULL (primary) > rate FLOAT NOT NULL > rtime DATETUME NOT NULL > is_favorite BIT(1) NOT NULL > > and some simple data in it: > user_id pub_id rate > 3 11 2 > 3 12 2 > 3 15 3 > 2 15 5 > 2 13 5 > 10 13 5 > 10 23 5 > > I call Mahout in the following way: > Integer neighborhoodSize = 1; > > MysqlConnectionPoolDataSource dataSource > = new MysqlConnectionPoolDataSource(); > dataSource.setUser("root"); > dataSource.setPassword("haslo"); > dataSource.setServerName("localhost"); > dataSource.setPort(3306); > dataSource.setDatabaseName("qadro"); > MySQLJDBCDataModel dataModel = new MySQLJDBCDataModel(dataSource, > "pub_preferences", "user_id", "pub_id", "rate", "rtime"); > > UserSimilarity userSimilarity > = new PearsonCorrelationSimilarity(dataModel); > userSimilarity.setPreferenceInferrer(new > AveragingPreferenceInferrer(dataModel)); > UserNeighborhood neighborhood > = new NearestNUserNeighborhood(neighborhoodSize, > userSimilarity, dataModel); > Recommender recommender = new GenericUserBasedRecommender(dataModel, > neighborhood, userSimilarity) > > List<RecommendedItem> recommendations = recommender.recommend(forUserId, > 1); > > dataModel.getNumUsers(), or dataModel.getNumItems() work as expected, so > does > dataModel.getPreferencesFromUser(). > > Unfortunately when asking for recommendation I get: > > java.lang.NullPointerException > at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2843) > at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2830) > at org.apache.mahout.cf.taste.impl.model.jdbc.AbstractJDBCDataModel. > getLongColumn(AbstractJDBCDataModel.java:721) > at org.apache.mahout.cf.taste.impl.model.jdbc.AbstractJDBCDataModel > $ResultSetIDIterator.nextLong(AbstractJDBCDataModel.java:799) > at org.apache.mahout.cf.taste.impl.model.jdbc.AbstractJDBCDataModel > $ResultSetIDIterator.next(AbstractJDBCDataModel.java:788) > at org.apache.mahout.cf.taste.impl.model.jdbc.AbstractJDBCDataModel > $ResultSetIDIterator.next(AbstractJDBCDataModel.java:742) > at org.apache.mahout.cf.taste.impl.recommender.TopItems > .getTopUsers(TopItems.java:99) > at > org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood > .getUserNeighborhood(NearestNUserNeighborhood.java:94) > at org.apache.mahout.cf.taste.impl.recommender > .GenericUserBasedRecommender.recommend(GenericUserBasedRecommender.java:80) > at org.apache.mahout.cf.taste.impl.recommender.AbstractRecommender > .recommend(AbstractRecommender.java:64) > at pl.edu.agh.mobilne.RecommendationEngine > .recommend(RecommendationEngine.java:55) > > Someone previously had this issue but it wasn't resolved: > > http://web.archiveorange.com/archive/v/wfftaSgxJSE3hnw46y40 > > Can anyone help? What am I doing wrong? :/ > Is my data table sufficient? > Is the neighborhood size sufficient? > >
