Skip to content

Instantly share code, notes, and snippets.

@ioleo
Created October 12, 2016 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioleo/7d247ebf64ac84fb0ce85509f9cebf73 to your computer and use it in GitHub Desktop.
Save ioleo/7d247ebf64ac84fb0ce85509f9cebf73 to your computer and use it in GitHub Desktop.
Sparkathon @ Warsaw 2016-10-12
import org.apache.spark.sql.SparkSession
object Main extends App {
val spark = SparkSession.builder().master("local[*]").getOrCreate()
spark.experimental.extraOptimizations = Seq(MyRule)
import spark.implicits._
val numbersDS = Seq(0,1,2,3,4,5,6,7,8,9).toDS()
println(numbersDS.map(_+2).explain(true))
spark.stop()
}
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.rules._
import org.apache.spark.sql.types._
object MyRule extends Rule[LogicalPlan] with PredicateHelper {
def apply(plan: LogicalPlan): LogicalPlan = {
plan match {
case Filter(Literal(true, BooleanType), child) => {
println("I found a filter!!! yayaayaya!")
child
}
case _ => {
println("Anything else :P")
plan
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment