Program to load a text file into a Dataset in Spark using Java 8

Hey there!

Welcome to

In this post, we will look at a program to load a text file into a Dataset in Spark(2.3.0) using Java 8.

Check out the below classes/concepts before going through the program:

  • static org.apache.spark.sql.functions.col
  • org.apache.spark.sql.Dataset
  • org.apache.spark.sql.Row
  • org.apache.spark.sql.RowFactory
  • org.apache.spark.sql.types.DataTypes
  • org.apache.spark.sql.types.Metadata
  • org.apache.spark.sql.types.StructField
  • org.apache.spark.sql.types.StructType


Here is the Program:


Spark Submit Command:




Happy Learning :).

Please leave a reply in case of any queries.

Leave a Reply

Your email address will not be published. Required fields are marked *