首页 > 解决方案 > 为什么 Apache Spark 在作业运行时会进行一些检查并引发这些异常,但在单元测试期间从未抛出它们?

问题描述

我的 Scala 代码中有一个错误,它格式化了时间戳的日期,然后作为字符串连接到 Spark Streaming 的一些非时间戳列:

concat(date_format(col("timestamp"),"yyyy-MM-DD'T'HH:mm:ss.SSS'Z'")

因此,在测试期间,一切正常,测试,将消息发送到 Kafka,都通过了,我能够在 Kafka 工具中看到这些消息:

在此处输入图像描述

不是 10 月 292 日,因为DD不是dd在格式化程序中。

但是在执行程序中,有一些额外的检查没有通过,工作就崩溃了:

Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 8.0 failed 1 times, most recent failure: Lost task 1.0 in stage 8.0 (TID 12, kafkadatageneratorjob-driver, executor driver): org.apache.spark.SparkUpgradeException: You may get a different result due to the upgrading of Spark 3.0: Fail to format it to '2021-10-292T14:27:12.577Z' in the new formatter. You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0, or set to CORRECTED and treat it as an invalid datetime string.

如何对单元测试启用相同的严格检查,以使它们在没有明确检查值的情况下也无法通过这些检查,而只是强制 timeParserPolicy 也在测试中执行。

标签: scalaapache-sparkapache-spark-sqlspark-structured-streamingapache-spark-3.0

解决方案


推荐阅读