> For the complete documentation index, see [llms.txt](https://alvintoh.gitbook.io/apache-2-0-spark-with-scala/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alvintoh.gitbook.io/apache-2-0-spark-with-scala/section-3-spark-basics-and-simple-examples/9.-introduction-to-spark.md).

# 9. Introduction to Spark

## WHAT IS SPARK?

"A fast and general engine for large-scale data processing"

### It's Scalable

| Process Flow for Spark        |                              |                       |
| ----------------------------- | ---------------------------- | --------------------- |
|                               |                              | Executor -Cache Tasks |
| Driver Program -Spark Context | Cluster Manager (Spark,YARN) | Executor -Cache Tasks |
|                               |                              | Executor -Cache Tasks |

### It's Fast

* "Run programs up to 100x faster than Hadoop MapReduce in memory, or 10x faster on disk."
* DAG Engine (directed acyclic graph) optimizes workflows

### It's Hot

* Amazon
* Ebay: log analysis and aggregation
* NASA JPL: Deep Space Network
* Groupon
* TripAdviser
* Yahoo
* Many others: <https://cwiki.apache.org/confluence/display/SPARK/Powered+By+Spark>

### It's Not That Hard

* Code in Python, Java, or Scala
* Build around one main concept: the Resilient Distributed Dataset (RDD)

### Components Of Spark

| SPARK CORE      |           |        |        |
| --------------- | --------- | ------ | ------ |
| Spark Streaming | Spark SQL | MLLLib | GraphX |

### This Course Uses Scala

* Why Scala?
  * Spark itself is written in Scala
  * Scala's functional programming model is a good fit for distributed processing
  * Gives you fast performance (Scala compiles to Java bytecode)
  * Less code & boilerplate stuff than Java
  * Python is slow in comparison
* But...
  * You probably don't know Scala
  * So we'll have to learn the basics first.
  * It's not as hard you think!

### Fear Not

* Scala code in Spark looks a LOTlike Python code.
* Python code to square numbers in a data set:

  ```
    nums = sc.parallelize([1, 2, 3, 4])
    squared = nums.map[lambda x: x * x].collect()
  ```
* Scala code to square numbers in a data set:

  ```
    val nums = sc.parallelize(List(1, 2, 3, 4))
    val squared = nums.map(x -> x * x).collect()
  ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alvintoh.gitbook.io/apache-2-0-spark-with-scala/section-3-spark-basics-and-simple-examples/9.-introduction-to-spark.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
