Created
November 19, 2016 02:13
-
-
Save tues/22b1b4644fd40195bababb3e94e4aaa5 to your computer and use it in GitHub Desktop.
Minimal Spark + SnakeYAML test
This file contains 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
name := "SparkSnakeYamlTest" | |
version := "1.0" | |
scalaVersion := "2.11.7" | |
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0" | |
libraryDependencies += "org.yaml" % "snakeyaml" % "1.17" |
This file contains 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.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
See http://stackoverflow.com/questions/38002883/snakeyaml-and-spark-results-in-an-inability-to-construct-objects/40688619#40688619