How to use Spark-Scala to download a CSV file from the web?

后端 未结 2 602
抹茶落季
抹茶落季 2021-01-06 01:18

world,

How to use Spark-Scala to download a CSV file from the web and load the file into a spark-csv DataFrame?

Currently I depend on curl in a shell command

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-06 01:38

    val content = scala.io.Source.fromURL("http://ichart.finance.yahoo.com/table.csv?s=FB").mkString
    
    val list = content.split("\n").filter(_ != "")
    
    val rdd = sc.parallelize(list)
    
    val df = rdd.toDF
    

提交回复
热议问题