How to declare an empty dataset in Spark?

Viewed 17042

I am new in Spark and Spark dataset. I was trying to declare an empty dataset using emptyDataset but it was asking for org.apache.spark.sql.Encoder. The data type I am using for the dataset is an object of case class Tp(s1: String, s2: String, s3: String).

3 Answers

Alternatively you can convert an empty list into a Dataset:

import sparkSession.implicits._

case class Employee(name: String, id: Int)

val ds: Dataset[Employee] = List.empty[Employee].toDS()
Related