How to create a DataFrame from a text file in Spark

后端 未结 8 1200
滥情空心
滥情空心 2021-01-31 19:03

I have a text file on HDFS and I want to convert it to a Data Frame in Spark.

I am using the Spark Context to load the file and then try to generate individual columns f

8条回答
  •  天命终不由人
    2021-01-31 19:47

    I know I am quite late to answer this but I have come up with a different answer:

    val rdd = sc.textFile("/home/training/mydata/file.txt")
    
    val text = rdd.map(lines=lines.split(",")).map(arrays=>(ararys(0),arrays(1))).toDF("id","name").show 
    

提交回复
热议问题