将 Spark 数据集列从 UDT 转换为数组<String>

问题描述 投票:0回答:0

我正在使用 Spark OrientDB 连接器来检索一些如下所示的数据:

性格 标题
托尼·史塔克 [“钢铁侠”]
詹姆斯·布坎南·巴恩斯 [《美国队长:复仇者先锋》、《美国队长:冬日战士》、《美国队长:内战》、《复仇者联盟:无限战争》]
马库斯·布莱索 [《美国队长:冬兵》]

数据框将其返回为

[character: string, title: embeddedlist]
EmbeddedList
是定义于 here

的 UDT

我想将

title
视为
Array<String>
,以便我可以执行以下操作:

    val vertices = df
      .select(explode(concat(array('character), 'title)) as "x")
      .distinct.rdd.map(_.getAs[String](0))
      .zipWithIndex.map(_.swap)

我不确定如何正确投射/转换

EmbeddedList
。按原样运行会导致错误:
cannot resolve 'concat(array(name), out)' due to data type mismatch: input to function concat should have been string, binary or array, but it's [array<string>, array<string>]

任何帮助/指示表示赞赏。

scala apache-spark apache-spark-sql orientdb apache-spark-dataset
© www.soinside.com 2019 - 2024. All rights reserved.