class_docstr: Samples rows from record batches.
  
  The record batches in the partition can vary in the number of rows.
  SamplePartition guarantees that the sample returned is always going to be
  <= sample_size.
  
  The actual sampling occurs in `compact`. It uses np.partition to calculate
  the top-k of record batch's rows. Where the top-k is a random number assigned
  to each row. Given a uniform distribution of the random number, we can keep a
  running sample of the partition of size k. This gives each row an equal
  probability of being selected.
class_docstr_tok: ["Samples","rows","from","record","batches",".","The","record","batches","in","the","partition","can","vary","in","the","number","of","rows",".","SamplePartition","guarantees","that","the","sample","returned","is","always","going","to","be","<","=","sample_size",".","The","actual","sampling","occurs","in","`","compact","`",".","It","uses","np.partition","to","calculate","the","top-k","of","record","batch","'s","rows",".","Where","the","top-k","is","a","random","number","assigned","to","each","row",".","Given","a","uniform","distribution","of","the","random","number",",","we","can","keep","a","running","sample","of","the","partition","of","size","k.","This","gives","each","row","an","equal","probability","of","being","selected","."]
docstr: Initializes the analyzer.
docstr_tok: ["Initializes","the","analyzer","."]
code: def __init__(self, sample_size: int):
      """Initializes the analyzer."""
      self._sample_size = sample_size
      # Number of record batches in accumulator when compacting.
      self._combine_num_record_batches = (
          beam.metrics.Metrics.distribution(
              constants.METRICS_NAMESPACE,
              "sample_record_batch_rows_combine_num_record_batches",
          )
      )
      self._combine_num_columns = beam.metrics.Metrics.distribution(
          constants.METRICS_NAMESPACE, "sample_record_batch_num_columns"
      )
      # Post compress byte size.
      self._combine_byte_size = beam.metrics.Metrics.distribution(
          constants.METRICS_NAMESPACE,
          "sample_record_batch_rows_combine_byte_size",
      )
      # Number of compacts.
      self._num_compacts = beam.metrics.Metrics.counter(
          constants.METRICS_NAMESPACE,
          "sample_record_batch_rows_num_compacts",
      )
      # Total number of rows.
      self._num_instances = beam.metrics.Metrics.counter(
          constants.METRICS_NAMESPACE,
          "sample_record_batch_rows_num_instances",
      )
  
      # We allow our accumulators to keep a buffer of _BUFFER_SIZE_SCALAR x sample
      # size. With this threshold, OOM issues are possible, but unlikely.
      self._merge_record_batch_threshold = (
          self._BUFFER_SIZE_SCALAR * sample_size
      )
  
imports: import collections
  import functools
  from typing import Dict, Iterable, Text, Tuple
  import apache_beam
  import numpy
  import pyarrow
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import stats_generator
  from tensorflow_data_validation.utils import stats_util
  from tfx_bsl.arrow import table_util
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 1 to create a new _SampleRecordBatchRows object from inherited base classes: beam with example: obj = _SampleRecordBatchRows(sample_size)