How do I read a large CSV file with Scala Stream class?

后端 未结 3 1224
野的像风
野的像风 2020-12-01 05:02

How do I read a large CSV file (> 1 Gb) with a Scala Stream? Do you have a code example? Or would you use a different way to read a large CSV file without loading it into me

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 05:42

    Just use Source.fromFile(...).getLines as you already stated.

    That returns an Iterator, which is already lazy (You'd use stream as a lazy collection where you wanted previously retrieved values to be memoized, so you can read them again)

    If you're getting memory problems, then the problem will lie in what you're doing after getLines. Any operation like toList, which forces a strict collection, will cause the problem.

提交回复
热议问题