python - 如何为 .write.mode("overwrite") 添加`try/except`
问题描述
我有一个函数可以将一些数据写入 S3 存储桶:
def write_to_s3(data, s3_path):
data.write.mode("overwrite").parquet(s3_path)
data.write.mode("overwrite").json(s3_path, compression="gzip")
如何添加try / except
语句以捕获潜在的错误/异常?我在网上找不到例子,有人可以帮忙吗?谢谢。
就像是:
def write_to_s3(data, s3_path):
try:
data.write.mode("overwrite").parquet(s3_path)
except ????Error as error:
logging.error(error)
raise
try:
data.write.mode("overwrite").json(s3_path, compression="gzip")
except ????Error as error:
logging.error(error)
raise
解决方案
推荐阅读
- javascript - 提高 Javascript 中多个 FETCH 请求的性能
- time-series - 在时间序列中添加到移动平均模型的平均值是什么?
- java - 这段代码是否正确地演示了多态性?(JAVA)
- git - 如何在 SSH 代理中使用密码短语自动加载 SSH 密钥
- javascript - 如何在 JS (PHP) 中使用 Laravel Blade
- javascript - 如何:使用 websocket 的 MS Bot 直接消息传递
- java - 使用 Java LocalTime 锁定下溢/上溢
- python - django.core.exceptions.ImproperlyConfigured:找不到 GDAL 库
- python - 无法从 txt 文件制作字典
- reactjs - 更新 reactjs 中的嵌套状态