I operate with Spark 1.5, using Java. I need to append ID/Index column to existing DataFrame, for example:
+---------+--------+
| surname| name|
+---------+--------+
| Green| Jake|
| Anderson| Thomas|
| Corleone| Michael|
| Marsh| Randy|
| Montana| Tony|
| Green| Julia|
|Brenneman| Eady|
| Durden| Tyler|
| Corleone| Vito|
| Madiro| Mat|
+---------+--------+
I want every row to be appended with index, in range between between 1 and table records amount. Index order does not matter, any row must just contain unique ID/index. It could be done by transformation into RDD and appending index row and transformation into DataFrame with modified StructType, but, If I understand correctly, this operation consumes a lot of resources for transformation etc., and there must be another way. Result must be like:
+---------+--------+---+
| surname| name| id|
+---------+--------+---+
| Green| Jake| 3|
| Anderson| Thomas| 5|
| Corleone| Michael| 2|
| Marsh| Randy| 10|
| Montana| Tony| 7|
| Green| Julia| 1|
|Brenneman| Eady| 2|
| Durden| Tyler| 9|
| Corleone| Vito| 4|
| Madiro| Mat| 6|
+---------+--------+---+
Thank you.