2017-09-06 91 views
0

我的模式如下:火花階從列表中創建的地圖在數據幀

root 
    |-- id: string (nullable = true) 
    |-- info: array (nullable = true) 
    | |-- element: struct (containsNull = true) 
    | | |-- _1: string (nullable = true) 
    | | |-- _2: long (nullable = false) 
    | | |-- _3: string (nullable = true) 

我想要的O/P爲:

id | info 
    111|[{aaa:{12,abc}},{xxx:{14,def}}] 
    222|[{ddd:{23,fgh}},{jjj:{13,ijk}}] 
    333|[{aaa:{96,wer}] 

請幫

+0

你可以共享你的數據框架嗎? –

+0

我會分享你。信息是結構數組。我認爲該數組的第一個字段(info._1是關鍵和剩餘的值)基本上是關鍵值對 – gayathri

+0

嗨Ramesh,我已更新模式 – gayathri

回答

0

看來,您的「信息」字段包含一個列表,並且您希望將每個列表的第一個元素設置爲該列表的關鍵字。

也許嘗試:

dataset.map(row => row.getAs[Seq[Row]]("info") 
      .map(list => Map (list.head, list.tail))) 

我是新來斯卡拉過。由於我不知道你的特定模式,上面的代碼可能無法按預期工作。希望這是有幫助的。