1

I'm trying to convert Array[Row] to Array[Int] but in vain. Appreciate some help

scala> res17(0).toInt
<console>:30: error: value toInt is not a member of org.apache.spark.sql.Row
          res17(0).toInt
                   ^

scala> res17(0)
res28: org.apache.spark.sql.Row = [1,0]

scala> res17(0).toArray
<console>:30: error: value toArray is not a member of org.apache.spark.sql.Row
          res17(0).toArray
                   ^

scala> res17
res30: Array[org.apache.spark.sql.Row] = Array([1,0])
1
  • 1
    In general, this doesn't make sense. A Row can contain several entries which may not all be Int. What's in your Row? Commented Feb 8, 2016 at 17:00

1 Answer 1

7

Just map with getInt:

val rows: Array[Row] = ???
rows.map(_.getInt(0))
Sign up to request clarification or add additional context in comments.

1 Comment

Molecule_1 = tempMatrixRow.select("n1","n2","n3","n4","n5","n6","n7","n8","n9").filter($"index"===loopSize).map(_.getDouble(0)) . This is giving me the error error: missing parameter type for expanded function ((x$1) => x$1.getDouble(0))

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.