[SPARK-3517]mapPartitions is not correct clearing up the closure