xml - 在 Spark 中读取 XML
问题描述
我正在尝试使用 spark-xml jar 在 pyspark 中读取 xml/嵌套 xml。
df = sqlContext.read \
.format("com.databricks.spark.xml")\
.option("rowTag", "hierachy")\
.load("test.xml"
当我执行时,数据框没有正确创建。
+--------------------+
| att|
+--------------------+
|[[1,Data,[Wrapped...|
+--------------------+
下面提到了我拥有的 xml 格式:
解决方案
heirarchy
应该是rootTag并且att
应该是rowTag为
df = spark.read \
.format("com.databricks.spark.xml") \
.option("rootTag", "hierarchy") \
.option("rowTag", "att") \
.load("test.xml")
你应该得到
+-----+------+----------------------------+
|Order|attval|children |
+-----+------+----------------------------+
|1 |Data |[[[1, Studyval], [2, Site]]]|
|2 |Info |[[[1, age], [2, gender]]] |
+-----+------+----------------------------+
和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)
推荐阅读
- reactjs - React 测试库 - 模拟一个函数
- javascript - 是否可以在不使用当前状态的条件语句的情况下使用状态机?
- python - 基于配置和用户的动态过滤器:PySpark
- html - 我可以为粉红色冥想网站添加哪些设计方面使其看起来更有趣?
- python - 如何在表单中使用 pythonmechanissoup 将文件上传到 ASP.net 站点
- html - UL 现在显示为编号列表
- python - conda 环境改变了哪个 conda
- reactjs - Redux 在解构时只提取一部分数据
- php - 我无法在 Codeigniter 中获取 stdClass 对象值
- linux - 一段时间后,当从 Windows SSH 到 linux 机器时,子进程(在分叉后创建)卡在 Windows 上