3

I want to concatenate two column in dataframe as one column here I want to merge nameFirst and nameLast as column called FULL Name

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

I'm trying this code :

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

but it returns

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

any help please

MaxU - stop genocide of UA
  • 191,778
  • 30
  • 340
  • 375
angela
  • 95
  • 1
  • 2
  • 12

1 Answers1

3

Just use concat function:

sqlContext.sql("SELECT playerID, concat(nameFirst, nameLast) as full_name FROM Master")
Vitalii Kotliarenko
  • 2,899
  • 17
  • 25