code: def _compare_tables(
      conn_table_names: set,
      metadata_table_names: set,
      inspector: Inspector,
      upgrade_ops: UpgradeOps,
      autogen_context: AutogenContext,
  ) -> None:
      default_schema = inspector.bind.dialect.default_schema_name
  
      # tables coming from the connection will not have "schema"
      # set if it matches default_schema_name; so we need a list
      # of table names from local metadata that also have "None" if schema
      # == default_schema_name.  Most setups will be like this anyway but
      # some are not (see #170)
      metadata_table_names_no_dflt_schema = OrderedSet(
          [
              (schema if schema != default_schema else None, tname)
              for schema, tname in metadata_table_names
          ]
      )
  
      # to adjust for the MetaData collection storing the tables either
      # as "schemaname.tablename" or just "tablename", create a new lookup
      # which will match the "non-default-schema" keys to the Table object.
      tname_to_table = {
          no_dflt_schema: autogen_context.table_key_to_table[
              sa_schema._get_table_key(tname, schema)
          ]
          for no_dflt_schema, (schema, tname) in zip(
              metadata_table_names_no_dflt_schema, metadata_table_names
          )
      }
      metadata_table_names = metadata_table_names_no_dflt_schema
  
      for s, tname in metadata_table_names.difference(conn_table_names):
          name = "%s.%s" % (s, tname) if s else tname
          metadata_table = tname_to_table[(s, tname)]
          if autogen_context.run_object_filters(
              metadata_table, tname, "table", False, None
          ):
              upgrade_ops.ops.append(
                  ops.CreateTableOp.from_table(metadata_table)
              )
              log.info("Detected added table %r", name)
              modify_table_ops = ops.ModifyTableOps(tname, [], schema=s)
  
              comparators.dispatch("table")(
                  autogen_context,
                  modify_table_ops,
                  s,
                  tname,
                  None,
                  metadata_table,
              )
              if not modify_table_ops.is_empty():
                  upgrade_ops.ops.append(modify_table_ops)
  
      removal_metadata = sa_schema.MetaData()
      for s, tname in conn_table_names.difference(metadata_table_names):
          name = sa_schema._get_table_key(tname, s)
          exists = name in removal_metadata.tables
          t = sa_schema.Table(tname, removal_metadata, schema=s)
  
          if not exists:
              event.listen(
                  t,
                  "column_reflect",
                  # fmt: off
                  autogen_context.migration_context.impl.
                  _compat_autogen_column_reflect
                  (inspector),
                  # fmt: on
              )
              sqla_compat._reflect_table(inspector, t)
          if autogen_context.run_object_filters(
              t, tname, "table", True, None
          ):
              modify_table_ops = ops.ModifyTableOps(tname, [], schema=s)
  
              comparators.dispatch("table")(
                  autogen_context, modify_table_ops, s, tname, t, None
              )
              if not modify_table_ops.is_empty():
                  upgrade_ops.ops.append(modify_table_ops)
  
              upgrade_ops.ops.append(ops.DropTableOp.from_table(t))
              log.info("Detected removed table %r", name)
  
      existing_tables = conn_table_names.intersection(
          metadata_table_names
      )
  
      existing_metadata = sa_schema.MetaData()
      conn_column_info = {}
      for s, tname in existing_tables:
          name = sa_schema._get_table_key(tname, s)
          exists = name in existing_metadata.tables
          t = sa_schema.Table(tname, existing_metadata, schema=s)
          if not exists:
              event.listen(
                  t,
                  "column_reflect",
                  # fmt: off
                  autogen_context.migration_context.impl.
                  _compat_autogen_column_reflect(inspector),
                  # fmt: on
              )
              sqla_compat._reflect_table(inspector, t)
          conn_column_info[(s, tname)] = t
  
      for s, tname in sorted(
          existing_tables, key=lambda x: (x[0] or "", x[1])
      ):
          s = s or None
          name = "%s.%s" % (s, tname) if s else tname
          metadata_table = tname_to_table[(s, tname)]
          conn_table = existing_metadata.tables[name]
  
          if autogen_context.run_object_filters(
              metadata_table, tname, "table", False, conn_table
          ):
              modify_table_ops = ops.ModifyTableOps(tname, [], schema=s)
              with _compare_columns(
                  s,
                  tname,
                  conn_table,
                  metadata_table,
                  modify_table_ops,
                  autogen_context,
                  inspector,
              ):
                  comparators.dispatch("table")(
                      autogen_context,
                      modify_table_ops,
                      s,
                      tname,
                      conn_table,
                      metadata_table,
                  )
  
              if not modify_table_ops.is_empty():
                  upgrade_ops.ops.append(modify_table_ops)
  
imports: from __future__ import annotations
  import contextlib
  import logging
  import re
  from typing import Any
  from typing import cast
  from typing import Dict
  from typing import Iterator
  from typing import Mapping
  from typing import Optional
  from typing import Set
  from typing import Tuple
  from typing import TYPE_CHECKING
  from typing import TypeVar
  from typing import Union
  from sqlalchemy import event
  from sqlalchemy import inspect
  from sqlalchemy import schema
  from sqlalchemy import text
  from sqlalchemy import types
  from sqlalchemy.sql import expression
  from sqlalchemy.sql.schema import ForeignKeyConstraint
  from sqlalchemy.sql.schema import Index
  from sqlalchemy.sql.schema import UniqueConstraint
  from sqlalchemy.util import OrderedSet
  from ..None import util
  from ..ddl._autogen import is_index_sig
  from ..ddl._autogen import is_uq_sig
  from ..operations import ops
  from ..util import sqla_compat
label_desc: Use image node_id 4 for calling a global function with example usage: _compare_tables(conn_table_names, metadata_table_names, inspector, upgrade_ops, autogen_context) without return types