# Scan-based operations Apache Spark

Looking at the first paper on RDDs/Apache Spark, I found a statement saying that "RDDs degrade gracefully when there is not enough memory to store them, as long as they are only being used in scan-based operations"

What are scan-based operations in the context of RDDs and which of the Transformations in Spark are scan-based operations

## 1 Answer

Scan based operations are basically all the operations that require evaluating the predicate on an RDD.

In other terms, each time your create an RDD or a DataFrame in which you need to compute a predicate like performing a filter, map on a case class, per example, or even explain method will be considered as a scan based operation.

To be more clear, let's review the definition of a predicate.

A predicate or a functional predicate is a logical symbol that may be applied to an object term to produce another object term.

Functional predicates are also sometimes called mappings, but that term can have other meanings as well.

Example :

// scan based transformation
rdd.filter(!_.contains("#")) // here the predicate is !_.contains("#")

// another scan based transformation
rdd.filter(myfunc) // myfunc is a boolean function

// a third also trivial scan based transformation followed by a non scan based one.
rdd.map(myfunc2)
.reduce(myfunc3)


If you want to understand how spark internals work, I suggest that you watch the presentation made by Databricks about the topics

• That means that all Transformations in Spark are scan-based operations. Can you give some examples of Spark operations that aren't scan-based? – mbbce Oct 14 '15 at 6:08
• I didn't say that. What I said it that each time there is a predicate to calculate, the operation is scan based. – eliasah Oct 14 '15 at 6:32
• Ah, sorry, my bad. Can you kindly give an example of a transformation with predicate evaluation and one without it? I am (mostly) unfamiliar with Spark API atm and an example would help :) Thanks – mbbce Oct 14 '15 at 8:57
• @MB_CE I have edited the answer. Finding a non based transformation (not actions) example is actually quite tricky and difficult. – eliasah Oct 15 '15 at 15:39
• @eliasah what about methods like cache and unpersist? I don't think they count as transformations or actions, but they seem like an example of something that's not scan-based. – Matthew Graves Oct 15 '15 at 15:53