spark 通过 jdbc 写入 clickhouse 需要注意的点
最近在用 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
相关推荐
-
布隆过滤器你值得拥有的开发利器 Java基础
2020-6-14
-
学习排序算法,结合这个方法太容易理解了 Java基础
2019-7-26
-
Java 8 Stream Api 中的 peek 操作 Java基础
2020-5-28
-
聊聊ReentrantLock的内部实现 Java基础
2019-5-22
-
oracle 合并多个sys_refcursor Java基础
2019-9-11
-
微信扫码支付(模式二) Java基础
2020-5-30
-
【设计模式】观察者模式 Java基础
2019-3-19
-
F版本SpringCloud 5—Eureka集群和自我保护机制 Java基础
2020-6-13
-
ReentrantLock是如何基于AQS实现的 Java基础
2019-5-13
-
记一次自动恢复的支付故障 Java基础
2019-6-2