Skip to content

Commit

Permalink
temporary files for reading/writing
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonStoykovQC committed Oct 2, 2023
1 parent c1e7f8e commit f5c461b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
29 changes: 29 additions & 0 deletions x_read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import turbodbc
from time import perf_counter


def turbodbc_read_sql(
query: str, turbodbc_connection: turbodbc.connection.Connection
):
with turbodbc_connection.cursor() as cursor:
cursor.execute(query)
return cursor.fetchallarrow().to_pandas()


def mssql_connect_turbodbc() -> turbodbc.connection.Connection:
odbc_string = "Driver={libtdsodbc.so};Server=localhost,1433;Database=turbodbc;Encrypt=yes;TrustServerCertificate=no;UID=sa;PWD=QuantCo123"
conn_string_components = {
x.split("=")[0].lower(): x.split("=")[1] for x in odbc_string.split(";")
}
return turbodbc.connect(
**conn_string_components,
turbodbc_options=turbodbc.make_options(
prefer_unicode=True, large_decimals_as_64_bit_types=True
),
)


connection = mssql_connect_turbodbc()
start = perf_counter()
turbodbc_read_sql("SELECT * FROM turbodbc.dbo.single_big", connection)
print("Elapsed seconds:", perf_counter() - start)
21 changes: 21 additions & 0 deletions x_write.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sqlalchemy as sa

print("Hey")

ROWS = 1_000_000
AT_ONCE = 1

eng = sa.create_engine("mssql+pyodbc://sa:QuantCo123@localhost:1433/turbodbc?driver=libtdsodbc.so")

with eng.begin() as transaction:
transaction.execute(sa.text("DELETE FROM single_big"))
last = None
for idx in range(0, ROWS, AT_ONCE):
percentage = int(idx/ROWS * 100)
if percentage % 10 == 0 and percentage != last:
last = percentage
print(percentage)

value = "a" * 8_000
param = ", ".join([f"('{value}') "] * AT_ONCE)
transaction.execute(sa.text(f"INSERT INTO single_big VALUES {param}"))

0 comments on commit f5c461b

Please sign in to comment.