2014 holden - databricks umd scala crash course

100 %
0 %
Information about 2014 holden - databricks umd scala crash course
Technology

Published on October 20, 2014

Author: hkarau

Source: slideshare.net

Description

A quick crash course on Scala before diving into Spark's scala shell

1. SCALA CRASH COURSE Holden Karau - @holdenkarau

2. Scala vs Java API vs Python Spark was originally written in Scala, which allows concise function syntax and interactive use Java API added for standalone applications Python API added more recently along with an interactive shell. This course: mostly Scala, some translations shown to Java & Python

3. Outline Introduction to Scala & functional programming A picture of a cat Coffee Break* *The coffee break may or may not be a lie.

4. Introduction to Scala What is Scala? Functions in Scala Operating on collections in Scala

5. About Scala High-level language for the JVM ● Object oriented + functional programming Statically typed ● Comparable in speed to Java* ● Type inference saves us from having to write explicit types most of the time Interoperates with Java ● Can use any Java class (inherit from, etc.) ● Can be called from Java code

6. Best way to Learn Scala Interactive scala shell (just type scala) Supports importing libraries, tab completing, and all of the constructs in the language http://www.scala-lang.org/

7. Quick Tour of Scala Declaring variables: var x: Int = 7 var x = 7 // type inferred val y = “hi” // read-only Functions: def square(x: Int): Int = x*x def square(x: Int): Int = { x*x } def announce(text: String) = { println(text) } Java equivalent: int x = 7; final String y = “hi”; Java equivalent: int square(int x) { return x*x; } void announce(String text) { System.out.println(text); }

8. Scala functions (closures) (x: Int) => x + 2 // full version

9. Scala functions (closures) (x: Int) => x + 2 // full version x => x + 2 // type inferred

10. Scala functions (closures) (x: Int) => x + 2 // full version x => x + 2 // type inferred _ + 2 // placeholder syntax (each argument must be used exactly once)

11. Scala functions (closures) (x: Int) => x + 2 // full version x => x + 2 // type inferred _ + 2 // placeholder syntax (each argument must be used exactly once) x => { // body is a block of code val numberToAdd = 2 x + numberToAdd }

12. Scala functions (closures) (x: Int) => x + 2 // full version x => x + 2 // type inferred _ + 2 // placeholder syntax (each argument must be used exactly once) x => { // body is a block of code val numberToAdd = 2 x + numberToAdd } // Regular functions def addTwo(x: Int): Int = x + 2

13. Quick Tour of Scala Part 2 (electric boogaloo) Processing collections with functional programming val lst = List(1, 2, 3) list.foreach(x => println(x)) // prints 1, 2, 3 list.foreach(println) // same list.map(x => x + 2) // returns a new List(3, 4, 5) list.map(_ + 2) // same list.filter(x => x % 2 == 1)// returns a new List(1, 3) list.filter(_ % 2 == 1) // same list.reduce((x, y) => x + y) // => 6 list.reduce(_ + _) // same All of these leave the list unchanged as it is immutable.

14. Functional methods on collections There are a lot of methods on Scala collections, just google Scala Seq or http://www.scala-lang.org/api/2. 10.4/index.html#scala.collection.Seq Method on Seq[T] Explanation map(f: T => U): Seq[U] Each element is result of f flatMap(f: T => Seq[U]): Seq[U] One to many map filter(f: T => Boolean): Seq[T] Keep elements passing f exists(f: T => Boolean): Boolean True if one element passes f forall(f: T => Boolean): Boolean True if all elements pass reduce(f: (T, T) => T): T Merge elements using f groupBy(f: T => K): Map[K, List[T]] Group elements by f sortBy(f: T => K): Seq[T] Sort elements …..

15. Cat picture from http://galato901.deviantart.com/art/Cat-on-Work-Break-173043455

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Intro to Apache Spark - Databricks

Scala Crash Course Holden Karau ... slides/day1_Scala_crash_course.pdf ... databricks.com/blog/2014/09/25/guavus-embeds-apache-spark-
Read more

Spark Tutorial

Crash course in Scala (Holden Karau) ... Spark Streaming; MLlib; Databricks Cloud Demo ... Full house at the UMD Spark Tutorial!
Read more

Scary Moment RC Starfighter F-104 on Crash Course - YouTube

Scary Moment RC Starfighter F-104 on Crash Course ... WESTON PARK 2014 ... * GIANT RC SCALE * 85% PITTS PYTHON BIPLANE CRASH * HD ...
Read more

V8 Supercars - Wikipedia, the free encyclopedia

... leaving these open solely to the 5.0-litre Ford and Holden models. V8 Supercars ... in the event of a crash. ... 2014, V8 Supercars released details ...
Read more

Welcome to Rmetrics | Rmetrics

2014 Zurich Crash Course; ... R Crash Course. Zurich, 26 February 2015, ... Chronological Objects with R/Rmetrics, ...
Read more

Carson SPECTER 6S X8EB - First Run (?) - DOUBLE CRASH ...

... 2014. Sollte das erste ... 6S Brushless Reifen Wheels Kill Carson Specter 6S Lipo Mamba Monster Burnout Wheelies Crash ... 2013 Short Course ...
Read more

John Green (author) - Wikipedia, the free encyclopedia

... VidCon and created a total of 11 online series including Crash Course, ... John Green presents "The List Show" in which he lists off ... (2014) An ...
Read more

The University of Maryland :: A Public Research University ...

Click here to view other UMD calendars. ... 2014 T32 Neuroscience & Addictions Conference August ... Learning Technologies Institute Course Design and ...
Read more