简体   繁体   中英

Can I set the isolation level of modin's parallel read_sql function?

I have some python code that I am trying to use to read uncommitted from my database in parallel using sqlalchemy and modin. I have tried calling the function as: df = pd.read_sql("select * from my_table", uri_string, params={'isolation_level': 'READ UNCOMMITTED'}) . However, I am seeing the generated queries submitted without an isolation level to my database. Has anyone been able to inject the isolation level without creating an sqlalchemy engine before calling read_sql?

EDIT: Unlike pandas, modin's implementation allows read_sql to run in parallel. Part of that implementation means that whatever query I write will be wrapped into several subqueries like select * from (select * from my_table) limit 100 offset 200; . Therefore, statement level isolation is off the table without adjusting this implementation. Further, this implementation requires an sqlalchemy URI string rather than an engine or connection which can be serialized by many workers. Therefore, I would need to know how to inject the isolation level parameter within the URI string if I were to set the isolation level from the connection string.

Every database transaction for Db2-LUW has an isolation level regardless of whether or not you make it explicit - there is always some default. But if you are connecting to Db2-for-i (as/400) this might not not true.

You make a choice as to how and where you change the isolation level .

For occasional queries you can use statement level isolation (as long as the tooling allows it), where the SELECT statement itself has an optional clause appended to specify the isolation for that statement only. For example select whatever from table where... with UR (uncommitted read).

If you want all dynamic SQL statements to have the same isolation level (where that has a meaning), then you can specify the isolation when you connect to the database. For python, (ie cpython) which uses the CLI interface, you use a CLI setting either on the connection string ;TxnIsolation=1; (for UR), or via the data source definition in db2dsdriver.cfg or db2cli.ini (if using) with the parameter IsolationLevel=... . More details here

If you call (directly or indirectly) any Db2 routines with static packages that are bound with a specific isolation level then this will override any other settings you may have previously set, so be aware.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM