Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ object ALS extends DefaultParamsReadable[ALS] with Logging {
checkpointInterval: Int = 10,
seed: Long = 0L)(
implicit ord: Ordering[ID]): (RDD[(ID, Array[Float])], RDD[(ID, Array[Float])]) = {
require(!ratings.isEmpty(), s"No ratings available from $ratings")
require(intermediateRDDStorageLevel != StorageLevel.NONE,
"ALS is not designed to run without persisting intermediate RDDs.")
val sc = ratings.sparkContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ class ALS private (
*/
@Since("0.8.0")
def run(ratings: RDD[Rating]): MatrixFactorizationModel = {
require(!ratings.isEmpty(), s"No ratings available from $ratings")

val sc = ratings.context

val numUserBlocks = if (this.numUserBlocks == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.apache.spark._
import org.apache.spark.internal.Logging
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.ml.recommendation.ALS._
import org.apache.spark.ml.recommendation.ALS.Rating
import org.apache.spark.ml.util.{DefaultReadWriteTest, MLTestingUtils}
import org.apache.spark.ml.util.TestingUtils._
import org.apache.spark.mllib.util.MLlibTestSparkContext
Expand Down Expand Up @@ -539,6 +540,13 @@ class ALSSuite
}.getMessage.contains("was out of Integer range"))
}
}

test("SPARK-18268: ALS with empty RDD should fail with better message") {
val ratings = sc.parallelize(Array.empty[Rating[Int]])
intercept[IllegalArgumentException] {
ALS.train(ratings)
}
}
}

class ALSCleanerSuite extends SparkFunSuite {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ class ALSSuite extends SparkFunSuite with MLlibTestSparkContext {
testALS(100, 200, 2, 15, 0.7, 0.4, false, false, false, -1, -1, false)
}

test("SPARK-18268: ALS with empty RDD should fail with better message") {
val ratings = sc.parallelize(Array.empty[Rating])
intercept[IllegalArgumentException] {
new ALS().run(ratings)
}
}

/**
* Test if we can correctly factorize R = U * P where U and P are of known rank.
*
Expand Down