scala解析databricks中的嵌套xml

qf9go6mv  于 2021-07-14  发布在  Spark
关注(0)|答案(1)|浏览(268)

我在试着做点什么
我试图将xml读入一个Dataframe,并尝试使用explode将数据展平,如下所示。
val df=spark.read.format(“xml”).option(“rowtag”,“on”).option(“inferschema”,“true”).load(“filepath”)val parsxml=df.withcolumn(“exploded\u element”,exploded((“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.
l7mqbcuq

l7mqbcuq1#

用这个

import spark.implicits._

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

相关问题