JDBC call to impala / hive from a spark job and table creation

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

How should I do it? Any example would be very helpful. Thank!

+2
source share
1 answer
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)
+13
source

Source: https://habr.com/ru/post/1654070/


All Articles