LUZ*_*UZO 3 xml dataframe apache-spark pyspark apache-spark-xml
我正在尝试使用 spark-xml jar 在 pyspark 中读取 xml/嵌套 xml。
df = sqlContext.read \
.format("com.databricks.spark.xml")\
.option("rowTag", "hierachy")\
.load("test.xml"
Run Code Online (Sandbox Code Playgroud)
当我执行时,数据框没有正确创建。
+--------------------+
| att|
+--------------------+
|[[1,Data,[Wrapped...|
+--------------------+
Run Code Online (Sandbox Code Playgroud)
下面提到了我的 xml 格式:
heirarchy应该是rootTag并且att应该是rowTag作为
df = spark.read \
.format("com.databricks.spark.xml") \
.option("rootTag", "hierarchy") \
.option("rowTag", "att") \
.load("test.xml")
Run Code Online (Sandbox Code Playgroud)
你应该得到
+-----+------+----------------------------+
|Order|attval|children |
+-----+------+----------------------------+
|1 |Data |[[[1, Studyval], [2, Site]]]|
|2 |Info |[[[1, age], [2, gender]]] |
+-----+------+----------------------------+
Run Code Online (Sandbox Code Playgroud)
和 schema
root
|-- Order: long (nullable = true)
|-- attval: string (nullable = true)
|-- children: struct (nullable = true)
| |-- att: array (nullable = true)
| | |-- element: struct (containsNull = true)
| | | |-- Order: long (nullable = true)
| | | |-- attval: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)
查找有关databricks xml 的更多信息