Skip to content

Commit d4cb38a

Browse files
Alainsrowen
authored andcommitted
[MLLIB] [TREE] Verify size of input rdd > 0 when building meta data
Require non empty input rdd such that we can take the first labeledpoint and get the feature size Author: Alain <[email protected]> Author: [email protected] <[email protected]> Closes apache#5810 from AiHe/decisiontree-issue and squashes the following commits: 3b1d08a [[email protected]] [MLLIB][tree] merge the assertion into the evaluation of numFeatures cf2e567 [Alain] [MLLIB][tree] Use a rdd api to verify size of input rdd > 0 when building meta data b448f47 [Alain] [MLLIB][tree] Verify size of input rdd > 0 when building meta data
1 parent 9d250e6 commit d4cb38a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mllib/src/main/scala/org/apache/spark/mllib/tree/impl/DecisionTreeMetadata.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ private[tree] object DecisionTreeMetadata extends Logging {
107107
numTrees: Int,
108108
featureSubsetStrategy: String): DecisionTreeMetadata = {
109109

110-
val numFeatures = input.take(1)(0).features.size
110+
val numFeatures = input.map(_.features.size).take(1).headOption.getOrElse {
111+
throw new IllegalArgumentException(s"DecisionTree requires size of input RDD > 0, " +
112+
s"but was given by empty one.")
113+
}
111114
val numExamples = input.count()
112115
val numClasses = strategy.algo match {
113116
case Classification => strategy.numClasses

0 commit comments

Comments
 (0)