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