Edamame
Edamame

Reputation: 25366

Spark Scala: value add is not a member of scala.collection.mutable.ListBuffer

Below is my code, trying to add a data frame row to a list, then return it in a tuple.

import scala.collection.mutable.ListBuffer

myDF.rdd.filter{row:Row => row.getString(6).length > 0}.map {
  row: Row => 
  var rowList: ListBuffer[Row] = ListBuffer()
  rowList.add(row)
  (row.getString(1) + "_" + row.getString(2) + "_" + row.getString(6) + "_" + row.getString(7) + "_" + row.getString(14), rowList)
}.count()

Then I got the following error:

 error: value add is not a member of scala.collection.mutable.ListBuffer[org.apache.spark.sql.Row]
                rowList.add(row)

Does anyone know what I did wrong here? Thanks!

Upvotes: 2

Views: 2068

Answers (2)

BugsBunny
BugsBunny

Reputation: 99

use += in ListBuffer: rowList += row

Upvotes: 3

Edamame
Edamame

Reputation: 25366

add is not the standard ListBuffer API. Just need to import the following line:

import scala.collection.JavaConversions._

Upvotes: 1

Related Questions