score:4

Accepted answer

each entry in the rdd is a string. so comparing it to "name" will always fail, as it's "name"+some digits.

what you need is map to iterate over the rdd and return a new value for each entry. and that new value should be the string, without the first 4 characters, and converted to long.

putting that all together, we get

name.map(_.drop(4).tolong)

if you don't know the first four characters will be "name", you might want to check that first. what you need then depends on what you want to do with rows that don't have name as the first four, but something like

name.filter(_.startswith("name")).map(_.drop(4).tolong)

score:3

the method stripprefix will remove a given prefix from a string (and do nothing if the string does not start with that prefix.

so you achieve what you need by:

val name_clean = name.map(_.stripprefix("name").tolong)

Related Query