类型转换 DecimalType(10,5
) 例如99999.99999
至 DecimalType(
5,4) 在 Apache Spark 中默默返回 null
在这种情况下,是否可以更改此行为并允许 Spark 抛出异常(例如某些 CastException)并使作业失败而不是静默返回 null
?
最佳答案
/** * Change the precision / scale in a given decimal to those set in
decimalType
(if any), * returning null if it overflows or modifyingvalue
in-place and returning it if successful. * * NOTE: this modifiesvalue
in-place, so don't call it on external data. */
还有另一个线程,表明如果无法转换,则可能没有直接方法使代码失败。 Spark: cast decimal without changing nullable property of column .
所以,也许你可以尝试检查
null
类型转换列中的值并创建逻辑以失败(如果有)?
关于scala - 转换不兼容的 DecimalType 与 ClassCastException 时的 Apache Spark Null 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55688810/