Skip to content

Commit b448f47

Browse files
author
Alain
committed
[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
1 parent d188b8b commit b448f47

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,8 +107,11 @@ private[tree] object DecisionTreeMetadata extends Logging {
107107
numTrees: Int,
108108
featureSubsetStrategy: String): DecisionTreeMetadata = {
109109

110-
val numFeatures = input.take(1)(0).features.size
111110
val numExamples = input.count()
111+
require(numExamples > 0, s"DecisionTree requires size of input RDD > 0, " +
112+
s"but was given by an empty one.")
113+
114+
val numFeatures = input.take(1)(0).features.size
112115
val numClasses = strategy.algo match {
113116
case Classification => strategy.numClasses
114117
case Regression => 0

0 commit comments

Comments
 (0)