0
我目前使用的Spark和Scala 2.11.8阵列字符串来
斯卡拉+星火结构的阵列我有以下模式:
root
|-- partnumber: string (nullable = true)
|-- brandlabel: string (nullable = true)
|-- availabledate: string (nullable = true)
|-- descriptions: array (nullable = true)
|-- |-- element: string (containsNull = true)
我试图使用UDF将其转换以下几点:
root
|-- partnumber: string (nullable = true)
|-- brandlabel: string (nullable = true)
|-- availabledate: string (nullable = true)
|-- description: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- value: string (nullable = true)
| | |-- code: string (nullable = true)
| | |-- cost: int(nullable = true)
所以源数据是这样的:
[WrappedArray(a abc 100,b abc 300)]
[WrappedArray(c abc 400)]
我需要使用“”(空格)作为分隔符,但不知道如何在scala中执行此操作。
def convert(product: Seq[String]): Seq[Row] = {
??/
}
我是相当新的斯卡拉,所以有人可以指导我如何构建这种类型的功能?
谢谢。
谢谢你的快速回复。我试图实现你的建议,但它是说“无法解决符号拆分”我应该使用不同的方法吗? – SuWon
[String.split](http://www.scala-lang.org/api/2.12.x/scala/collection/immutable/StringOps.html#split(separator:Char):Array [String])是一种方法为字符串。我不知道你的包装数组是什么类型。也许你必须在每个值上调用toString来获得一个字符串。 val split = s.toString.split(“”) –
谢谢。我能够在你的帮助下解决这个问题。 – SuWon