code: def _establish_dataclass_or_model_schema(
      first_element: Any,
      schema: SchemaDefinition | None,
      schema_overrides: SchemaDict | None,
      model_fields: list[str] | None,
  ) -> tuple[bool, list[str], SchemaDict, SchemaDict]:
      """Shared utility code for establishing dataclasses/pydantic model cols/schema."""
      from dataclasses import asdict
  
      unpack_nested = False
      if schema:
          column_names, schema_overrides = _unpack_schema(
              schema, schema_overrides=schema_overrides
          )
          overrides = {
              col: schema_overrides.get(col, Unknown)
              for col in column_names
          }
      else:
          column_names = []
          overrides = {
              col: (
                  py_type_to_dtype(tp, raise_unmatched=False) or Unknown
              )
              for col, tp in type_hints(first_element.__class__).items()
              if (
                  (col in model_fields)
                  if model_fields
                  else (col != "__slots__")
              )
          }
          if schema_overrides:
              overrides.update(schema_overrides)
          elif not model_fields:
              dc_fields = set(asdict(first_element))
              schema_overrides = overrides = {
                  nm: tp
                  for nm, tp in overrides.items()
                  if nm in dc_fields
              }
          else:
              schema_overrides = overrides
  
      for col, tp in overrides.items():
          if tp in (Categorical, Enum):
              overrides[col] = String
          elif not unpack_nested and (
              tp.base_type() in (Unknown, Struct)
          ):
              unpack_nested = contains_nested(
                  getattr(first_element, col, None),
                  is_pydantic_model if model_fields else dataclasses.is_dataclass,  # type: ignore[arg-type]
              )
  
      if model_fields and len(model_fields) == len(overrides):
          overrides = dict(zip(model_fields, overrides.values()))
  
      return unpack_nested, column_names, schema_overrides, overrides
  
imports: from __future__ import annotations
  import contextlib
  import warnings
  from datetime import date, datetime, time, timedelta
  from decimal import Decimal
  from functools import lru_cache, singledispatch
  from itertools import islice, zip_longest
  from operator import itemgetter
  from sys import version_info
  from typing import TYPE_CHECKING, Any, Callable, Generator, Iterable, Iterator, Mapping, MutableMapping, Sequence, get_type_hints
  import polars._reexport
  from polars import functions
  from polars.datatypes import INTEGER_DTYPES, N_INFER_DEFAULT, TEMPORAL_DTYPES, Boolean, Categorical, Date, Datetime, Duration, Enum, List, Null, Object, String, Struct, Time, UInt32, Unknown, dtype_to_py_type, is_polars_dtype, numpy_char_code_to_dtype, py_type_to_dtype
  from polars.datatypes.constructor import numpy_type_to_constructor, numpy_values_and_dtype, polars_type_to_constructor, py_type_to_constructor
  from polars.dependencies import _NUMPY_AVAILABLE, _check_for_numpy, _check_for_pandas, _check_for_pydantic, dataclasses, pydantic
  from polars.dependencies import numpy
  from polars.dependencies import pandas
  from polars.dependencies import pyarrow
  from polars.exceptions import ComputeError, ShapeError, TimeZoneAwareConstructorWarning
  from polars.utils._wrap import wrap_df, wrap_s
  from polars.utils.meta import get_index_type, threadpool_size
  from polars.utils.various import _is_generator, arrlen, find_stacklevel, parse_version, range_to_series
label_desc: Use image node_id 33 for calling a global function with example usage: _establish_dataclass_or_model_schema(first_element, schema, schema_overrides, model_fields) and returns: unpack_nested,  column_names,  schema_overrides,  overrides