code: def parse_header_block_sample_block_label(
      key: Tuple, key_pattern: List[str]
  ) -> Tuple[str, str, str]:
      """
      Extracts header_block, sample_block, and label from the key corresponding to a group from the groupBy(key_pattern)
      clause.  Key pattern can be one of:
          (header_block, sample_block),
          (header_block, sample_block, label),
          (sample_block, label)
      depending on the context.  In each case, a tuple with 3 members is returned, with the missing member filled in by
      'all' where necessary
  
      Args:
          key : key for the group
          key_pattern : one of the aforementioned key patterns
  
      Returns:
          tuple of (header_block, sample_block, label), where header_block or label may be filled with 'all'
          depending on context.
      """
      if "label" in key_pattern:
          label = key[-1]
      else:
          label = "all"
      if "header_block" in key_pattern:
          header_block = key[0]
          sample_block = key[1]
      else:
          header_block = "all"
          sample_block = key[0]
  
      return header_block, sample_block, label
  
imports: import itertools
  import math
  import re
  import warnings
  from typing import Any, Dict, Iterable, List, Tuple
  import numpy
  import pandas
  import pyspark.sql.functions
  import scipy.optimize
  from nptyping import Float, Int, NDArray
  from pyspark.sql import DataFrame, Row
  from pyspark.sql.window import Window
  from typeguard import typechecked
label_desc: Use image node_id 2 for calling a global function with example usage: parse_header_block_sample_block_label(key, key_pattern) and returns: header_block,  sample_block,  label