【问题标题】:DataFrame numPartitions default valueDataFrame numPartitions 默认值
【发布时间】:2020-07-09 12:18:20
【问题描述】:

我正在尝试使用 JDBC 从数据库表中读取内容:

val df = spark.read.jdbc("<database url>", "<some table name>", <some DbProperties>)

然后将其写入另一个数据库:

df.write.mode(SaveMode.Append).jdbc("<other database url>", "<same table name>", <some DbProperties>)
  1. 如果我们没有在 Db 属性中指定 numPartitions 选项,那么 numPartitions Spark 用于将表从数据库读取到 df 的默认值是多少?
  2. 如果我想将上面的df写入另一个数据库的另一个表中,如果我仍然不指定numPartitions,写入数据库时​​是否会创建并行连接?
  3. 假设在阅读时我将 numPartitions 设为 8,而在将此 df 写入目标数据库时,如果我在写入时没有明确指定 numPartitions = 8 仍然有效吗?

【问题讨论】:

标签: scala apache-spark apache-spark-sql


【解决方案1】:

如果您未指定 {partitionColumnlowerBoundupperBoundnumPartitions} 或 {predicates},Spark 将使用单个执行程序并创建单个非空分区。所有数据都将使用单个事务处理,读取既不会分布式也不会并行化。

另见:

有关 spark JDBC 集成的更多信息,请查看 spark 文档

【讨论】:

  • 好吧,假设我在阅读 DataFrame 时给出了numPartitions,在编写相同的df 时是否会使用相同的numPartitions(在编写时没有明确指定)(Qn。# 3)?
  • 运行 df.write 时,df 中的每个原始分区都是独立写入的。但如果您还添加numPartitions 作为最佳做法。
  • 好的,这意味着在写入数据库时​​会保留相同的numPartitions,而无需我明确指定,对吗?
猜你喜欢
  • 2018-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-12
  • 2015-05-22
  • 1970-01-01
  • 1970-01-01
  • 2021-05-28
相关资源
最近更新 更多