code: def from_arrow_type(
      at: "pa.DataType", prefer_timestamp_ntz: bool = False
  ) -> DataType:
      """Convert pyarrow type to Spark data type."""
      import pyarrow.types as types
  
      spark_type: DataType
      if types.is_boolean(at):
          spark_type = BooleanType()
      elif types.is_int8(at):
          spark_type = ByteType()
      elif types.is_int16(at):
          spark_type = ShortType()
      elif types.is_int32(at):
          spark_type = IntegerType()
      elif types.is_int64(at):
          spark_type = LongType()
      elif types.is_float32(at):
          spark_type = FloatType()
      elif types.is_float64(at):
          spark_type = DoubleType()
      elif types.is_decimal(at):
          spark_type = DecimalType(
              precision=at.precision, scale=at.scale
          )
      elif types.is_string(at):
          spark_type = StringType()
      elif types.is_large_string(at):
          spark_type = StringType()
      elif types.is_binary(at):
          spark_type = BinaryType()
      elif types.is_large_binary(at):
          spark_type = BinaryType()
      elif types.is_date32(at):
          spark_type = DateType()
      elif (
          types.is_timestamp(at)
          and prefer_timestamp_ntz
          and at.tz is None
      ):
          spark_type = TimestampNTZType()
      elif types.is_timestamp(at):
          spark_type = TimestampType()
      elif types.is_duration(at):
          spark_type = DayTimeIntervalType()
      elif types.is_list(at):
          spark_type = ArrayType(
              from_arrow_type(at.value_type, prefer_timestamp_ntz)
          )
      elif types.is_map(at):
          spark_type = MapType(
              from_arrow_type(at.key_type, prefer_timestamp_ntz),
              from_arrow_type(at.item_type, prefer_timestamp_ntz),
          )
      elif types.is_struct(at):
          return StructType(
              [
                  StructField(
                      field.name,
                      from_arrow_type(field.type, prefer_timestamp_ntz),
                      nullable=field.nullable,
                  )
                  for field in at
              ]
          )
      elif types.is_dictionary(at):
          spark_type = from_arrow_type(
              at.value_type, prefer_timestamp_ntz
          )
      elif types.is_null(at):
          spark_type = NullType()
      else:
          raise PySparkTypeError(
              error_class="UNSUPPORTED_DATA_TYPE_FOR_ARROW_CONVERSION",
              message_parameters={"data_type": str(at)},
          )
      return spark_type
  
imports: import datetime
  import itertools
  from typing import Any, Callable, Iterable, List, Optional, Union, TYPE_CHECKING
  from pyspark.sql.types import cast, BooleanType, ByteType, ShortType, IntegerType, IntegralType, LongType, FloatType, DoubleType, DecimalType, StringType, BinaryType, DateType, TimestampType, TimestampNTZType, DayTimeIntervalType, ArrayType, MapType, StructType, StructField, NullType, DataType, UserDefinedType, _create_row
  from pyspark.errors import PySparkTypeError, UnsupportedOperationException, PySparkValueError
label_desc: Use image node_id 3 for calling a global function with example usage: from_arrow_type(at, prefer_timestamp_ntz) and returns: spark_type, StructType