java - 在 Spark 的驱动程序上捕获 Dataset foreachPartition() 函数中引发的异常?
问题描述
我正在尝试找到一种方法来捕获 Spark 在其驱动程序的 foreachPartition() 方法中引发的异常。在数据集上使用 foreachPartition() 时,我传递了一个跨多个工作人员执行的 lambda 函数。此过程可能会引发异常。但是我想不出一种方法来在驱动程序上捕获这个异常。看来这是设计使然。我能做些什么来改变这一点吗?这是我目前正在做的一个例子:
public static void driverClassExecute() {
Dataset<ModelDTO> dataset = getSomeData();
dataset.foreachPartition(AClass::methodCanThrowException);
//How can I recover if the above throws an exception?
}
public static void methodCanThrowException(Iterator<ModelDTO> it) throws Exception {
//do stuff. If bad, throw exception. This crashes the driver.
throw new Exception("any exception");
}
我也在使用 Eclipse Oxygen IDE,以防编译器很重要。
解决方案
在这种情况下,foreachPartition 将引发异常,因此您可以将该调用包装在 try-catch 中并像任何其他异常一样处理,尽管 spark 作业已经失败。为避免作业失败,您必须在 methodCanThrowException 中处理异常。
推荐阅读
- jestjs - 我可以为 jestjs 测试指定类别并选择要运行的类别吗?
- ubuntu - 无法使用 sox 转换批量 wav 文件
- javascript - 如何修复返回“未定义”的异步函数?
- xpages - 会话范围的托管 bean 似乎不是 xpages 应用程序中的会话范围
- python - Python - Tweepy - 列表引用问题
- python - 使用 Py2App 创建应用程序后,Tkinter GUI 按钮变得不可见
- python - 如何使用python中的循环将键和值分配给字典?
- php - 我们可以在 php 或 codeigniter 中创建在一段时间后过期的临时路由吗?
- android - 相关活动未关闭
- angular - 自定义比较密码验证器和这个 [Angular 2,4,5,6]