def _write_to_temporary_asset_file(
    temp_dir: str, temporary_asset_info: TemporaryAssetInfo) -> str:
  """Returns path to temporary asset file created during tracing."""
  # TODO(b/170111921): This temporary file should have a unique name to
  # avoid namespace collisions between temporary files that contain data
  # of different dtypes.
  base_filename = uuid.uuid4().hex
  if temporary_asset_info.file_format == 'text':
    result = os.path.join(temp_dir, base_filename)
    with tf.io.gfile.GFile(result, 'w') as f:
      f.write(temporary_asset_info.value)
  elif temporary_asset_info.file_format == 'tfrecord_gzip':
    result = os.path.join(temp_dir, '{}.tfrecord.gz'.format(base_filename))
    with tf.io.TFRecordWriter(result, 'GZIP') as f:
      f.write(temporary_asset_info.value)
  else:
    raise ValueError(
        'File format should be one of \'text\' or \'tfrecord_gzip\'. Received '
        f'{temporary_asset_info.file_format}')
  return result
Returns path to temporary asset file created during tracing.
tensorflow_transform/analyzer_nodes.py