pyspark - Spark DataFrame 获取所有
每个元素的 xml 文档中的 xml 标签
问题描述
我为 Pyspark 中的数据框打印了这个模式 - 用于 xml 文件:
root
|-- _id: long (nullable = true)
|-- _published-at: string (nullable = true)
|-- _title: string (nullable = true)
|-- a: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- _VALUE: string (nullable = true)
| | |-- _href: string (nullable = true)
| | |-- _type: string (nullable = true)
|-- p: array (nullable = true)
| |-- element: string (containsNull = true)
XML 数据如下所示:
如您所见,每篇文章内容都是带有 < P> 和 < a> 标签的 html,架构将每篇文章的内容确定为 < P> 标签数组,但实际上在显示数据时,它只采用第一个 < P> 标记直到第一个 <a> 并且剩余的内容被忽略!
articles_df.select("_id", articles_df.p.alias('content')).show(truncate=False)
17 |[Chief juvenile probation officer ]
我怎么能保证拿起所有的内容?(下一步将是在没有 html 特殊承租人的情况下对其进行格式化: )
我尝试使用自己的自定义架构,但得到了相同的结果:
link_structure = StructType([
StructField("_VALUE", StringType(), True),
StructField("_href", StringType(), True),
StructField("_type", StringType(), True)
])
articles_schema = StructType([
StructField("_id", LongType(), True),
StructField("_published-at", StringType(), True),
StructField("_title", StringType(), True),
StructField("a", ArrayType(link_structure), True),
StructField("p", ArrayType(StringType()), True)])
articles_df = spark.read.format('xml'). \
options(rootTag='articles', rowTag='article'). \
load('data-sets/articles-validation-small.xml', schema=articles_schema)
解决方案
推荐阅读
- c++ - 带有模板参数的 Lambda 函数,而不是函数参数
- python - Python混淆矩阵中的模型精度为0%
- r - 如何为闪亮列表中的单个列表元素渲染数据表或渲染表
- excel - 计数返回 0 的 Sumproduct
- mysql - 没有使用 spring boot 和 jpa 在多方关系中添加实体
- swift - 为什么 UITextView 滚动在 tvOS 上不起作用?
- c# - 如何通过 Bot Framework 向 Teams 中的用户发送通知?
- kubernetes - K8S Cron 作业从 config-map 读取环境特定值
- javascript - 使用 javascript 动态移动谷歌地图标记
- java - 有没有办法在 VS Code 中获取 Exclipse 的(tomcat-)服务器插件功能?(自动部署分解的 WAR 文件等。)