code: def test_to_sql():
      index = pd.RangeIndex(100, 0, -1, name="index")
      raw = pd.DataFrame(
          {
              "col1": np.random.rand(100),
              "col2": np.random.choice(["a", "b", "c"], (100,)),
              "col3": np.arange(100).astype("int64"),
          },
          index=index,
      )
  
      patch_sa_engine_execute()
      with tempfile.TemporaryDirectory() as d:
          table_name1 = "test_table"
          table_name2 = "test_table2"
          uri = "sqlite:///" + os.path.join(d, "test.db")
  
          engine = sqlalchemy.create_engine(uri)
  
          # test write dataframe
          df = DataFrame(raw, chunk_size=33)
          df.to_sql(table_name1, con=engine).execute()
  
          written = pd.read_sql(
              table_name1, con=engine, index_col="index"
          ).sort_index(ascending=False)
          pd.testing.assert_frame_equal(raw, written)
  
          # test write with existing table
          with pytest.raises(ValueError):
              df.to_sql(table_name1, con=uri).execute()
  
          # test write series
          series = md.Series(raw.col1, chunk_size=33)
          with engine.connect() as conn:
              series.to_sql(table_name2, con=conn).execute()
  
          written = pd.read_sql(
              table_name2, con=engine, index_col="index"
          ).sort_index(ascending=False)
          pd.testing.assert_frame_equal(raw.col1.to_frame(), written)
  
file_path: mars/mars/dataframe/datastore/tests/test_datastore_execution.py
imports: import os
  import tempfile
  import numpy
  import pandas
  import pytest
  from ....None import dataframe
  from ....tests.core import flaky
  from ...None import DataFrame
  from ...utils import patch_sa_engine_execute
label_desc: Use image node_id 2 for calling a global function with example usage: test_to_sql() without return types