code: def paginated_update(
      query: Query,
      print_page_progress: Optional[
          Union[Callable[[int, int], None], bool]
      ] = None,
      batch_size: int = DEFAULT_BATCH_SIZE,
  ) -> Iterator[Any]:
      """
      Update models in small batches so we don't have to load everything in memory.
      """
  
      total = query.count()
      processed = 0
      session: Session = inspect(query).session
      result = session.execute(query)
  
      if print_page_progress is None or print_page_progress is True:
          print_page_progress = lambda processed, total: print(
              f"    {processed}/{total}", end="\r"
          )
  
      while True:
          rows = result.fetchmany(batch_size)
  
          if not rows:
              break
  
          for row in rows:
              yield row[0]
  
          session.commit()
          processed += len(rows)
  
          if print_page_progress:
              print_page_progress(processed, total)
  
file_path: superset/superset/migrations/shared/utils.py
imports: import json
  import logging
  import os
  import time
  from collections.abc import Iterator
  from typing import Any, Callable, Optional, Union
  from uuid import uuid4
  from alembic import op
  from sqlalchemy import engine_from_config, inspect
  from sqlalchemy.dialects.mysql.base import MySQLDialect
  from sqlalchemy.dialects.postgresql.base import PGDialect
  from sqlalchemy.engine import reflection
  from sqlalchemy.exc import NoSuchTableError
  from sqlalchemy.orm import Query, Session
label_desc: Use image node_id 3 for calling a global function with example usage: paginated_update(query, print_page_progress, batch_size) without return types