如何将spark流输出推送到oracle

x4shl7ld  于 2021-06-03  发布在  Sqoop
关注(0)|答案(1)|浏览(293)

我有一个spark流程序,可以在15分钟内聚合和处理数据​. 需要将其输出推送到oracle表中。
最好的方法是什么?
如果我将数据写入hive,然后使用sqoop将其推送到oracle,那么我将不得不以一定的频率安排sqoop作业,sqoop应该知道它以前从hive中提取了什么数据,现在应该从hive中提取什么delta。我不确定sqoop能否做到这一点。
你有什么建议?
谢谢您。

hrirmatl

hrirmatl1#

您也可以在spark示例中连接到oracle db:

r2.foreachPartition {
it =>
    val conn= DriverManager.getConnection(url,username,password)
    val del = conn.prepareStatement ("INSERT INTO tweets (ID,Text) VALUES (?,?) ")
    for (bookTitle <-it)
     {
          del.setString(1,bookTitle.toString)
          del.setString(2,"my input")
          del.executeUpdate
    }
}

OR

val employees = sqlContext.load("jdbc", Map("url" -> "jdbc:oracle:thin:user/pass@//localhost:1521/single", "dbtable" -> "hr.employees"))

相关问题