concept record in category spark

appears as: record, records, records, record, The records, The record
Spark in Action, Second Edition

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

Figure 2.7 shows the record being copied from the CSV file to the partition during the ingestion process, within the R > P (Record to Partition) box. The Memory box shows which records are in which partition. In this example, record 1, which contains Blaise Pascal , is in the first partition of the first worker.

Figure 2.7 As the ingestion is taking place, each task loads records into its own memory partition, as indicated by the R > P (Record to Partition) box. The partition box contains the records after the ingestion has been completed.
Figure 2.6 The tasks are being created based on available resources. The worker may create several tasks and will assign a memory partition to each task. The solid tasks are running (they also have a dot), to contrast with nonworking tasks (from another application, for example), which are hollow and have a triangle.

In this scenario, you are going to run two applications. The order in which you start the application does not matter for file streams. One application will produce the stream, which contains records describing people. The other application will use Spark to consume the generated stream. You will start with the data generator and then build the consumer. Figure 10.3 illustrates the process.

Figure 10.3 In this streaming scenario, one application (the generator) generates records in a file and places those files in a folder. A Spark application (the consumer) reads the files in that folder and displays the data.

The record ingestion application, shown in listing 10.8, is a bit different from the raw line ingestion application from listing 10.5. You will have to tell Spark that you want records and specify the schema.

Listing 10.8 ReadRecordFromFileStreamApp.java
...
      SparkSession spark = SparkSession.builder()
            .appName( "Read records from a file stream" )
            .master( "local" )
            .getOrCreate();
 
       StructType recordSchema = new StructType () #1
            .add( "fname" , "string" )
            .add( "mname" , "string" )
            .add( "lname" , "string" )
            .add( "age" , "integer" )
            .add( "ssn" , "string" );
 
      Dataset<Row> df = spark
            .readStream()
            .format( "csv" ) #2
            .schema( recordSchema ) #3
            .load(StreamingUtils.getInputDirectory());
 
      StreamingQuery query = df
            .writeStream()
            .outputMode(OutputMode.Append())
            .format( "console" )
             .start();