2016-04-23 61 views
2

我想連接在數據幀兩個欄,如下一個專欄中,我要合併nameFirst和nameLast稱爲全名在火花蟒蛇一列如何連接兩個字符串列

+---------+---------+--------+ 
| playerID|nameFirst|nameLast| 
+---------+---------+--------+ 
|aardsda01| David| Aardsma| 
|aaronha01|  Hank| Aaron| 
|aaronto01| Tommie| Aaron| 
| aasedo01|  Don| Aase| 
+---------+---------+--------+ 

我想列驗證碼:

sqlContext.sql("SELECT playerID,(nameFirst+nameLast) as full_name FROM Master") 

但它返回

+---------+---------+ 
| playerID|full_name| 
+---------+---------+ 
|aardsda01|  null| 
|aaronha01|  null| 
|aaronto01|  null| 
| aasedo01|  null| 

任何幫助,請

回答

2

只需使用CONCAT功能:

sqlContext.sql("SELECT playerID, concat(nameFirst, nameLast) as full_name FROM Master")