0
[error]  found   : Unit
[error]  required: Boolean
[error]  val value = values.split( " " ).filter(x => ( for(y <- x) { if(y!=""){ y}}) )

My input RDD is like

1 : 11111,22222
2 : 22224 4747

val lines1 = input2.map( line => line.split(":") )

val l1 = lines1.flatMap( arr => {
val key = arr( 0 )
val values = arr( 1 )
val value = values.split( " " ).filter(x => ( for(y <- x) { if(y!=""){ y}}) )

Any suggestions?

2
  • can you add input and expected output Commented Sep 20, 2017 at 2:24
  • Just a note that y!="" is y.nonEmpty. Commented Sep 20, 2017 at 13:34

2 Answers 2

1

filter method requires a boolean return type checking a condition but your filter method seems its not returning anything as for loop is just creating value variable without returning anything at the end of for loop which scala assumes to be unit.

According to my understanding to your question, you are trying to filter the empty values from the second array of numbers. So if my understanding is correct then you can use the following logic

val lines1 = input2.map( line => line.split(":") )

val l1 = lines1.flatMap( arr => {
  val key = arr(0).trim
  val values = arr(1).trim
  val value = values.split(" ").map(x => x.filter(y => y != ""))
  value
})
Sign up to request clarification or add additional context in comments.

Comments

0

A for will return a Unit as it has no inherent output. Maybe you want a for-comprehension, but you would need to yield the result. Although even then the output would be a Seq and not the expected Boolean. I am guessing you want to filter your values down to only those that have a value. Without knowing the types it seems you could just use a filter via filter(x=>x!="") or maybe flatMap via flatMap(x=>for{y<-x; y!=""}yield y) but we need more info for a complete answer at this time.

Comments

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.