Koalas applymap 将所有数据移动到单个分区
Koalas applymap moving all data to a single partition
我需要对 Koalas DataFrame 进行逐元素操作。为此,我使用了 Koalas applymap 方法。在执行时,Koalas 将所有数据移动到一个分区,然后应用该操作。结果是工作表现很差
>>> sdf = spark.range(0, 10**7, 1, 10).toDF('col1').withColumn('col2', F.lit('[1,2]'))
>>> kdf = ks.DataFrame(sdf)
>>> kdf_new = kdf[['col2']].applymap(eval)
WARN window.WindowExec: No Partition Defined for Window operation! Moving all data to a single partition, this can cause serious performance degradation.
如何强制 Koalas 不对数据进行洗牌并将操作应用于现有分区?
您可以通过在 Koalas DataFrame 上指定索引来解决此问题。预计默认索引会提供较差的性能。在 Koalas 中阅读 default index type。
要么指定一个不同的默认索引
ks.options.compute.default_index_type = 'distributed-sequence'
或在您的 DataFrame 上指定特定索引(即不使用默认索引)
kdf = kdf.set_index('col1')
我需要对 Koalas DataFrame 进行逐元素操作。为此,我使用了 Koalas applymap 方法。在执行时,Koalas 将所有数据移动到一个分区,然后应用该操作。结果是工作表现很差
>>> sdf = spark.range(0, 10**7, 1, 10).toDF('col1').withColumn('col2', F.lit('[1,2]'))
>>> kdf = ks.DataFrame(sdf)
>>> kdf_new = kdf[['col2']].applymap(eval)
WARN window.WindowExec: No Partition Defined for Window operation! Moving all data to a single partition, this can cause serious performance degradation.
如何强制 Koalas 不对数据进行洗牌并将操作应用于现有分区?
您可以通过在 Koalas DataFrame 上指定索引来解决此问题。预计默认索引会提供较差的性能。在 Koalas 中阅读 default index type。
要么指定一个不同的默认索引
ks.options.compute.default_index_type = 'distributed-sequence'
或在您的 DataFrame 上指定特定索引(即不使用默认索引)
kdf = kdf.set_index('col1')