code: def _write_to_path_from_cached_data(
      self, dir_path, data_source, dataset
  ):
      if os.path.exists(dir_path):
          return dir_path
      os.makedirs(dir_path)
  
      scenario = data_source.scenario
      schema = parse(self.scenario_to_avro_schema(scenario))
  
      filenames_to_num_records = self._get_filenames_to_num_records(
          data_source
      )
      iterator = iter(dataset)
      for filename in sorted(filenames_to_num_records):
          file_path = os.path.join(dir_path, filename)
          num_records = filenames_to_num_records[filename]
  
          with open(file_path, "wb") as out:
              file_writer = DataFileWriter(
                  out, DatumWriter(), schema, codec=self._codec
              )
              for _ in range(num_records):
                  features = {}
                  record = iterator.get_next()
                  for feature_name in record:
                      generator = data_source.scenario[feature_name]
                      # tf.Example only supports tf.float32, tf.int64, and tf.string
                      # For other dtypes, cast feature into its original dtype.
                      actual = tf.cast(
                          record[feature_name], generator.spec.dtype
                      )
                      self._add_tensor_to_features(
                          generator, feature_name, actual, features
                      )
                  file_writer.append(features)
              file_writer.close()
  
imports: import os
  import hashlib
  import json
  import numpy
  import tensorflow
  from avro.schema import Parse
  from avro.datafile import DataFileWriter
  from avro.io import DatumWriter
  from tests.test_atds_avro.utils.file_writer import FileWriter
  from tests.test_atds_avro.utils.generator.varlen_tensor_generator import VarLenTensorGeneratorBase
  from tensorflow_io.python.experimental.atds.features import DenseFeature, SparseFeature, VarlenFeature
label_desc: Use image node_id 4 for calling the ATDSWriter obj's underlying member method code with example usage: obj._write_to_path_from_cached_data(dir_path, data_source, dataset) and returns: dir_path