code: def offsets_to_where_statement(start_offset, end_offset):
      assert start_offset != end_offset, str((start_offset, end_offset))
  
      if start_offset is None:
          start_batch_id, start_job_id, start_attempt_id = (
              None,
              None,
              None,
          )
      else:
          start_batch_id, start_job_id, start_attempt_id = start_offset
  
      if end_offset is None:
          end_batch_id, end_job_id, end_attempt_id = None, None, None
      else:
          end_batch_id, end_job_id, end_attempt_id = end_offset
  
      if (
          start_batch_id is None
          or start_job_id is None
          or start_attempt_id is None
      ):
          assert end_batch_id
          where_cond = (
              "WHERE attempts.batch_id < %s OR "
              "(attempts.batch_id = %s AND attempts.job_id < %s) OR "
              "(attempts.batch_id = %s AND attempts.job_id = %s AND attempts.attempt_id < %s)"
          )
          query_args = (
              end_batch_id,
              end_batch_id,
              end_job_id,
              end_batch_id,
              end_job_id,
              end_attempt_id,
          )
      elif (
          end_batch_id is None
          or end_job_id is None
          or end_attempt_id is None
      ):
          assert start_batch_id
          where_cond = (
              "WHERE attempts.batch_id > %s OR "
              "(attempts.batch_id = %s AND attempts.job_id > %s) OR "
              "(attempts.batch_id = %s AND attempts.job_id = %s AND attempts.attempt_id >= %s)"
          )
          query_args = (
              start_batch_id,
              start_batch_id,
              start_job_id,
              start_batch_id,
              start_job_id,
              start_attempt_id,
          )
      else:
          where_cond = (
              "WHERE (attempts.batch_id > %s OR "
              "(attempts.batch_id = %s AND attempts.job_id > %s) OR "
              "(attempts.batch_id = %s AND attempts.job_id = %s AND attempts.attempt_id >= %s)) "
              "AND (attempts.batch_id < %s OR "
              "(attempts.batch_id = %s AND attempts.job_id < %s) OR "
              "(attempts.batch_id = %s AND attempts.job_id = %s AND attempts.attempt_id < %s))"
          )
          query_args = (
              start_batch_id,
              start_batch_id,
              start_job_id,
              start_batch_id,
              start_job_id,
              start_attempt_id,
              end_batch_id,
              end_batch_id,
              end_job_id,
              end_batch_id,
              end_job_id,
              end_attempt_id,
          )
  
      return (where_cond, query_args)
  
file_path: hail/batch/sql/populate_agg_billing_by_date.py
imports: import asyncio
  import functools
  import os
  import random
  import time
  from typing import List, Optional, Tuple
  from gear import Database, transaction
  from hailtop.utils import bounded_gather
label_desc: Use image node_id 1 for calling a global function with example usage: offsets_to_where_statement(start_offset, end_offset) and returns: where_cond,  query_args