1290 1290 - 3 months ago 50
Scala Question

FlatMap Traversable Ones Error

I have this code below:

//TABLE FROM HIve
val df = hiveContext.sql("select * from test_table where date ='20160721' LIMIT 300")
//ERROR ON THE LINE BELOW
val row = df.flatMap(row => ((row.get(0), row.get(1), row.get(2)), 1))


I get this error in the code above saying:

Type mismatch, expected: (Row) => Traversable[NotInferedU], actual : (Row) => ((Any, Any, Any), Int)


Can someone check to see what is wrong in my flatMap function. I am not able to understand what this error is stating.

Answer

you probably should use map instead. ((row.get(0), row.get(1), row.get(2)), 1) is not a Traversable as the error message stated.