code: def _generate_num_row_groups_per_file(
      dataset, spark_context, filesystem_factory
  ):
      """
      Generates the metadata file containing the number of row groups in each file
      for the parquet dataset located at the dataset_url. It does this in spark by
      opening all parquet files in the dataset on the executors and collecting the
      number of row groups in each file back on the driver.
      :param dataset: :class:`pyarrow.parquet.ParquetDataset`
      :param spark_context: spark context to use for retrieving the number of row groups
      in each parquet file in parallel
      :return: None, upon successful completion the metadata file will exist.
      """
      if not isinstance(dataset.paths, str):
          raise ValueError(
              "Expected dataset.paths to be a single path, not a list of paths"
          )
  
      # Get the common prefix of all the base path in order to retrieve a relative path
      paths = [piece.path for piece in dataset.pieces]
  
      # Needed pieces from the dataset must be extracted for spark because the dataset object is not serializable
      base_path = dataset.paths
  
      def get_row_group_info(path):
          fs = filesystem_factory()
          relative_path = os.path.relpath(path, base_path)
          pq_file = fs.open(path)
          num_row_groups = pq.read_metadata(pq_file).num_row_groups
          pq_file.close()
          return relative_path, num_row_groups
  
      row_groups = (
          spark_context.parallelize(paths, len(paths))
          .map(get_row_group_info)
          .collect()
      )
      num_row_groups_str = json.dumps(dict(row_groups))
      # Add the dict for the number of row groups in each file to the parquet file metadata footer
      utils.add_to_dataset_metadata(
          dataset, ROW_GROUPS_PER_FILE_KEY, num_row_groups_str
      )
  
imports: import json
  import logging
  import os
  from concurrent import futures
  from contextlib import contextmanager
  from operator import attrgetter
  from urllib.parse import urlparse
  from packaging import version
  from pyarrow import parquet
  from six.moves import cPickle
  from petastorm import utils
  from petastorm.etl.legacy import depickle_legacy_package_name_compatible
  from petastorm.fs_utils import FilesystemResolver, get_filesystem_and_path_or_paths, get_dataset_path
  from petastorm.unischema import Unischema
label_desc: Use image node_id 5 for calling a global function with example usage: _generate_num_row_groups_per_file(dataset, spark_context, filesystem_factory) and returns: relative_path,  num_row_groups