您现在的位置是:首页 > 文章详情

spark 通过 jdbc 写入 clickhouse 需要注意的点

日期:2019-07-27点击:2686

最近在用 spark 通过 jdbc 写入 clickhouse 的时候,遇到一些坑,这里分享下,造福人民群众。

一个 WARN

WARN JdbcUtils: Requested isolation level 1, but transactions are unsupported 

这是因为 clickhouse 不支持事务造成的,解决方案,jdbc 加入 isolationLevel 等于 NONE 的选项,isolationLevel 详解

The transaction isolation level, which applies to current connection. It can be one of NONE, READ_COMMITTED, READ_UNCOMMITTED, REPEATABLE_READ, or SERIALIZABLE, corresponding to standard transaction isolation levels defined by JDBC's Connection object, with default of READ_UNCOMMITTED. This option applies only to writing. Please refer the documentation in java.sql.Connection.

一个报错

merges are processing significantly slower than inserts 

这是因为 spark 多个 partition 同时并发写引发的错误,解决方案 jdbc 加入 numPartitions 等于 1 的选项控制并发数,numPartitions 详解

The maximum number of partitions that can be used for parallelism in table reading and writing. This also determines the maximum number of concurrent JDBC connections. If the number of partitions to write exceeds this limit, we decrease it to this limit by calling coalesce(numPartitions) before writing.

完整 scala 代码

 spark.createDataFrame(data) .write .mode(SaveMode.Append) .option("batchsize", "50000") .option("isolationLevel", "NONE") // 设置事务 .option("numPartitions", "1") // 设置并发 .jdbc(dbUrl, "table", dbProp) 

更多 spark jdbc 选项,参考 spark 官方文档 更多架构、PHP、GO相关踩坑实践技巧请关注我的公众号

原文链接:https://my.oschina.net/u/222608/blog/3080008
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章