Apache Spark is a powerful open-source distributed data processing engine, widely recognized for its capability to perform real-time data analytics at scale. A significant aspect of learning Spark is understanding its programming model through example codes. Let's delve into a couple of practical examples that illustrate Spark's functionality and demonstrate how to write Spark code.

Spark provides four primary modes of computation: map, filter, reduce, and flatMap. These operations are akin to the functional programming concepts you might encounter in languages like Scala or Java. Let's explore two basic but insightful examples based on these operations.

Data Processing with Spark
Let's start with a simple word count example, a common use case when learning data processing frameworks like Spark. We'll use an RDD (Resilient Distributed Dataset), Spark's fundamental data structure.

An RDD is immutable, partitioned collection of records, and can be created from Hadoop InputFormat (like HDFS files) or from existing Scala/Java collections. Here's a simple word count example:
Word Count using Map and Reduce

We start by creating an RDD from an array of strings. Then we apply the map operation to convert the array of strings into pairs of words and 1. The reduceByKey operation sums up the counts for each word.
```Scala val input = Array("hello world", "Hello, Spark") val rdd = sc.parallelize(input) val wordCount = rdd.flatMap(line => line.split(" ")) .map(word => (word, 1)) .reduceByKey(_ + _) ```
Word Count using FlatMap and ReduceByKey
Instead of using map and then reduceByKey as above, we can combine these operations into a single flatMap operation for more concise code.

```Scala val wordCount = rdd.flatMap(line => line.split(" ").map(word => (word, 1))) .reduceByKey(_ + _) ```









