注意: Spark 2.3.x(EOL) 理论上也支持。但我们只对 Java 8 和 Java 11 做测试,Spark 自 3.0.0 起官方支持 Java 11。
// 自 2.4.0 起可用
compile "com.github.housepower:clickhouse-integration-spark_2.11:${clickhouse_native_jdbc_version}"
<!-- 自 2.4.0 起可用 -->
<dependency>
<groupId>com.github.housepower</groupId>
<artifactId>clickhouse-integration-spark_2.11</artifactId>
<version>${clickhouse-native-jdbc.version}</version>
</dependency>
请确保在使用前注册 ClickHouseDialect
JdbcDialects.registerDialect(ClickHouseDialect)
读取 ClickHouse 表数据到 DataFrame
val df = spark.read
.format("jdbc")
.option("driver", "com.github.housepower.jdbc.ClickHouseDriver")
.option("url", "jdbc:clickhouse://127.0.0.1:9000")
.option("user", "default")
.option("password", "")
.option("dbtable", "db.test_source")
.load
将 DataFrame 写入 ClickHouse 表 (支持 truncate table
)
df.write
.format("jdbc")
.mode("overwrite")
.option("driver", "com.github.housepower.jdbc.ClickHouseDriver")
.option("url", "jdbc:clickhouse://127.0.0.1:9000")
.option("user", "default")
.option("password", "")
.option("dbtable", "db.test_target")
.option("truncate", "true")
.option("batchsize", 10000)
.option("isolationLevel", "NONE")
.save
Can you improve this documentation? These fine people already did:
Cheng Pan & sundyliEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close