我正在使用用户定义的函数 (readByteUFF) 来读取文件,执行转换内容并返回 pyspark.sql 行。
在以下设置中,我在 rdd(应遵循相同模式的大量文件集合)上使用此函数:
mapped_rdd = rdd.map(readByteUFF)
df = mapped_rdd.toDF()
df.write.format("delta").mode("append").option("mergeSchema", "true").option("path", "dbfs:/mnt/").saveAsTable("table")
当文件遵循相同的模式时,这很有效,但是在函数返回错误或None
整个事情抛出我的情况下
org.apache.spark.SparkException:作业中止。
---------------------------------------------------------------------------
Py4JJavaError Traceback (most recent call last)
<command-3680885025756706> in <module>
8
9 #df.createOrReplaceTempView("table")
---> 10 df.write.format("delta").mode("append").option("mergeSchema", "true").option("path", "dbfs:/mnt/").saveAsTable("table")
/databricks/spark/python/pyspark/sql/readwriter.py in saveAsTable(self, name, format, mode, partitionBy, **options)
775 if format is not None:
776 self.format(format)
--> 777 self._jwrite.saveAsTable(name)
778
779 @since(1.4)
/databricks/spark/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py in __call__(self, *args)
1255 answer = self.gateway_client.send_command(command)
1256 return_value = get_return_value(
-> 1257 answer, self.gateway_client, self.target_id, self.name)
1258
1259 for temp_arg in temp_args:
/databricks/spark/python/pyspark/sql/utils.py in deco(*a, **kw)
61 def deco(*a, **kw):
62 try:
---> 63 return f(*a, **kw)
64 except py4j.protocol.Py4JJavaError as e:
65 s = e.java_exception.toString()
/databricks/spark/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
326 raise Py4JJavaError(
327 "An error occurred while calling {0}{1}{2}.\n".
--> 328 format(target_id, ".", name), value)
329 else:
330 raise Py4JError(
我希望能够在处理剩余文件时标记导致问题的文件。有没有办法在 flatMap() 功能中处理这个问题?