Spark: generate an error when reading from folder without _SUCCESS file

Viewed 166

I cannot seem to find any documentation, but I want to understand how I can do the following:

  • We have Spark pipelines that write data to S3 in the standard format where they write several part-... files and the _SUCCESS file to the folder.
  • We then have further Spark pipelines that read data from those S3 buckets.
  • We would like to have the pipelines automatically throw an exception (fail) if they try to read from a folder that does not have the _SUCCESS file.
  • We can create some sort of user-created function to manage this test, but it seems so common that I figured there must be an easy Spark-native way to generate this exception if the file is not found.

Is there such a native Spark way to trigger that exception?

1 Answers

The only way I can think of is using ,

boolean isExists=getFileSystem(spark.sparkContext().hadoopConfiguration())).exists(new Path("location of _SUCCESS file"));

if this returns false throw an exception.

Related