code: def _flatten_statistics_for_sliced_validation(
      statistics: statistics_pb2.DatasetFeatureStatisticsList,
  ) -> Tuple[statistics_pb2.DatasetFeatureStatisticsList, Set[str]]:
      """Flattens sliced stats into unsliced stats with prepended slice keys."""
      result = statistics_pb2.DatasetFeatureStatisticsList()
      dataset_flat = result.datasets.add()
      # Copy top level metadata from the default (overall) slice.
      default_slice = stats_util.DatasetListView(
          statistics
      ).get_default_slice()
      if default_slice is None:
          raise ValueError("Missing default slice")
      dataset_flat.CopyFrom(default_slice.proto())
      dataset_flat.ClearField("features")
      dataset_flat.ClearField("cross_features")
      slice_names = set()
      for dataset in statistics.datasets:
          slice_names.add(dataset.name)
          for feature in dataset.features:
              copied_feature = dataset_flat.features.add()
              copied_feature.CopyFrom(feature)
              copied_feature.path.CopyFrom(
                  _prepend_slice_path(
                      dataset.name,
                      types.FeaturePath.from_proto(copied_feature.path),
                  ).to_proto()
              )
          for cross_feature in dataset.cross_features:
              copied_cross_feature = dataset_flat.cross_features.add()
              copied_cross_feature.CopyFrom(cross_feature)
              copied_cross_feature.path_x.CopyFrom(
                  _prepend_slice_path(
                      dataset.name,
                      types.FeaturePath.from_proto(
                          copied_cross_feature.path_x
                      ),
                  ).to_proto()
              )
              copied_cross_feature.path_y.CopyFrom(
                  _prepend_slice_path(
                      dataset.name,
                      types.FeaturePath.from_proto(
                          copied_cross_feature.path_y
                      ),
                  ).to_proto()
              )
      return result, slice_names
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import itertools
  import logging
  from typing import Callable, Iterable, List, Optional, Text, Tuple, Set
  import apache_beam
  import pyarrow
  import tensorflow
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.anomalies.proto import custom_validation_config_pb2
  from tensorflow_data_validation.anomalies.proto import validation_config_pb2
  from tensorflow_data_validation.anomalies.proto import validation_metadata_pb2
  from tensorflow_data_validation.api import validation_options
  from tensorflow_data_validation.pywrap.tensorflow_data_validation_extension import validation
  from tensorflow_data_validation.skew import feature_skew_detector
  from tensorflow_data_validation.skew.protos import feature_skew_results_pb2
  from tensorflow_data_validation.statistics import stats_impl
  from tensorflow_data_validation.statistics import stats_options
  from tensorflow_data_validation.utils import anomalies_util
  from tensorflow_data_validation.utils import slicing_util
  from tensorflow_data_validation.utils import stats_util
  from tensorflow_metadata.proto.v0 import anomalies_pb2
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 15 for calling a global function with example usage: _flatten_statistics_for_sliced_validation(statistics) and returns: result,  slice_names