【发布时间】:2021-11-21 12:21:33
【问题描述】:
假设我有这个代码:
def func1():
# some code to create a dataframe df
df.persist(StorageLevel.MEMORY_AND_DISK)
return df.repartition("col1", "col2")
def func2(df: Dataframe):
df = (df.select("col1", "col2").groupby("col1").count().withColumnRenamed("count", "count_col1"))
return df
所以在 func2 中,当我传递变量“df”时,它是通过引用传递还是通过值传递?我在func1中应用的repartition(),在将func2中的df用于groupBy时应该有助于提高性能吗? 类似地,如果我在 func1 中应用 persist(),那么它将正确保存在内存中,然后当我在 func2() 中引用 df 时,它将从它在 func1() 中仅保存一次的同一位置引用.对吗?
谢谢!
【问题讨论】:
标签: performance pyspark parameter-passing pass-by-reference partitioning