You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env python3# encoding: utf-8importpolarsasplfromsqlalchemyimportTable, MetaData, funcfromsqlalchemy.engineimportcreate_enginefromsqlalchemy.engine.baseimportEnginefromsqlalchemy.ormimportQuery, Session
...
frame=pl.DataFrame(data={'data':range(10)})
OUT_TABLE_NAME:str='transaction_test'withEngineContext(uri=CONNECTION) asengine:
out_table: Table=Table(OUT_TABLE_NAME, MetaData(bind=engine, schema=SCHEMA_NAME), autoload=True)
withSession(bind=engine) assession, session.begin():
foriteminframe.to_dicts():
# Insert values from 0 to 9 sequentiallyprint(item['data'])
ifitem['data']==5:
# This to ensure premature termination# and making sure the session is rolled backraiseValueErrorstatement=out_table.insert(values=[item])
print(statement)
session.execute(statement=statement)
sleep(1)
Description
Insert a sequence of records (each containing an integer) into big query one by one.
Pip Libraries
sqlalchemy==1.4.51 # ORM
sqlalchemy-bigquery==1.9.0 # Dialect for bigquery, need latest Ubuntu version
polars==1.2.1 # Tabular data manipulation
google-cloud-bigquery-storage==2.25.0 # Bigquery storage write client used for inserts
Technology Stack
Python 3.8
Ubuntu 20.04
Before
Before I run the above code, assume the table (in Google Bigquery) is empty.
After
Expected Outcome
The table remains empty, as the session should be rolled back by SQL Alchemy upon the error.
Observed Outcome
The table contains values from 0 to 4, both inclusive.
The text was updated successfully, but these errors were encountered:
Code
Description
Insert a sequence of records (each containing an integer) into big query one by one.
Pip Libraries
Technology Stack
Before
Before I run the above code, assume the table (in Google Bigquery) is empty.
After
Expected Outcome
The table remains empty, as the session should be rolled back by SQL Alchemy upon the error.
Observed Outcome
The table contains values from 0 to 4, both inclusive.
The text was updated successfully, but these errors were encountered: