class_docstr: Writes a dataset to a TFRecord file.
  
  The elements of the dataset must be scalar strings. To serialize dataset
  elements as strings, you can use the `tf.io.serialize_tensor` function.
  
  ```python
  dataset = tf.data.Dataset.range(3)
  dataset = dataset.map(tf.io.serialize_tensor)
  writer = tf.data.experimental.TFRecordWriter("/path/to/file.tfrecord")
  writer.write(dataset)
  ```
  
  To read back the elements, use `TFRecordDataset`.
  
  ```python
  dataset = tf.data.TFRecordDataset("/path/to/file.tfrecord")
  dataset = dataset.map(lambda x: tf.io.parse_tensor(x, tf.int64))
  ```
  
  To shard a `dataset` across multiple TFRecord files:
  
  ```python
  dataset = ... # dataset to be written
  
  def reduce_func(key, dataset):
    filename = tf.strings.join([PATH_PREFIX, tf.strings.as_string(key)])
    writer = tf.data.experimental.TFRecordWriter(filename)
    writer.write(dataset.map(lambda _, x: x))
    return tf.data.Dataset.from_tensors(filename)
  
  dataset = dataset.enumerate()
  dataset = dataset.apply(tf.data.experimental.group_by_window(
    lambda i, _: i % NUM_SHARDS, reduce_func, tf.int64.max
  ))
  
  # Iterate through the dataset to trigger data writing.
  for _ in dataset:
    pass
  ```
docstr: Initializes a `TFRecordWriter`.
  
  Args:
    filename: a string path indicating where to write the TFRecord data.
    compression_type: (Optional.) a string indicating what type of compression
      to use when writing the file. See `tf.io.TFRecordCompressionType` for
      what types of compression are available. Defaults to `None`.
code: def __init__(self, filename, compression_type=None):
      """Initializes a `TFRecordWriter`.
  
      Args:
        filename: a string path indicating where to write the TFRecord data.
        compression_type: (Optional.) a string indicating what type of compression
          to use when writing the file. See `tf.io.TFRecordCompressionType` for
          what types of compression are available. Defaults to `None`.
      """
      self._filename = ops.convert_to_tensor(
          filename, dtypes.string, name="filename"
      )
      self._compression_type = convert.optional_param_to_tensor(
          "compression_type",
          compression_type,
          argument_default="",
          argument_dtype=dtypes.string,
      )
  
file_path: tensorflow-upstream/tensorflow/python/data/experimental/ops/writers.py
imports: from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.util import convert
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_spec
  from tensorflow.python.ops import gen_experimental_dataset_ops
  from tensorflow.python.types import data
  from tensorflow.python.util import deprecation
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 1 to create a new TFRecordWriter object  with example: obj = TFRecordWriter(filename, compression_type)