1 / 9

Scala/Spark Review

6/13/2014 Redo Week 1 First Scala Course/Demo Scalatestest Spray Can (in JobServer)/sbt. Scala/Spark Review. Recursion. 3 exercises on Recursion Point is: to use matching as replacement for loops Very few if/then statements in proper Scala code Example: Factorial w/wo if then.

jolie
Télécharger la présentation

Scala/Spark Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 6/13/2014 Redo Week 1 First Scala Course/Demo Scalatestest Spray Can (in JobServer)/sbt Scala/Spark Review

  2. Recursion • 3 exercises on Recursion • Point is: • to use matching as replacement for loops • Very few if/then statements in proper Scala code • Example: • Factorial w/wo if then

  3. Factorial factorial(n:Int):Int={ if(n==0) 1 else n*factorial(n-1) }

  4. Factorial with match def factorial(n:Int):Int = n match{ case 0 => 1 case _ => n*factorial(n-1) }

  5. codingbat examples • http://codingbat.com/java/Recursion-1 ,recursion 2 • Doesn't cover backtracking • Doesn't exists for scala, copy and paste questions and code up solns in unit test. Add maven artifact/scalatest

  6. Maven/Scalatest • Disable surefire tests. Have to add the Java unit tests separately. HW uses @RunWith(classOf[JUnitRunner]) <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.7</version> <configuration> <skipTests>true</skipTests> </configuration>

  7. Demo • > cd TestScalatest ; mvn test • Some strange looking patterns: • Either do nested case statement or mixed if/case statements. Can't put conditionals in case () • case _ => if (n<10 && n==7) 1 else if(n<10 && n!=7) 0 else if ((n%10)==7) 1+count7(n/10) else count7(n/10)

  8. SprayCan • Scala server. • Akka-io config, jetty config (servlets) • Used in spark-job-server from Ooyala • Sbt; • build.sbt or scala code. Build.sbt specify k/v pairs for config map • Job-server doesn't use build.sbt. Replace with scala code/sbt api • No blank lines in sbt.build at top; uses for delimiters. Opposite of xml

  9. Spray Resources • SprayExamples from github • Add build.sbt, plugins.sbt • Doesn't exist in SprayExamples • Match akka with spray-can versions java.lang.NoSuchMethodError: akka.actor.Props$.apply(Lscala/Function0;Lscala/reflect/ClassTag;)Lakka/actor/Props; at spray.can.HttpExt.<init>(Http.scala:153)

More Related