Last active
June 16, 2016 12:39
-
-
Save geowa4/a9bc238ca7c372b95267 to your computer and use it in GitHub Desktop.
Testing Spark SQL with Postgres data source
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
Exception in thread "main" java.lang.ClassNotFoundException: org.postgresql.Driver | |
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) | |
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) | |
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) | |
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) | |
at java.lang.Class.forName0(Native Method) | |
at java.lang.Class.forName(Class.java:264) | |
at org.apache.spark.sql.jdbc.DefaultSource.createRelation(JDBCRelation.scala:102) | |
at org.apache.spark.sql.sources.ResolvedDataSource$.apply(ddl.scala:219) | |
at org.apache.spark.sql.SQLContext.load(SQLContext.scala:697) | |
at SimpleApp$.main(SimpleApp.scala:17) | |
at SimpleApp.main(SimpleApp.scala) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:497) | |
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:569) | |
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:166) | |
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:189) | |
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:110) | |
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) |
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
name := "simple-project" | |
version := "1.0" | |
scalaVersion := "2.11.6" | |
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.3.1" % "provided" | |
libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.3.1" % "provided" | |
libraryDependencies += "org.postgresql" % "postgresql" % "9.4-1201-jdbc41" |
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.SparkContext | |
import org.apache.spark.SparkContext._ | |
import org.apache.spark.SparkConf | |
import org.apache.spark.sql.SQLContext | |
object SimpleApp { | |
def main(args: Array[String]) { | |
val conf = new SparkConf().setAppName("Simple Application") | |
val sc = new SparkContext(conf) | |
val sqlContext = new SQLContext(sc) | |
import sqlContext.implicits._ | |
val commits = sqlContext.load("jdbc", Map( | |
"url" -> "jdbc:postgresql://192.168.59.103:5432/postgres", | |
"dbtable" -> "commits", | |
"driver" -> "org.postgresql.Driver")) | |
commits.select("message").show(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment