Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Is their any way to configure new datbase for spark-sql in hdp 2.6

avatar
New Member

Will you please please help me to configure new database.


By default the spark-sql is connecting to the hive, so i want to configure new database like postgreSQL instead of hive


it will be very help full to rectify for me

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Vasanth Reddy

Spark SQL data source can read data from other databases using JDBC.JDBC connection properties such as user and password are normally provided as connection properties for logging into the data sources.

In the example below I am using MySQL, so will need to have the Postgres drivers in place

Sample Program

import org.apache.spark.sql.SQLContext
val sqlcontext = new org.apache.spark.sql.SQLContext(sc)
val dataframe_mysql = sqlcontext.read.format("jdbc").option("url", "jdbc:mysql://mbarara.com:3306/test").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "emp").option("user", "root").option("password", "welcome1").load()
dataframe_mysql.show()

Hope that helps

View solution in original post

2 REPLIES 2

avatar
Master Mentor

@Vasanth Reddy

Spark SQL data source can read data from other databases using JDBC.JDBC connection properties such as user and password are normally provided as connection properties for logging into the data sources.

In the example below I am using MySQL, so will need to have the Postgres drivers in place

Sample Program

import org.apache.spark.sql.SQLContext
val sqlcontext = new org.apache.spark.sql.SQLContext(sc)
val dataframe_mysql = sqlcontext.read.format("jdbc").option("url", "jdbc:mysql://mbarara.com:3306/test").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "emp").option("user", "root").option("password", "welcome1").load()
dataframe_mysql.show()

Hope that helps

avatar
New Member

@Geoffrey Shelton Okot Thanks a lot helping in this