class_docstr: Base class for file writer.
  
  FileWriter consumes a DataSource and generates benchmark data as described
  in the DataSource. DataSource contains benchmark data metadata such as value
  generators, total number of records, and number of partitioned files.
  
  SubClass must implement `_write_to_path` function to write data under the
  given path and follow the spec described in DataSource.
class_docstr_tok: ["Base","class","for","file","writer",".","FileWriter","consumes","a","DataSource","and","generates","benchmark","data","as","described","in","the","DataSource",".","DataSource","contains","benchmark","data","metadata","such","as","value","generators",",","total","number","of","records",",","and","number","of","partitioned","files",".","SubClass","must","implement","`","_write_to_path","`","function","to","write","data","under","the","given","path","and","follow","the","spec","described","in","DataSource","."]
docstr: Generate benchmark data and return the path to the generated files.
  
  Args:
    data_source: A DataSource object that describes the properties of
      the benchmark data.
  
  Returns:
    A str path to the generated files.
docstr_tok: ["Generate","benchmark","data","and","return","the","path","to","the","generated","files",".","Args",":","data_source",":","A","DataSource","object","that","describes","the","properties","of","the","benchmark","data",".","Returns",":","A","str","path","to","the","generated","files","."]
code: def write(self, data_source):
      """Generate benchmark data and return the path to the generated files.
  
      Args:
        data_source: A DataSource object that describes the properties of
          the benchmark data.
  
      Returns:
        A str path to the generated files.
      """
      # Use data source hash code as data source folder name.
      data_source_path = data_source.hash_code()
      # Use writer hash code as the writer folder path.
      writer_dir = self.hash_code()
  
      if self._data_cache_path is not None:
          cached_dataset = None
          writer_path = os.path.join(
              self._data_cache_path, data_source_path, writer_dir
          )
          if os.path.exists(writer_path):
              return writer_path
          from tests.test_atds_avro.utils.tf_record_writer import (
              TFRecordWriter,
          )
  
          with TFRecordWriter() as tf_writer:
              tf_record_cache_dir = os.path.join(
                  self._data_cache_path,
                  data_source_path,
                  tf_writer.hash_code(),
              )
              if not os.path.exists(tf_record_cache_dir):
                  os.makedirs(tf_record_cache_dir, exist_ok=True)
                  tf_writer._write_to_path(
                      tf_record_cache_dir, data_source
                  )
              parser_fn = tf_writer.create_tf_example_parser_fn(
                  data_source
              )
              pattern = os.path.join(
                  tf_record_cache_dir, f"*.{tf_writer.extension}"
              )
              cached_dataset = tf.data.Dataset.list_files(
                  pattern, shuffle=False
              )
              cached_dataset = tf.data.TFRecordDataset(cached_dataset)
              cached_dataset = cached_dataset.map(parser_fn)
              self._write_to_path_from_cached_data(
                  writer_path, data_source, cached_dataset
              )
              return writer_path
      else:
          writer_path = os.path.join(
              self._dir_path, data_source_path, writer_dir
          )
          if not os.path.exists(writer_path):
              os.makedirs(writer_path, exist_ok=True)
              self._write_to_path(writer_path, data_source)
          return writer_path
  
file_path: io/tests/test_atds_avro/utils/file_writer.py
imports: import abc
  import os
  import shutil
  import hashlib
  import tempfile
  import tensorflow
label_desc: Use image node_id 4 for calling the FileWriter obj's underlying member method code with example usage: obj.write(data_source) and returns: writer_path, writer_path, writer_path