Github user srowen commented on a diff in the pull request: https://github.com/apache/spark/pull/21740#discussion_r202531693 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala --- @@ -75,10 +75,22 @@ class MatrixFactorizationModel @Since("0.8.0") ( } } + /** Check for the invalid user. */ + private def validateUser(user: Int): Unit = { + require(userFeatures.lookup(user).nonEmpty, s"userId: $user not found in the model") --- End diff -- The problem is you now look up the user and product twice. Instead, the callers should probably check whether `userFeatures.lookup(user)` is empty before calling `.head` and otherwise throw the exception.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org