Skip to content

Commit efc95c5

Browse files
committed
Add tests covering SPARK-17027
1 parent 47170b8 commit efc95c5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

mllib/src/test/scala/org/apache/spark/ml/feature/PolynomialExpansionSuite.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,29 @@ class PolynomialExpansionSuite
116116
.setDegree(3)
117117
testDefaultReadWrite(t)
118118
}
119+
120+
test("SPARK-17027. Integer overflow in PolynomialExpansion.getPolySize") {
121+
val data: Array[(Vector, Int, Int)] = Array(
122+
(Vectors.dense(1.0, 2.0, 3.0, 4.0, 5.0), 3002, 4367),
123+
(Vectors.sparse(5, Seq((0, 1.0), (4, 5.0))), 3002, 4367),
124+
(Vectors.dense(1.0, 2.0, 3.0, 4.0, 5.0, 6.0), 8007, 12375)
125+
)
126+
127+
val df = spark.createDataFrame(data)
128+
.toDF("features", "expectedPoly10size", "expectedPoly11size")
129+
130+
val t = new PolynomialExpansion()
131+
.setInputCol("features")
132+
.setOutputCol("polyFeatures")
133+
134+
for (i <- Seq(10, 11)) {
135+
val transformed = t.setDegree(i)
136+
.transform(df)
137+
.select(s"expectedPoly${i}size", "polyFeatures")
138+
.rdd.map { case Row(expected: Int, v: Vector) => expected == v.size }
139+
140+
assert(transformed.collect.forall(identity))
141+
}
142+
}
119143
}
120144

0 commit comments

Comments
 (0)