2
val keyValue = parsedData.map(x => (x.col1,x.col2,
  if(x.col3 = "a") "0.1" 
  else if(x.col3 = "b") "0.2" 
  else if(x.col3 = "c") "0.3" 
  else if(x.col3 = "d") "0.4"     
  else if(x.col3 = "e") "0.5"))

My parsedData rdd has 3 columns and for my third column i am trying to do the above, and you might have guessed its not working.

Any ideas how to implement this ?

5
  • 1
    What error are you getting? This looks valid to me. The only thing I notice is that you'll end up with a Unit type for the last column since you have no else Commented Oct 21, 2015 at 14:45
  • what's the type of x ? Commented Oct 21, 2015 at 14:47
  • Its saying expression of type unit doesn't conform to expected type boolean. parsedData has data like (1,2,a),(2,3,b),(3,4,c) Commented Oct 21, 2015 at 14:54
  • still doesn't answer my question, what is the type of x? can you run :type parsedData if you are using spark-shell? Commented Oct 21, 2015 at 14:58
  • its an rdd, I am not sure if I am missing something .. Commented Oct 21, 2015 at 15:08

1 Answer 1

1

There are a couple of problems:

  1. You should be using == instead of =
  2. You need an else or else your type for the 3rd item will be Unit...but that will still compile. Worst case, you should maybe use an Option?
Sign up to request clarification or add additional context in comments.

1 Comment

You could also use a match to be more concise. x.col3 match { case "a" => "0.1" case "b" => "0.2" ... }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.