class_docstr: A DoFn that extracts slice keys in batch based on input SQL.
class_docstr_tok: ["A","DoFn","that","extracts","slice","keys","in","batch","based","on","input","SQL","."]
code: def process(
      self, record_batch: pa.RecordBatch
  ) -> Iterable[types.SlicedRecordBatch]:
      # Keep track of row indices per slice key.
      per_slice_indices = collections.defaultdict(set)
      if record_batch.schema.metadata is not None:
          # record_batch may have unhashable schema metadata if derived features are
          # being used, so we construct a new schema that strips that information.
          cache_schema = pa.schema(
              zip(record_batch.schema.names, record_batch.schema.types)
          )
      else:
          cache_schema = record_batch.schema
      for query in self._get_queries_for_schema(cache_schema):
          # Example of result with batch size = 3:
          # result = [[[('feature', 'value_1')]],
          #           [[('feature', 'value_2')]],
          #           []
          #          ]
          if query is None:
              yield (constants.INVALID_SLICE_KEY, record_batch)
              continue
  
          result = query.Execute(record_batch)
          for i, per_row_slices in enumerate(result):
              for slice_tuples in per_row_slices:
                  slice_key = "_".join(map("_".join, slice_tuples))
                  per_slice_indices[slice_key].add(i)
  
      yield (constants.DEFAULT_SLICE_KEY, record_batch)
      for slice_key, row_indices in per_slice_indices.items():
          yield (
              slice_key,
              table_util.RecordBatchTake(
                  record_batch, pa.array(row_indices)
              ),
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from collections import abc
  import functools
  import logging
  from typing import Any, Dict, Iterable, List, Optional, Text, Union, Tuple
  import apache_beam
  import numpy
  import pandas
  import pandas.core.computation.expressions
  import pyarrow
  import six
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.arrow import arrow_util
  from tensorflow_data_validation.utils import stats_util
  from tfx_bsl.arrow import array_util
  from tfx_bsl.arrow import sql_util
  from tfx_bsl.arrow import table_util
  from tfx_bsl.public.proto import slicing_spec_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 3 for calling the GenerateSlicesSqlDoFn obj's underlying member method code with example usage: obj.process(record_batch) without return types