我需要分批處理 Spark 資料幀磁區,一次處理 N 個磁區。例如,如果我在 hive 表中有 1000 個磁區,我需要一次處理 100 個磁區。
我嘗試了以下方法
從 hive 表中獲取磁區串列并查找總數
使用 total_count/100 獲取回圈計數
然后
for x in range(loop_count): files_list=partition_path_list[start_index:end_index] df = spark.read.option("basePath", target_table_location).parquet(*files_list)
但這并沒有按預期作業。任何人都可以提出更好的方法。首選 Spark Scala 中的解決方案
uj5u.com熱心網友回復:
您擁有的 for 回圈x每次都在增加。這就是開始和結束索引不增加的原因。
不知道你為什么提到 Scala,因為你的代碼是用 Python 撰寫的。這是一個回圈計數為 1000 的示例。
partitions_per_iteration = 100
loop_count = 1000
for start_index in range(0, loop_count, partitions_per_iteration):
files_list=partition_path_list[start_index:start_index partitions_per_iteration]
df = spark.read.option("basePath", target_table_location).parquet(*files_list)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/529607.html
