使用 DBR 7.3.x+ 将 XML 文件加载到 PySpark 中的数据帧

问题描述

我正在尝试在 databricks notebook 中使用 PySpark 将 XML 文件加载到数据框中。

df = spark.read.format("xml").options(
    rowTag="product",mode="PERMISSIVE",columnNameOfCorruptRecord="error_record"
).load(filePath)

这样做时,我收到以下错误:

Could not initialize class com.databricks.spark.xml.util.PermissiveMode$

Databricks 运行时版本:7.3 LTS Spark 版本:3.0.1 Scala 版本:2.12

相同的代码块在 DBR 6.4 Spark 2.4.5、Scala 2.11 中运行良好

解决方法

您需要将 spark_xml 库的版本升级到为 Scala 2.12 编译的版本,因为适用于 DBR 6.4 的版本与新的 Scala 版本不兼容。因此,您需要使用 spark-xml_2.11 而不是 spark-xml_2.12

附言我刚刚检查了 DBR 7.3 LTS & com.databricks:spark-xml_2.12:0.11.0 - 工作正常。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...