code: def _get_feature_value(
      feature: "tf.train.Feature",
      schema_feature_type: Optional["schema_pb2.FeatureType"] = None,
  ) -> "pyarrow.Array":
      import pyarrow as pa
  
      underlying_feature_type = {
          "bytes": feature.HasField("bytes_list"),
          "float": feature.HasField("float_list"),
          "int": feature.HasField("int64_list"),
      }
      # At most one of `bytes_list`, `float_list`, and `int64_list`
      # should contain values. If none contain data, this indicates
      # an empty feature value.
      assert (
          sum(bool(value) for value in underlying_feature_type.values())
          <= 1
      )
  
      if schema_feature_type is not None:
          try:
              from tensorflow_metadata.proto.v0 import schema_pb2
          except ModuleNotFoundError:
              raise ModuleNotFoundError(
                  "To use TensorFlow schemas, please install "
                  "the tensorflow-metadata package."
              )
          # If a schema is specified, compare to the underlying type
          specified_feature_type = {
              "bytes": schema_feature_type
              == schema_pb2.FeatureType.BYTES,
              "float": schema_feature_type
              == schema_pb2.FeatureType.FLOAT,
              "int": schema_feature_type == schema_pb2.FeatureType.INT,
          }
          und_type = _get_single_true_type(underlying_feature_type)
          spec_type = _get_single_true_type(specified_feature_type)
          if und_type is not None and und_type != spec_type:
              raise ValueError(
                  "Schema field type mismatch during read: specified type is "
                  f"{spec_type}, but underlying type is {und_type}",
              )
          # Override the underlying value type with the type in the user-specified schema.
          underlying_feature_type = specified_feature_type
  
      if underlying_feature_type["bytes"]:
          value = feature.bytes_list.value
          type_ = pa.binary()
      elif underlying_feature_type["float"]:
          value = feature.float_list.value
          type_ = pa.float32()
      elif underlying_feature_type["int"]:
          value = feature.int64_list.value
          type_ = pa.int64()
      else:
          value = []
          type_ = pa.null()
      value = list(value)
      if len(value) == 1 and schema_feature_type is None:
          # Use the value itself if the features contains a single value.
          # This is to give better user experience when writing preprocessing UDF on
          # these single-value lists.
          value = value[0]
      else:
          # If the feature value is empty and no type is specified in the user-provided
          # schema, set the type to null for now to allow pyarrow to construct a valid
          # Array; later, infer the type from other records which have non-empty values
          # for the feature.
          if len(value) == 0:
              type_ = pa.null()
          type_ = pa.list_(type_)
      return pa.array([value], type=type_)
  
file_path: ray/python/ray/data/datasource/tfrecords_datasource.py
imports: import struct
  from typing import TYPE_CHECKING, Dict, Iterable, Iterator, List, Optional, Union
  import numpy
  from ray.data.block import Block
  from ray.data.datasource.file_based_datasource import FileBasedDatasource
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 4 for calling a global function with example usage: _get_feature_value(feature, schema_feature_type) and returns: pa