首页 > 解决方案 > 在 Databricks 中解析嵌套的 XML

问题描述

我正在尝试 p

我正在尝试将 XML 读入数据框中,并尝试使用如下所示的 explode 来展平数据。

val df = spark.read.format("xml").option("rowTag","on").option("inferschema","true").load("filepath") val parsxml= df .withColumn("爆炸元素”,爆炸((“prgSvc.element”)))。

我收到以下错误。

command-5246708674960:4: error: type mismatch;
found   : String("prgSvc.element")
required: org.apache.spark.sql.Column
.withColumn("exploded_element", explode(("prgSvc.element")))**

Before reading the XML into the data frame, I also tried to manually assign a custom schema and read the XML file. But the output is all NULL. Could you please let me know if my approach is valid and how to resolve this issue and achieve the output.
Thank you.
    

标签: scalaapache-sparkapache-spark-sqlazure-databricks

解决方案


用这个

import spark.implicits._

val parsxml= df .withColumn("exploded_element", explode($"prgSvc.element"))

推荐阅读