我需要将文件夹中的许多xmlf文件(zip格式)转换为Dataframe。所有关于堆栈溢出的讨论,都是基于databricks的。因为我没有使用databricks,所以我不能使用它们的方法。
有没有同样的方法?
我尝试的是:
我解压缩了文件并试图直接读取:
df_schema = spark.read.format("xml").option("rowTag", "Root").load("test.xml")
错误消息:
Py4JJavaError: An error occurred while calling o48.load.
: java.lang.ClassNotFoundException: Failed to find data source: xml. Please find packages at http://spark.apache.org/third-party-projects.html
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:639)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:190)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: xml.DefaultSource
我需要安装什么来解决这个问题吗?或者我需要通过python将xml转换成csv并读入Dataframe吗?
1条答案
按热度按时间bvn4nwqk1#
是的,您需要安装spark xml scala库。你可以通过maven坐标在spark作业中包含它们。https://github.com/databricks/spark-xml#scala-212