Skip to content

Instantly share code, notes, and snippets.

@ruivieira
Created May 18, 2017 14:16
Show Gist options
  • Select an option

  • Save ruivieira/d3c6c18cc7c42d87c455512f4cc225b8 to your computer and use it in GitHub Desktop.

Select an option

Save ruivieira/d3c6c18cc7c42d87c455512f4cc225b8 to your computer and use it in GitHub Desktop.
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