I am converting list of strings to list of BigDecimal values in below scala code. But when queryResults list is very large (> 10 million), I'm getting below error.
We have some limitations on memory usage and cannot increase memory. Is there any way to handle this error, without increasing memory size?
This is the error I am getting
java.lang.OutOfMemoryError: Java heap space
at scala.Option.toList(Option.scala:301)
at scala.Option$.option2Iterable(Option.scala:17)
Code:
val queryResults = List("11", "test", "444", "22", "33", "44", "1111", "2222", "3333", "4444")
//getting error at below line
val z = queryResults.flatMap(idPath => Try(idPath.toLong).toOption).map(BigDecimal.valueOf)