【问题标题】:Spark JDBC read API: Determining the number of partitions dynamically for a column of type datetimeSpark JDBC读取API:动态确定日期时间类型列的分区数
【发布时间】:2021-07-07 11:02:05
【问题描述】:

我正在尝试使用 PySpark 从 RDS MySQL 实例中读取表。这是一个巨大的表,因此我想通过使用分区概念来并行化读取操作。该表没有用于查找分区数的数字列。相反,它有一个时间戳列(即日期时间类型)。

我通过检索时间戳列的最小值和最大值找到了下限和上限。但是,我不确定是否有标准公式可以动态找出分区数。这是我目前正在做的事情(硬编码 numPartititons 参数的值):

select_sql = "SELECT {} FROM {}".format(columns, table)
partition_info = {'partition_column': 'col1', 
                  'lower_bound': '<result of min(col1)>', 
                  'upper_bound': '<result of max(col1)>', 
                  'num_partitions': '10'}
read_df = spark.read.format("jdbc") \
        .option("driver", driver) \
        .option("url", url) \
        .option("dbtable", select_sql) \
        .option("user", user) \
        .option("password", password) \
        .option("useSSL", False) \
        .option("partitionColumn", partition_info['partition_column']) \
        .option("lowerBound", partition_info['lower_bound'])) \
        .option("upperBound", partition_info['upper_bound'])) \
        .option("numPartitions", partition_info['num_partitions']) \
        .load()

请建议我一个可行的解决方案/您的方法。谢谢

【问题讨论】:

  • 你在这里试过的代码是什么?
  • 我已经添加了代码sn-p。请看一下。

标签: apache-spark pyspark apache-spark-sql partitioning spark-jdbc


【解决方案1】:

如何设置numPartitions 取决于集群的定义。这里没有正确或错误或自动设置。只要您了解partitionColumnlowerBoundupperBoundnumPartitions 背后的逻辑,并且可能进行了大量基准测试,您就可以决定什么是正确的数字。

Pyspark - df.cache().count() taking forever to run

What is the meaning of partitionColumn, lowerBound, upperBound, numPartitions parameters?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2018-05-18
    • 2021-12-19
    相关资源
    最近更新 更多