docstr: Writes the pyarrow table as SQL to a database.
  
  Caller is responsible for opening and closing the SQL connection.
docstr_tok: ["Writes","the","pyarrow","table","as","SQL","to","a","database",".","Caller","is","responsible","for","opening","and","closing","the","SQL","connection","."]
code: def _write(self, index, **to_sql_kwargs) -> int:
      """Writes the pyarrow table as SQL to a database.
  
      Caller is responsible for opening and closing the SQL connection.
      """
      written = 0
  
      if self.num_proc is None or self.num_proc == 1:
          for offset in hf_tqdm(
              range(0, len(self.dataset), self.batch_size),
              unit="ba",
              desc="Creating SQL from Arrow format",
          ):
              written += self._batch_sql((offset, index, to_sql_kwargs))
      else:
          num_rows, batch_size = len(self.dataset), self.batch_size
          with multiprocessing.Pool(self.num_proc) as pool:
              for num_rows in hf_tqdm(
                  pool.imap(
                      self._batch_sql,
                      [
                          (offset, index, to_sql_kwargs)
                          for offset in range(0, num_rows, batch_size)
                      ],
                  ),
                  total=(num_rows // batch_size) + 1
                  if num_rows % batch_size
                  else num_rows // batch_size,
                  unit="ba",
                  desc="Creating SQL from Arrow format",
              ):
                  written += num_rows
  
      return written
  
file_path: datasets/src/datasets/io/sql.py
imports: import multiprocessing
  from typing import TYPE_CHECKING, Optional, Union
  from ..None import Dataset, Features, config
  from ..formatting import query_table
  from ..packaged_modules.sql.sql import Sql
  from ..utils import tqdm
  from .abc import AbstractDatasetInputStream
label_desc: Use image node_id 4 for calling the SqlDatasetWriter obj's underlying member method code with example usage: obj._write(index) and returns: written