I am reading a large CSV file in Spark and I would like to parse each line using the CSVParser library (au.com.bytecode.opencsv.CSVParser)

Here is my code:

```
val parsedLines = sc.textFile("path/to/a/csv/file.csv").map(line => {
     val parser = new CSVParser(',')
     try{
       parser.parseLine(line)
     }catch{
       case e: Exception => "Error"
     }
})

```

The result of calling `parser.parseLine(line)` is an `Array[String]`.

I couldn't create the parser outside the map because the class CSVParser is not serializable.

Is it acceptable to call `new CSVParser(',')` inside the map function as I did in the code above?... if yes, why?... if no, why?

Does `new CSVParser(',')` being called for each element of the RDD?

Is there any more efficient way to do the same processing differently?