code: def _handle_sparse_feature(
      feature, key, sparse_keys, sparse_types, sparse_ranks, types
  ):
      """handle_sparse_feature"""
      if tf.io.SparseFeature not in types:
          raise ValueError(f"Unsupported SparseFeature {feature}.")
      if not feature.index_key:
          raise ValueError(
              f"Missing index_key for SparseFeature {feature}."
          )
      if not feature.value_key:
          raise ValueError(
              f"Missing value_key for SparseFeature {feature}."
          )
      if not feature.dtype:
          raise ValueError("Missing type for feature %s." % key)
      index_keys = feature.index_key
      if isinstance(index_keys, str):
          index_keys = [index_keys]
      elif len(index_keys) > 1:
          tf.get_logger().warning(
              "SparseFeature is a complicated feature config "
              "and should only be used after careful "
              "consideration of VarLenFeature."
          )
      for index_key in sorted(index_keys):
          if index_key in sparse_keys:
              dtype = sparse_types[sparse_keys.index(index_key)]
              if dtype != tf.int64:
                  raise ValueError(
                      "Conflicting type {} vs int64 for feature {}.".format(
                          dtype, index_key
                      )
                  )
          else:
              sparse_keys.append(index_key)
              sparse_types.append(tf.int64)
              # sparse features always have rank 1 because they encode the indices separately (one for each component) and then merge these before the user get's them.
              # setting 1 here is merely achieving the same behavior as before.
              sparse_ranks.append(1)
      if feature.value_key in sparse_keys:
          dtype = sparse_types[sparse_keys.index(feature.value_key)]
          if dtype != feature.dtype:
              raise ValueError(
                  "Conflicting type %s vs %s for feature %s."
                  % (dtype, feature.dtype, feature.value_key)
              )
      else:
          sparse_keys.append(feature.value_key)
          sparse_types.append(feature.dtype)
          # sparse features always have rank 1 because they encode the indices separately (one for each component) and then merge these before the user get's them.
          # setting 1 here is merely achieving the same behavior as before.
          sparse_ranks.append(1)
  
file_path: io/tensorflow_io/python/experimental/parse_avro_ops.py
imports: import collections
  import re
  import tensorflow
  import tensorflow_io
  from tensorflow_io.python.ops import core_ops
label_desc: Use image node_id 8 for calling a global function with example usage: _handle_sparse_feature(feature, key, sparse_keys, sparse_types, sparse_ranks, types) without return types