使用 Apache Spark 1.6 在 PostgreSQL 9.6 上以批处理模式插入 [英] Insert in batch mode on PostgreSQL 9.6 with Apache Spark 1.6

查看:23
本文介绍了使用 Apache Spark 1.6 在 PostgreSQL 9.6 上以批处理模式插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拜托,有一个配置或参数可以做到这一点:

Please, there is a configuration or params to do this:

dataFrame.write.mode(saveMode).jdbc(url, "tablename", new java.util.Properties())

命令是用 Scala 编写的,Apache Spark 1.6

Command is written in Scala, Apache Spark 1.6

这需要一个 DataFrame 并一行一行地在 PostgreSQL 中插入数据.我们需要在批处理模式下执行此操作.

That takes a DataFrame and inserts data in PostgreSQL row by row, one by one. We need to do this in batch mode.

有谁知道是否存在任何配置或其他方式来实现?

Anyone knows if exists any configuration or another way to accomplish that?

提前致谢

推荐答案

根据文档 - link - 您可以使用 batchsize 参数批量执行插入

According to documentation - link - you can use batchsize parameter to perform inserts in batches

dataFrame
    .write
    .mode(saveMode)
    .option("batchsize", 1000)
    .jdbc(url, "tablename", new java.util.Properties())

现在插入将分批执行 1000 行

Now insert will be perfomed in batches of 1000 rows

这篇关于使用 Apache Spark 1.6 在 PostgreSQL 9.6 上以批处理模式插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆