code: def _get_all_sparse_features(
      schema: schema_pb2.Schema,
  ) -> List[Tuple[types.FeaturePath, schema_pb2.SparseFeature]]:
      """Returns all sparse features in a schema."""
  
      def _recursion_helper(
          parent_path: types.FeaturePath,
          container: Union[schema_pb2.Schema, schema_pb2.StructDomain],
      ) -> List[Tuple[types.FeaturePath, schema_pb2.SparseFeature]]:
          """Helper function that is used in finding sparse features in a tree."""
          result = []
          for sf in container.sparse_feature:
              # Sparse features do not have a struct_domain, so they cannot be parent
              # features. Thus, once this reaches a sparse feature, add it to the
              # result.
              result.append((parent_path.child(sf.name), sf))
          for f in container.feature:
              if f.type == schema_pb2.STRUCT:
                  result.extend(
                      _recursion_helper(
                          parent_path.child(f.name), f.struct_domain
                      )
                  )
          return result
  
      return _recursion_helper(types.FeaturePath([]), schema)
  
file_path: data-validation/tensorflow_data_validation/statistics/generators/sparse_feature_stats_generator.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Dict, Iterable, List, Text, Tuple, Union
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import stats_generator
  from tensorflow_data_validation.statistics.generators.constituents import count_missing_generator
  from tensorflow_data_validation.statistics.generators.constituents import length_diff_generator
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
  from tfx_bsl.types import tfx_namedtuple
label_desc: Use image node_id 1 for calling a global function with example usage: _get_all_sparse_features(schema) and returns: _recursion_helper, result