Pyspark中是否可以专门处理Hudi异常

问题描述 投票:0回答:1

我正在从 s3 读取 Hudi 表,有时存储桶或前缀可能为空,并且会抛出

 org.apache.hudi.exception.TableNotFoundException
。有没有办法让我导入并处理这些特定错误,而不是 try/ except 块中的通用
Exception

我使用的是spark 3.4.1和hudi 0.14

pyspark apache-hudi
1个回答
0
投票

是的,应该可以。首先导入预期的异常。

from org.apache.hudi.exception import TableNotFoundException

在 try except 语句中使用它。

try:
    if bucket_or_prefix_empty:
        raise TableNotFoundException("Bucket or prefix is empty")
except TableNotFoundException as e:
    print("Table not found:", e)
except Exception as e:
    print("An error occurred:", e)
© www.soinside.com 2019 - 2024. All rights reserved.