code: def _get_context_from_context_query(
      store: mlmd.MetadataStore,
      context_query: pipeline_pb2.InputSpec.Channel.ContextQuery,
  ) -> Optional[metadata_store_pb2.Context]:
      """Get Context from InputSpec.Channel.ContextQuery."""
      if (
          not context_query.HasField("type")
          or not context_query.type.name
      ):
          raise ValueError("ContextQuery.type.name should be set.")
      if (
          not context_query.name
          or not context_query.name.field_value
          or not context_query.name.field_value.string_value
      ):
          raise ValueError(
              "ContextQuery.name.field_value.string_value should be set."
          )
      if context_query.HasField("property_predicate"):
          logging.warning(
              "ContextQuery.property_predicate is not supported."
          )
      return store.get_context_by_type_and_name(
          context_query.type.name,
          context_query.name.field_value.string_value,
      )
  
file_path: tfx/tfx/orchestration/portable/input_resolution/channel_resolver.py
imports: from typing import List, Optional, Sequence, Tuple
  from absl import logging
  from tfx import types
  from tfx.orchestration import mlmd_connection_manager
  from tfx.orchestration.portable.mlmd import event_lib
  from tfx.proto.orchestration import pipeline_pb2
  from tfx.types import artifact_utils
  import ml_metadata
  from ml_metadata import errors
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: _get_context_from_context_query(store, context_query) and returns: store