如何将spark输出存储到rdbms数据库



我最近开始使用spark,我有一个用例,我需要处理文件并存储postgre数据库的输出。我能够读取文件并处理它,我不能将处理过的数据存储到数据库。有人能建议我如何保存输出到db吗?

谢谢…

如果数据库可以从所有工作节点访问,则可以使用foreachPartition保存输出。伪代码:

rdd.foreachPartition { records =>
  // Connect to the database 
  records.foreach { r => 
    // Loop over records and save
  }
  // Close the connection to the db
}

最新更新