Skip to content

Commit f055d82

Browse files
author
Feynman Liang
committed
Fix failing scalatest
1 parent 2e00cba commit f055d82

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mllib/src/main/scala/org/apache/spark/mllib/fpm/LocalPrefixSpan.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ private[fpm] object LocalPrefixSpan extends Logging with Serializable {
4848
if (database.isEmpty) return Iterator.empty
4949

5050
val frequentItemAndCounts = getFreqItemAndCounts(minCount, database)
51-
val frequentItems = frequentItemAndCounts.map(_._1)
51+
val frequentItems = frequentItemAndCounts.map(_._1).toSet
5252
val frequentPatternAndCounts = frequentItemAndCounts
5353
.map { case (item, count) => ((item :: prefix).reverse.toArray, count) }
5454

5555
val filteredProjectedDatabase = database.map(x => x.filter(frequentItems.contains(_)))
5656

5757
if (prefix.length + 1 < maxPatternLength) {
58-
frequentPatternAndCounts ++ frequentItems.flatMap { item =>
58+
frequentPatternAndCounts.iterator ++ frequentItems.flatMap { item =>
5959
val nextProjected = project(filteredProjectedDatabase, item)
6060
run(minCount, maxPatternLength, item :: prefix, nextProjected)
6161
}
6262
} else {
63-
frequentPatternAndCounts
63+
frequentPatternAndCounts.iterator
6464
}
6565
}
6666

@@ -93,12 +93,11 @@ private[fpm] object LocalPrefixSpan extends Logging with Serializable {
9393
*/
9494
private def getFreqItemAndCounts(
9595
minCount: Long,
96-
database: Iterable[Array[Int]]): Iterator[(Int, Long)] = {
96+
database: Iterable[Array[Int]]): Iterable[(Int, Long)] = {
9797
database.flatMap(_.distinct)
9898
.foldRight(Map[Int, Long]().withDefaultValue(0L)) { case (item, ctr) =>
9999
ctr + (item -> (ctr(item) + 1))
100100
}
101101
.filter(_._2 >= minCount)
102-
.iterator
103102
}
104103
}

0 commit comments

Comments
 (0)