虽然Scala UDF中的模式匹配(匹配具有double数据类型的列的模式),但它无法捕获其中包含空值的记录
val Binning = udf((colValue: Double) => {
colValue match {
case 1 => "one_day"
case x if (x > 1 && x <= 4) => "two_to_four_days"
case x if (x > 4 && x <= 7) => "four_to_seven_days"
case x if (x > 7 && x <= 14) => "one_to_two_weeks"
case x if (x > 14 && x <= 31) => "two_to_four_weeks"
case x if (x > 31 && x <= 90) => "more_than_one_month"
case x if (x > 90) => "more_than_three_month"
case _ => "zero_days"
}
输出中的我得到了:
+--------------------+
| output |
+--------------------+
|more_than_three_m...|
| more_than_one_month|
| two_to_four_weeks|
| one_to_two_weeks|
| two_to_four_days|
| zero_days|
| four_to_seven_days|
| null|
| one_day|
+--------------------+
它不应该在输出中填充null。知道发生了什么事吗?