I'm trying to construct a DataFrame from a list of data, then write it as parquet files:
dataframe = None
while True:
data_list = get_data_list() # this function would return a list of data, about 1 million rows
rdd = sparkContext.parallelize(data_list, 20)
if dataframe:
dataframe.union(sparkSession.createDataFrame(data=rdd))
else:
dataframe = sparkSession.createDataFrame(data=rdd)
if some_judgement:
break
dataframe.write.parquet('...')
But I found the driver would fail with java.lang.OutOfMemoryError: Java heap space after a few cycles. If I increase the driver-memory or decrease the number of cycles in the loop, this exception stops occurring. So I guess even if I created an RDD, the data is still stored in the driver. So when will the data be sent to executors ? I want to decrease the memory usage of the driver.