def METHOD_NAME(table_field, namespace):
  # type: (Dict[Text, Any], str) -> Dict[Text, Any] # noqa: F821
  """Convert a BigQuery field to an avro field.
  Args:
    table_field (Dict[Text, Any]): A BigQuery field in dict form.
  Returns:
    Dict[Text, Any]: An equivalent Avro field in dict form.
  """
  assert "type" in table_field, \
    "Unable to get type for table field {}".format(table_field)
  assert table_field["type"] in BIG_QUERY_TO_AVRO_TYPES, \
    "Unable to map BigQuery field type {} to avro type".format(
      table_field["type"])
  avro_type = BIG_QUERY_TO_AVRO_TYPES[table_field["type"]]
  if avro_type == "record":
    element_type = get_record_schema_from_dict_table_schema(
        table_field["name"],
        table_field,
        namespace=".".join((namespace, table_field["name"])))
  else:
    element_type = avro_type
  field_mode = table_field.get("mode", "NULLABLE")
  if field_mode in (None, "NULLABLE"):
    field_type = ["null", element_type]
  elif field_mode == "REQUIRED":
    field_type = element_type
  elif field_mode == "REPEATED":
    field_type = {"type": "array", "items": element_type}
  else:
    raise ValueError("Unkown BigQuery field mode: {}".format(field_mode))
  avro_field = {"type": field_type, "name": table_field["name"]}
  doc = table_field.get("description")
  if doc:
    avro_field["doc"] = doc
  return avro_field