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 @@ -231,8 +231,12 @@ class PowerIterationClustering private[clustering] (
dataset.schema($(idCol)).dataType match {
case _: LongType =>
uncastPredictions
case _: IntegerType =>
uncastPredictions.withColumn($(idCol), col($(idCol)).cast(LongType))
Copy link
Contributor

@shahidki31 shahidki31 May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be

case _: IntegerType => uncastPredictions.withColumn($(idCol), col($(idCol)).cast(IntegerType))

Otherwise it is not necessary for casting. right? Because prediction already has id as Long type and dataset has id as IntegerType. So, we need to cast prediction.id to IntegerType. right?
Correct me if I am wrong.

case otherType =>
uncastPredictions.select(col($(idCol)).cast(otherType).alias($(idCol)))
throw new IllegalArgumentException(s"PowerIterationClustering had an unexpected error: " +
s"ID col was found to be of type ${otherType.simpleString}, despite initial schema " +
s"checks. Please report this bug.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,21 @@ class PowerIterationClusteringSuite extends SparkFunSuite
.setK(2)
.setMaxIter(1)

def runTest(idType: DataType, neighborType: DataType, similarityType: DataType): Unit = {
def runTest(idType: DataType, similarityType: DataType): Unit = {
val typedData = data.select(
col("id").cast(idType).alias("id"),
col("neighbors").cast(ArrayType(neighborType, containsNull = false)).alias("neighbors"),
col("neighbors").cast(ArrayType(idType, containsNull = false)).alias("neighbors"),
col("similarities").cast(ArrayType(similarityType, containsNull = false))
.alias("similarities")
)
model.transform(typedData).collect()
model.transform(typedData).select("id", "prediction").collect()
}

for (idType <- Seq(IntegerType, LongType)) {
runTest(idType, LongType, DoubleType)
}
for (neighborType <- Seq(IntegerType, LongType)) {
runTest(LongType, neighborType, DoubleType)
runTest(idType, DoubleType)
}
for (similarityType <- Seq(FloatType, DoubleType)) {
runTest(LongType, LongType, similarityType)
runTest(LongType, similarityType)
}
}

Expand Down