code: def row_to_example(  # pylint: disable=invalid-name
      field_to_type: Dict[str, str], field_name_to_data: Dict[str, Any]
  ) -> tf.train.Example:
      """Convert bigquery result row to tf example.
  
      Args:
        field_to_type: The name of the field to its type from BigQuery.
        field_name_to_data: The data need to be converted from BigQuery that
          contains field name and data.
  
      Returns:
        A tf.train.Example that converted from the BigQuery row. Note that BOOLEAN
        type in BigQuery result will be converted to int in tf.train.Example.
  
      Raises:
        RuntimeError: If the data type is not supported to be converted.
          Only INTEGER, BOOLEAN, FLOAT, STRING is supported now.
      """
      feature = {}
      for key, value in field_name_to_data.items():
          data_type = field_to_type[key]
  
          if value is None:
              feature[key] = tf.train.Feature()
              continue
  
          value_list = value if isinstance(value, list) else [value]
          if data_type in ("INTEGER", "BOOLEAN"):
              feature[key] = tf.train.Feature(
                  int64_list=tf.train.Int64List(value=value_list)
              )
          elif data_type == "FLOAT":
              feature[key] = tf.train.Feature(
                  float_list=tf.train.FloatList(value=value_list)
              )
          elif data_type == "STRING":
              feature[key] = tf.train.Feature(
                  bytes_list=tf.train.BytesList(
                      value=[
                          tf.compat.as_bytes(elem)
                          for elem in value_list
                      ]
                  )
              )
          else:
              # TODO(jyzhao): support more types.
              raise RuntimeError(
                  'BigQuery column "{}" has non-supported type {}.'.format(
                      key, data_type
                  )
              )
  
      return tf.train.Example(
          features=tf.train.Features(feature=feature)
      )
  
file_path: tfx/tfx/extensions/google_cloud_big_query/utils.py
imports: from typing import Any, Dict, List, Optional
  import apache_beam
  from apache_beam.io.gcp import bigquery
  from apache_beam.options import value_provider
  import tensorflow
  from tfx.utils import telemetry_utils
label_desc: Use image node_id 2 for calling a global function with example usage: row_to_example(field_to_type, field_name_to_data) and returns: tf