Skip to content

Instantly share code, notes, and snippets.

@tues
Created November 19, 2016 02:13
Show Gist options
  • Save tues/22b1b4644fd40195bababb3e94e4aaa5 to your computer and use it in GitHub Desktop.
Save tues/22b1b4644fd40195bababb3e94e4aaa5 to your computer and use it in GitHub Desktop.
Minimal Spark + SnakeYAML test
name := "SparkSnakeYamlTest"
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0"
libraryDependencies += "org.yaml" % "snakeyaml" % "1.17"
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.Constructor
import scala.collection.mutable.ListBuffer
import scala.beans.BeanProperty
object Main {
class EmailAccount {
@scala.beans.BeanProperty var accountName: String = null
override def toString: String = {
return s"acct ($accountName)"
}
}
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("SparkSnakeYamlTest")
val sc = new SparkContext(conf)
val text = """accountName: Ymail Account"""
val yaml = new Yaml(new Constructor(classOf[EmailAccount]))
val e = yaml.load(text).asInstanceOf[EmailAccount]
println(e)
sc.stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment