-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[WIP][SPARK-25044][SQL] Address translation of LMF closure primitive args to Object in Scala 2.12 #22063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][SPARK-25044][SQL] Address translation of LMF closure primitive args to Object in Scala 2.12 #22063
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
package org.apache.spark.ml.classification | ||
|
||
import org.apache.spark.SparkException | ||
import org.apache.spark.annotation.{DeveloperApi, Since} | ||
import org.apache.spark.annotation.DeveloperApi | ||
import org.apache.spark.ml.{PredictionModel, Predictor, PredictorParams} | ||
import org.apache.spark.ml.feature.LabeledPoint | ||
import org.apache.spark.ml.linalg.{Vector, VectorUDT} | ||
|
@@ -164,8 +164,8 @@ abstract class ClassificationModel[FeaturesType, M <: ClassificationModel[Featur | |
var outputData = dataset | ||
var numColsOutput = 0 | ||
if (getRawPredictionCol != "") { | ||
val predictRawUDF = udf { (features: Any) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into this, and now I understand why it worked before. Scala 2.11 somehow can generate type tag for I think it makes more sense to specify the type and ask Spark to do type check. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your review @cloud-fan , I could really use your input here. That's a good find. It may be that we want to explicitly support UDFs where a schema isn't available -- see below. But I agree I'd rather not. It gets kind of messy though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea, but in any case the new version seems nicer :-) Both 2.11 and 2.12 will happily generate a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I apologize, that's my mistake. In the end it isn't related to TypeTags for Any and that is not a difference. Thanks for your input, I think we are close. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem! Happy to help with the 2.12 upgrade. |
||
predictRaw(features.asInstanceOf[FeaturesType]) | ||
val predictRawUDF = udfInternal { features: FeaturesType => | ||
predictRaw(features) | ||
} | ||
outputData = outputData.withColumn(getRawPredictionCol, predictRawUDF(col(getFeaturesCol))) | ||
numColsOutput += 1 | ||
|
@@ -174,8 +174,8 @@ abstract class ClassificationModel[FeaturesType, M <: ClassificationModel[Featur | |
val predUDF = if (getRawPredictionCol != "") { | ||
udf(raw2prediction _).apply(col(getRawPredictionCol)) | ||
} else { | ||
val predictUDF = udf { (features: Any) => | ||
predict(features.asInstanceOf[FeaturesType]) | ||
val predictUDF = udfInternal { features: FeaturesType => | ||
predict(features) | ||
} | ||
predictUDF(col(getFeaturesCol)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import org.apache.spark.sql.types.DataType | |
* @param nullable True if the UDF can return null value. | ||
* @param udfDeterministic True if the UDF is deterministic. Deterministic UDF returns same result | ||
* each time it is invoked with a particular input. | ||
* @param nullableTypes which of the inputTypes are nullable (i.e. not primitive) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The approach here is to capture at registration time whether the arg types are primitive, or nullable. Not a great way to record this, but might be the least hack for now |
||
*/ | ||
case class ScalaUDF( | ||
function: AnyRef, | ||
|
@@ -47,7 +48,8 @@ case class ScalaUDF( | |
inputTypes: Seq[DataType] = Nil, | ||
udfName: Option[String] = None, | ||
nullable: Boolean = true, | ||
udfDeterministic: Boolean = true) | ||
udfDeterministic: Boolean = true, | ||
nullableTypes: Seq[Boolean] = Nil) | ||
extends Expression with ImplicitCastInputTypes with NonSQLExpression with UserDefinedExpression { | ||
|
||
// The constructor for SPARK 2.1 and 2.2 | ||
|
@@ -58,7 +60,8 @@ case class ScalaUDF( | |
inputTypes: Seq[DataType], | ||
udfName: Option[String]) = { | ||
this( | ||
function, dataType, children, inputTypes, udfName, nullable = true, udfDeterministic = true) | ||
function, dataType, children, inputTypes, udfName, nullable = true, | ||
udfDeterministic = true, nullableTypes = Nil) | ||
} | ||
|
||
override lazy val deterministic: Boolean = udfDeterministic && children.forall(_.deterministic) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really surprised that this worked before...