code: def saveAsTFRecords(df, output_dir):
      """Save a Spark DataFrame as TFRecords.
  
      This will convert the DataFrame rows to TFRecords prior to saving.
  
      Args:
        :df: Spark DataFrame
        :output_dir: Path to save TFRecords
      """
      tf_rdd = df.rdd.mapPartitions(toTFExample(df.dtypes))
      tf_rdd.saveAsNewAPIHadoopFile(
          output_dir,
          "org.tensorflow.hadoop.io.TFRecordFileOutputFormat",
          keyClass="org.apache.hadoop.io.BytesWritable",
          valueClass="org.apache.hadoop.io.NullWritable",
      )
  
file_path: TensorFlowOnSpark/tensorflowonspark/dfutil.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import nested_scopes
  from __future__ import print_function
  import tensorflow
  from pyspark.sql import Row
  from pyspark.sql.types import ArrayType, BinaryType, DoubleType, LongType, StringType, StructField, StructType
label_desc: Use image node_id 2 for calling a global function with example usage: saveAsTFRecords(df, output_dir) without return types