How to add Postgres / Redshidt jdbc driver dependency to Zipplein

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add Postgres / Redshidt jdbc driver dependency to Zipplein

shahab
Hi,

I am quite new to Zeppelin. And I would like to query Redshift database using data frames.

I just wonder how I can add required JDBC driver to Zeppelin?Any example?

best,
/Shahab
Reply | Threaded
Open this post in threaded view
|

Re: How to add Postgres / Redshidt jdbc driver dependency to Zipplein

Antall Fernandes
This should help you out.

z.load("<path>/RedshiftJDBC41-1.1.2.0002.jar")
import org.apache.spark.sql.SQLContext
val host = sys.env("REDSHIFT_HOST")
val port = sys.env("REDSHIFT_PORT")
val username = sys.env("REDSHIFT_USERNAME")
val password = sys.env("REDSHIFT_PASSWORD")
val database = sys.env("REDSHIFT_DATABASE")
val url= List("jdbc:redshift://", host, ":", port, "/", database).mkString

val sqlSC = new SQLContext(sc)
val sql = "<query>"

val options = Map(
  "driver" -> "com.amazon.redshift.jdbc41.Driver",
  "user" -> username,
  "password" -> password,
  "url" -> url,
  "numPartitions" -> "5",
  "dbTable" -> List("(", sql, ") as dbTable").mkString
)

val result = sqlSC.read.format("jdbc").options(options).load()
result.show()

On Fri, Sep 18, 2015 at 5:11 AM, shahab <[hidden email]> wrote:
Hi,

I am quite new to Zeppelin. And I would like to query Redshift database using data frames.

I just wonder how I can add required JDBC driver to Zeppelin?Any example?

best,
/Shahab