class_docstr: Shuffles / writes Examples beam collection to sharded TFRecord files.
  
  The given examples are not directly writen to the final tfrecord file, but to
  temporary files.
class_docstr_tok: ["Shuffles","\/","writes","Examples","beam","collection","to","sharded","TFRecord","files",".","The","given","examples","are","not","directly","writen","to","the","final","tfrecord","file",",","but","to","temporary","files","."]
docstr: Write all examples of a shard to disk.
  
  Arguments:
    shardid_examples: tuple of the shard id and the serialized examples that
      belong to that shard.
    non_empty_shard_ids: list of the shard ids of all the non-empty shards.
      Must be sorted.
  
  Returns:
    the shard info of the written shard.
docstr_tok: ["Write","all","examples","of","a","shard","to","disk",".","Arguments",":","shardid_examples",":","tuple","of","the","shard","id","and","the","serialized","examples","that","belong","to","that","shard",".","non_empty_shard_ids",":","list","of","the","shard","ids","of","all","the","non-empty","shards",".","Must","be","sorted",".","Returns",":","the","shard","info","of","the","written","shard","."]
code: def _write_final_shard(
      self,
      shardid_examples: Tuple[
          int, Iterable[type_utils.KeySerializedExample]
      ],
      non_empty_shard_ids: List[int],
  ) -> _ShardInfo:
      """Write all examples of a shard to disk.
  
      Arguments:
        shardid_examples: tuple of the shard id and the serialized examples that
          belong to that shard.
        non_empty_shard_ids: list of the shard ids of all the non-empty shards.
          Must be sorted.
  
      Returns:
        the shard info of the written shard.
      """
      original_shard_id, examples = shardid_examples
      if not examples:
          raise AssertionError(
              "Not a single example present in the PCollection!"
          )
      # There may be empty shards, this ensures there are no gaps.
      shard_id = non_empty_shard_ids.index(original_shard_id)
      examples = sorted(examples)
      self._get_distribution(name="ShardLenDistribution").update(
          len(examples)
      )
      # Compare continuous examples
      for ex0, ex1 in zip(examples[:-1], examples[1:]):
          if ex0[0] == ex1[0]:  # Different keys
              _raise_error_for_duplicated_keys(
                  ex0[1], ex1[1], self._serializer.example_specs
              )
      shard_path = self._filename_template.sharded_filepath(
          shard_index=shard_id, num_shards=len(non_empty_shard_ids)
      )
      with utils.incomplete_file(epath.Path(shard_path)) as tmp_path:
          logging.info(
              "Writing %d examples to %s.",
              len(examples),
              os.fspath(tmp_path),
          )
          record_keys = _write_examples(
              tmp_path, examples, self._file_format
          )
      self.inc_counter(name="written_shards")
      # If there are record_keys, create index files.
      if record_keys:
          index_path = _get_index_path(os.fspath(shard_path))
          _write_index_file(index_path, list(record_keys))
      shard_size = sum(map(len, examples))
      return _ShardInfo(
          id=shard_id, num_examples=len(examples), size=shard_size
      )
  
imports: import dataclasses
  import functools
  import itertools
  import json
  import os
  from typing import Any, Iterable, List, Optional, Tuple
  from absl import logging
  from etils import epath
  from tensorflow_datasets.core import example_parser
  from tensorflow_datasets.core import example_serializer
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import hashing
  from tensorflow_datasets.core import lazy_imports_lib
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import shuffle
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.utils import file_utils
  from tensorflow_datasets.core.utils import shard_utils
  from tensorflow_datasets.core.utils import type_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import apache_beam
label_desc: Use image node_id 9 for calling the BeamWriter obj's underlying member method code with example usage: obj._write_final_shard(shardid_examples, non_empty_shard_ids) and returns: _ShardInfo