Created
May 18, 2017 14:16
-
-
Save ruivieira/d3c6c18cc7c42d87c455512f4cc225b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.apache.spark.SparkConf | |
| import org.apache.spark.api.java.JavaSparkContext | |
| import kotlin.reflect.KClass | |
| fun main(args: Array<String>) { | |
| val conf = SparkConf() | |
| .setMaster("local") | |
| .setAppName("Kotlin Spark Test") | |
| val sc = JavaSparkContext(conf) | |
| val items = listOf("123/643/7563/2134/ALPHA", "2343/6356/BETA/2342/12", "23423/656/343") | |
| val input = sc.parallelize(items) | |
| val sumOfNumbers = input.flatMap { it.split("/") } | |
| .filter { it.matches(Regex("[0-9]+")) } | |
| .map { it.toInt() } | |
| .reduce {total,next -> total + next } | |
| println(sumOfNumbers) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment