4

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 - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
angela
  • 105
  • 1
  • 3
  • 12

1 Answers1

5

Just use concat function:

sqlContext.sql("SELECT playerID, concat(nameFirst, nameLast) as full_name FROM Master")
Vitalii Kotliarenko
  • 2,947
  • 18
  • 26