class_docstr: Convertor between RDD and Spark DataFrame.
class_docstr_tok: ["Convertor","between","RDD","and","Spark","DataFrame","."]
code: def dataframe_to_collection(
      self, df: SparkDataFrame, columns: Columns
  ) -> pyspark.RDD:
      self._save_partition_key_schema(df, columns.partition_key)
      columns_to_keep = [columns.privacy_key]
      if isinstance(columns.partition_key, str):
          num_partition_columns = 1
          columns_to_keep.append(columns.partition_key)
      else:  # Sequence[str], multiple columns
          num_partition_columns = len(columns.partition_key)
          columns_to_keep.extend(columns.partition_key)
      value_present = columns.value is not None
      if value_present:
          columns_to_keep.append(columns.value)
  
      df = df[columns_to_keep]  # leave only needed columns.
  
      def extractor(row):
          privacy_key = row[0]
          partition_key = (
              row[1]
              if num_partition_columns == 1
              else row[1 : 1 + num_partition_columns]
          )
          value = row[1 + num_partition_columns] if value_present else 0
          return (privacy_key, partition_key, value)
  
      return df.rdd.map(extractor)
  
imports: import abc
  import copy
  from collections import namedtuple
  from dataclasses import dataclass
  from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union
  import pipeline_dp
  import pyspark
label_desc: Use image node_id 2 for calling the SparkConverter obj's underlying member method code with example usage: obj.dataframe_to_collection(df, columns) and returns: df, privacy_key,  partition_key,  value