code: def test_caching_vocab_for_integer_categorical(
      self, use_tf_compat_v1
  ):
      if not use_tf_compat_v1:
          tft_unit.skip_if_not_tf2("Tensorflow 2.x required.")
      span_0_key = analyzer_cache.DatasetKey("span-0")
      span_1_key = analyzer_cache.DatasetKey("span-1")
  
      def preprocessing_fn(inputs):
          return {
              "x_vocab": tft.compute_and_apply_vocabulary(
                  inputs["x"], frequency_threshold=2
              )
          }
  
      feature_spec = {"x": tf.io.FixedLenFeature([], tf.int64)}
      input_data_dict = {
          span_0_key: [{"x": -2}, {"x": -4}, {"x": -1}, {"x": 4}],
          span_1_key: [{"x": -2}, {"x": -1}, {"x": 6}, {"x": 7}],
      }  # pyformat: disable
      expected_transformed_data = [
          {"x_vocab": 0},
          {"x_vocab": 1},
          {"x_vocab": -1},
          {"x_vocab": -1},
      ]  # pyformat: disable
  
      dataset_size = 17
      cache_dict = {
          span_0_key: analyzer_cache.DatasetCache(
              {
                  _make_cache_key(
                      b"VocabularyAccumulate[compute_and_apply_vocabulary#vocabulary]"
                  ): [
                      _encode_vocabulary_accumulator(b"-2", b"2"),
                      _encode_vocabulary_accumulator(b"-4", b"1"),
                      _encode_vocabulary_accumulator(b"-1", b"1"),
                      _encode_vocabulary_accumulator(b"4", b"1"),
                  ]
              },
              analyzer_cache.DatasetCacheMetadata(
                  dataset_size=dataset_size
              ),
          ),
          span_1_key: analyzer_cache.DatasetCache({}, None),
      }
  
      run_result = self._run_pipeline(
          feature_spec,
          input_data_dict,
          preprocessing_fn,
          cache_dict=cache_dict,
          datasets_to_transform=[span_1_key],
          expected_transform_data=expected_transformed_data,
          transform_fn_output_dir=None,
          use_tf_compat_v1=use_tf_compat_v1,
      )
  
      self.assertNotIn(span_0_key, run_result.cache_output)
  
      metrics = run_result.metrics
      # 4 from analysis since 1 span was completely cached, and 4 from transform.
      self.assertMetricsCounterEqual(metrics, "num_instances", 8)
      self.assertMetricsCounterEqual(
          metrics, "cache_entries_decoded", 1
      )
      self.assertMetricsCounterEqual(
          metrics, "cache_entries_encoded", 1
      )
      self.assertMetricsCounterEqual(
          metrics,
          "saved_models_created",
          _SINGLE_PHASE_NUM_SAVED_MODELS,
      )
      # Cache coverage allowed us to avoid processing this many bytes of data.
      self.assertMetricsCounterEqual(
          metrics, "analysis_input_bytes_from_cache", dataset_size
      )
  
imports: import functools
  import os
  import struct
  from typing import Callable, Mapping, List
  import uuid
  import apache_beam
  from apache_beam.testing import util
  import numpy
  import tensorflow
  import tensorflow_transform
  from tensorflow_transform import analyzer_nodes
  from tensorflow_transform import common_types
  from tensorflow_transform import impl_helper
  from tensorflow_transform import nodes
  import tensorflow_transform.beam
  from tensorflow_transform.beam import analysis_graph_builder
  from tensorflow_transform.beam import analyzer_cache
  from tensorflow_transform.beam import tft_unit
  from tensorflow_transform.tf_metadata import dataset_metadata
  from tfx_bsl.types import tfx_namedtuple
label_desc: Use image node_id 9 for calling the CachedImplTest obj's underlying member method code with example usage: obj.test_caching_vocab_for_integer_categorical(use_tf_compat_v1) and returns: dict