gpt4 book ai didi

scala - 如何将DataFrame写入MySQL表

转载 作者:行者123 更新时间:2023-12-03 07:07:19 26 4
gpt4 key购买 nike

很抱歉,如果这听起来很模糊,但可以解释一下将现有 DataFrame“df”写入 MySQL 表“product_mysql”的步骤,反之亦然。

最佳答案

请参阅this databricks article : Connecting to SQL Databases using JDBC.

import org.apache.spark.sql.SaveMode

val df = spark.table("...")
println(df.rdd.partitions.length)
// given the number of partitions above, users can reduce the partition value by calling coalesce() or increase it by calling repartition() to manage the number of connections.
df.repartition(10).write.mode(SaveMode.Append).jdbc(jdbcUrl, "product_mysql", connectionProperties)

关于scala - 如何将DataFrame写入MySQL表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47213167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com