concept file in category spark

appears as: file, The file, files, files, file, The files
Spark in Action, Second Edition

This is an excerpt from Manning's book Spark in Action, Second Edition.

At t 2, the master tells the workers to load the file, as coded in listing 2.4. You may wonder, “If you have three workers, which one is loading the file?” or “If they load simultaneously, how do they know where to start and finish?” Spark will ingest the CSV file in a distributed way. The file must be on a shared drive, distributed filesystem (like HDFS in chapter 18), or shared via a shared filesystem mechanism such as Dropbox, Box, Nextcloud, or ownCloud. In this context, a partition is a dedicated area in the worker’s memory.

Listing 2.4 Reading the authors file
Dataset<Row> df = spark .read()
         .format( "csv" )
         .option( "header" , "true" )
 .load( "data/authors.csv" );

Let’s take a second to look at our CSV file (see listing 2.5). It is a simple file with two columns: lname for the last name, and fname for the first name. The first line of the file is a header. The file contains six more lines, which will become six rows in our dataframe.

Listing 2.5 A good ol’ CSV file
lname,fname
Pascal,Blaise
Voltaire,François
Perrin,Jean-Georges
Maréchal,Pierre Sylvain
Karau,Holden
 Zaharia,Matei

The workers will create tasks to read the file. Each worker has access to the node’s memory and will assign a memory partition to the task, as shown in figure 2.6.

$ mvn exec:java@generate-records-in-files
Figure 18.6 Spark’s workers must be able to access the data. The data can be in files, databases, or streams. Files can be problematic because they may be spread logically around organizations and physically around servers and clusters.