Skip to content

Instantly share code, notes, and snippets.

@zero323
Last active March 21, 2016 16:21
Show Gist options
  • Save zero323/ef66ef6ad25d6fe9b501 to your computer and use it in GitHub Desktop.
Save zero323/ef66ef6ad25d6fe9b501 to your computer and use it in GitHub Desktop.
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "1.6.1",
"org.apache.spark" %% "spark-sql" % "1.6.1"
)
import org.apache.spark._
import org.apache.spark.sql._
import scala.util.Try
case class Dummy()
object App {
def main(args: Array[String]) {
val sc = new SparkContext("local", "foo", new SparkConf())
val sqlContext = new SQLContext(sc)
val df = sqlContext.read.json(sc.parallelize(Seq("""{"a": [1, 2, 3]}""")))
val optionA = Option(df.first.getAs[Dummy]("a")) // No exception
require(Try(optionA.map(identity)).isFailure)
sc.stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment