Calling JDBC to impala/hive from within a spark job and creating a table

11,833
val JDBCDriver = "com.cloudera.impala.jdbc41.Driver"
val ConnectionURL = "jdbc:impala://url.server.net:21050/default;auth=noSasl"

Class.forName(JDBCDriver).newInstance
val con = DriverManager.getConnection(ConnectionURL)
val stmt = con.createStatement()
val rs = stmt.executeQuery(query)

val resultSetList = Iterator.continually((rs.next(), rs)).takeWhile(_._1).map(r => {
    getRowFromResultSet(r._2) // (ResultSet) => (spark.sql.Row)
}).toList

sc.parallelize(resultSetList)
Share:
11,833
user1189851
Author by

user1189851

Updated on July 27, 2022

Comments

  • user1189851
    user1189851 almost 2 years

    I am trying to write a spark job in scala that would open a jdbc connection with Impala and let me create a table and perform other operations.

    How do I do this? Any example would be of great help. Thank you!