Dear Ravi,

Hope you are doing well.

The input should be like the below sample. We cannot keep column1 and column2 in dataset because it will also be taken as a value so the above should the dataset.

Dataset:
Value1 Value2
Value3 Value4

Code:
case class Demo(Column1: String, Column2: String ) 

val rdd = sc.textFile("file:///home/edureka/Desktop/myfile").map(_.split(" ")).map(x=>Demo(x(0),x(1))).toDF

rdd.toJSON.foreach(println)

Screenshot:

image


Please try and let us know if you face any issue.

We are eagerly waiting for your response.