sqlspec 0.72.0__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 6b29784d6b1cafc66758__mypyc.cp315-win_amd64.pyd +0 -0
- sqlspec/__init__.py +381 -0
- sqlspec/__main__.py +14 -0
- sqlspec/__metadata__.py +14 -0
- sqlspec/_typing.py +775 -0
- sqlspec/adapters/__init__.py +3 -0
- sqlspec/adapters/adbc/__init__.py +16 -0
- sqlspec/adapters/adbc/_typing.py +221 -0
- sqlspec/adapters/adbc/adk/__init__.py +11 -0
- sqlspec/adapters/adbc/adk/store.py +4101 -0
- sqlspec/adapters/adbc/config.py +843 -0
- sqlspec/adapters/adbc/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/core.py +3209 -0
- sqlspec/adapters/adbc/data_dictionary.py +1448 -0
- sqlspec/adapters/adbc/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/driver.py +1400 -0
- sqlspec/adapters/adbc/events/__init__.py +5 -0
- sqlspec/adapters/adbc/events/store.py +384 -0
- sqlspec/adapters/adbc/litestar/__init__.py +5 -0
- sqlspec/adapters/adbc/litestar/store.py +962 -0
- sqlspec/adapters/adbc/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/pool.py +242 -0
- sqlspec/adapters/adbc/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/type_converter.py +117 -0
- sqlspec/adapters/aiomysql/__init__.py +25 -0
- sqlspec/adapters/aiomysql/_typing.py +134 -0
- sqlspec/adapters/aiomysql/adk/__init__.py +5 -0
- sqlspec/adapters/aiomysql/adk/store.py +1542 -0
- sqlspec/adapters/aiomysql/config.py +634 -0
- sqlspec/adapters/aiomysql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiomysql/core.py +922 -0
- sqlspec/adapters/aiomysql/data_dictionary.py +16 -0
- sqlspec/adapters/aiomysql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiomysql/driver.py +494 -0
- sqlspec/adapters/aiomysql/events/__init__.py +5 -0
- sqlspec/adapters/aiomysql/events/store.py +72 -0
- sqlspec/adapters/aiomysql/litestar/__init__.py +5 -0
- sqlspec/adapters/aiomysql/litestar/store.py +345 -0
- sqlspec/adapters/aiosqlite/__init__.py +43 -0
- sqlspec/adapters/aiosqlite/_typing.py +75 -0
- sqlspec/adapters/aiosqlite/adk/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/adk/store.py +1546 -0
- sqlspec/adapters/aiosqlite/config.py +607 -0
- sqlspec/adapters/aiosqlite/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/core.py +1155 -0
- sqlspec/adapters/aiosqlite/data_dictionary.py +343 -0
- sqlspec/adapters/aiosqlite/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/driver.py +559 -0
- sqlspec/adapters/aiosqlite/events/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/events/store.py +54 -0
- sqlspec/adapters/aiosqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/litestar/store.py +315 -0
- sqlspec/adapters/aiosqlite/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/pool.py +1323 -0
- sqlspec/adapters/aiosqlite/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/type_converter.py +114 -0
- sqlspec/adapters/arrow_odbc/__init__.py +32 -0
- sqlspec/adapters/arrow_odbc/_typing.py +131 -0
- sqlspec/adapters/arrow_odbc/adk/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/adk/store.py +1671 -0
- sqlspec/adapters/arrow_odbc/config.py +446 -0
- sqlspec/adapters/arrow_odbc/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/core.py +795 -0
- sqlspec/adapters/arrow_odbc/data_dictionary.py +345 -0
- sqlspec/adapters/arrow_odbc/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/driver.py +885 -0
- sqlspec/adapters/arrow_odbc/events/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/events/store.py +114 -0
- sqlspec/adapters/arrow_odbc/litestar/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/litestar/store.py +682 -0
- sqlspec/adapters/arrow_odbc/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/type_converter.py +95 -0
- sqlspec/adapters/asyncmy/__init__.py +27 -0
- sqlspec/adapters/asyncmy/_typing.py +215 -0
- sqlspec/adapters/asyncmy/adk/__init__.py +5 -0
- sqlspec/adapters/asyncmy/adk/store.py +1544 -0
- sqlspec/adapters/asyncmy/config.py +707 -0
- sqlspec/adapters/asyncmy/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncmy/core.py +917 -0
- sqlspec/adapters/asyncmy/data_dictionary.py +16 -0
- sqlspec/adapters/asyncmy/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncmy/driver.py +529 -0
- sqlspec/adapters/asyncmy/events/__init__.py +5 -0
- sqlspec/adapters/asyncmy/events/store.py +72 -0
- sqlspec/adapters/asyncmy/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncmy/litestar/store.py +348 -0
- sqlspec/adapters/asyncpg/__init__.py +28 -0
- sqlspec/adapters/asyncpg/_typing.py +113 -0
- sqlspec/adapters/asyncpg/adk/__init__.py +5 -0
- sqlspec/adapters/asyncpg/adk/store.py +1145 -0
- sqlspec/adapters/asyncpg/config.py +903 -0
- sqlspec/adapters/asyncpg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/core.py +797 -0
- sqlspec/adapters/asyncpg/data_dictionary.py +417 -0
- sqlspec/adapters/asyncpg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/driver.py +927 -0
- sqlspec/adapters/asyncpg/events/__init__.py +6 -0
- sqlspec/adapters/asyncpg/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/events/_hub.py +279 -0
- sqlspec/adapters/asyncpg/events/backend.py +410 -0
- sqlspec/adapters/asyncpg/events/store.py +57 -0
- sqlspec/adapters/asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncpg/litestar/store.py +278 -0
- sqlspec/adapters/asyncpg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/tenant.py +140 -0
- sqlspec/adapters/bigquery/__init__.py +23 -0
- sqlspec/adapters/bigquery/_typing.py +184 -0
- sqlspec/adapters/bigquery/adk/__init__.py +5 -0
- sqlspec/adapters/bigquery/adk/store.py +920 -0
- sqlspec/adapters/bigquery/config.py +631 -0
- sqlspec/adapters/bigquery/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/core.py +1433 -0
- sqlspec/adapters/bigquery/data_dictionary.py +502 -0
- sqlspec/adapters/bigquery/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/driver.py +1266 -0
- sqlspec/adapters/bigquery/events/__init__.py +5 -0
- sqlspec/adapters/bigquery/events/store.py +158 -0
- sqlspec/adapters/bigquery/litestar/__init__.py +5 -0
- sqlspec/adapters/bigquery/litestar/store.py +359 -0
- sqlspec/adapters/cockroach_asyncpg/__init__.py +32 -0
- sqlspec/adapters/cockroach_asyncpg/_typing.py +54 -0
- sqlspec/adapters/cockroach_asyncpg/adk/__init__.py +9 -0
- sqlspec/adapters/cockroach_asyncpg/adk/store.py +1096 -0
- sqlspec/adapters/cockroach_asyncpg/config.py +653 -0
- sqlspec/adapters/cockroach_asyncpg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/core.py +835 -0
- sqlspec/adapters/cockroach_asyncpg/data_dictionary.py +371 -0
- sqlspec/adapters/cockroach_asyncpg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/driver.py +438 -0
- sqlspec/adapters/cockroach_asyncpg/events/__init__.py +5 -0
- sqlspec/adapters/cockroach_asyncpg/events/store.py +20 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/store.py +203 -0
- sqlspec/adapters/cockroach_asyncpg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/tenant.py +143 -0
- sqlspec/adapters/cockroach_psycopg/__init__.py +46 -0
- sqlspec/adapters/cockroach_psycopg/_typing.py +271 -0
- sqlspec/adapters/cockroach_psycopg/adk/__init__.py +17 -0
- sqlspec/adapters/cockroach_psycopg/adk/store.py +2274 -0
- sqlspec/adapters/cockroach_psycopg/config.py +1285 -0
- sqlspec/adapters/cockroach_psycopg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/core.py +667 -0
- sqlspec/adapters/cockroach_psycopg/data_dictionary.py +622 -0
- sqlspec/adapters/cockroach_psycopg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/driver.py +864 -0
- sqlspec/adapters/cockroach_psycopg/events/__init__.py +8 -0
- sqlspec/adapters/cockroach_psycopg/events/store.py +34 -0
- sqlspec/adapters/cockroach_psycopg/litestar/__init__.py +9 -0
- sqlspec/adapters/cockroach_psycopg/litestar/store.py +413 -0
- sqlspec/adapters/cockroach_psycopg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/tenant.py +222 -0
- sqlspec/adapters/db2/__init__.py +34 -0
- sqlspec/adapters/db2/_typing.py +357 -0
- sqlspec/adapters/db2/adk/__init__.py +10 -0
- sqlspec/adapters/db2/adk/store.py +1950 -0
- sqlspec/adapters/db2/config.py +550 -0
- sqlspec/adapters/db2/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/core.py +1021 -0
- sqlspec/adapters/db2/data_dictionary.py +493 -0
- sqlspec/adapters/db2/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/driver.py +898 -0
- sqlspec/adapters/db2/events/__init__.py +5 -0
- sqlspec/adapters/db2/events/store.py +77 -0
- sqlspec/adapters/db2/litestar/__init__.py +5 -0
- sqlspec/adapters/db2/litestar/store.py +519 -0
- sqlspec/adapters/db2/migrations.py +221 -0
- sqlspec/adapters/db2/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/pool.py +876 -0
- sqlspec/adapters/db2/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/tenant.py +292 -0
- sqlspec/adapters/duckdb/__init__.py +30 -0
- sqlspec/adapters/duckdb/_typing.py +182 -0
- sqlspec/adapters/duckdb/adk/__init__.py +10 -0
- sqlspec/adapters/duckdb/adk/store.py +1672 -0
- sqlspec/adapters/duckdb/config.py +506 -0
- sqlspec/adapters/duckdb/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/core.py +1299 -0
- sqlspec/adapters/duckdb/data_dictionary.py +553 -0
- sqlspec/adapters/duckdb/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/driver.py +1214 -0
- sqlspec/adapters/duckdb/events/__init__.py +5 -0
- sqlspec/adapters/duckdb/events/store.py +38 -0
- sqlspec/adapters/duckdb/litestar/__init__.py +5 -0
- sqlspec/adapters/duckdb/litestar/store.py +313 -0
- sqlspec/adapters/duckdb/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/pool.py +1121 -0
- sqlspec/adapters/mssql_python/__init__.py +42 -0
- sqlspec/adapters/mssql_python/_typing.py +135 -0
- sqlspec/adapters/mssql_python/adk/__init__.py +5 -0
- sqlspec/adapters/mssql_python/adk/store.py +1278 -0
- sqlspec/adapters/mssql_python/config.py +455 -0
- sqlspec/adapters/mssql_python/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/core.py +862 -0
- sqlspec/adapters/mssql_python/data_dictionary.py +417 -0
- sqlspec/adapters/mssql_python/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/driver.py +772 -0
- sqlspec/adapters/mssql_python/events/__init__.py +5 -0
- sqlspec/adapters/mssql_python/events/store.py +46 -0
- sqlspec/adapters/mssql_python/litestar/__init__.py +5 -0
- sqlspec/adapters/mssql_python/litestar/store.py +355 -0
- sqlspec/adapters/mssql_python/migrations.py +162 -0
- sqlspec/adapters/mssql_python/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/pool.py +165 -0
- sqlspec/adapters/mssql_python/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/tenant.py +74 -0
- sqlspec/adapters/mssql_python/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/type_converter.py +98 -0
- sqlspec/adapters/mysqlconnector/__init__.py +47 -0
- sqlspec/adapters/mysqlconnector/_typing.py +205 -0
- sqlspec/adapters/mysqlconnector/adk/__init__.py +17 -0
- sqlspec/adapters/mysqlconnector/adk/store.py +2503 -0
- sqlspec/adapters/mysqlconnector/config.py +925 -0
- sqlspec/adapters/mysqlconnector/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mysqlconnector/core.py +1075 -0
- sqlspec/adapters/mysqlconnector/data_dictionary.py +23 -0
- sqlspec/adapters/mysqlconnector/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mysqlconnector/driver.py +702 -0
- sqlspec/adapters/mysqlconnector/events/__init__.py +8 -0
- sqlspec/adapters/mysqlconnector/events/store.py +89 -0
- sqlspec/adapters/mysqlconnector/litestar/__init__.py +9 -0
- sqlspec/adapters/mysqlconnector/litestar/store.py +524 -0
- sqlspec/adapters/oracledb/__init__.py +159 -0
- sqlspec/adapters/oracledb/_json_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_json_handlers.py +208 -0
- sqlspec/adapters/oracledb/_param_types.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_param_types.py +65 -0
- sqlspec/adapters/oracledb/_plugins.py +137 -0
- sqlspec/adapters/oracledb/_storage.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_storage.py +138 -0
- sqlspec/adapters/oracledb/_typing.py +468 -0
- sqlspec/adapters/oracledb/_uuid_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_uuid_handlers.py +143 -0
- sqlspec/adapters/oracledb/_vector_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_vector_handlers.py +252 -0
- sqlspec/adapters/oracledb/adk/__init__.py +27 -0
- sqlspec/adapters/oracledb/adk/store.py +4031 -0
- sqlspec/adapters/oracledb/config.py +1785 -0
- sqlspec/adapters/oracledb/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/core.py +5416 -0
- sqlspec/adapters/oracledb/data_dictionary.py +1264 -0
- sqlspec/adapters/oracledb/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/driver.py +3273 -0
- sqlspec/adapters/oracledb/events/__init__.py +29 -0
- sqlspec/adapters/oracledb/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/events/_hub.py +394 -0
- sqlspec/adapters/oracledb/events/backend.py +311 -0
- sqlspec/adapters/oracledb/events/store.py +842 -0
- sqlspec/adapters/oracledb/litestar/__init__.py +17 -0
- sqlspec/adapters/oracledb/litestar/store.py +862 -0
- sqlspec/adapters/oracledb/migrations.py +650 -0
- sqlspec/adapters/oracledb/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/tenant.py +990 -0
- sqlspec/adapters/oracledb/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/type_converter.py +93 -0
- sqlspec/adapters/psqlpy/__init__.py +21 -0
- sqlspec/adapters/psqlpy/_typing.py +180 -0
- sqlspec/adapters/psqlpy/adk/__init__.py +5 -0
- sqlspec/adapters/psqlpy/adk/store.py +1514 -0
- sqlspec/adapters/psqlpy/config.py +828 -0
- sqlspec/adapters/psqlpy/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/core.py +1040 -0
- sqlspec/adapters/psqlpy/data_dictionary.py +399 -0
- sqlspec/adapters/psqlpy/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/driver.py +631 -0
- sqlspec/adapters/psqlpy/events/__init__.py +12 -0
- sqlspec/adapters/psqlpy/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/events/_hub.py +367 -0
- sqlspec/adapters/psqlpy/events/backend.py +415 -0
- sqlspec/adapters/psqlpy/events/store.py +46 -0
- sqlspec/adapters/psqlpy/litestar/__init__.py +5 -0
- sqlspec/adapters/psqlpy/litestar/store.py +270 -0
- sqlspec/adapters/psqlpy/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/tenant.py +137 -0
- sqlspec/adapters/psqlpy/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/type_converter.py +21 -0
- sqlspec/adapters/psycopg/__init__.py +44 -0
- sqlspec/adapters/psycopg/_typing.py +408 -0
- sqlspec/adapters/psycopg/adk/__init__.py +17 -0
- sqlspec/adapters/psycopg/adk/store.py +2761 -0
- sqlspec/adapters/psycopg/config.py +1522 -0
- sqlspec/adapters/psycopg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/core.py +1001 -0
- sqlspec/adapters/psycopg/data_dictionary.py +701 -0
- sqlspec/adapters/psycopg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/driver.py +1629 -0
- sqlspec/adapters/psycopg/events/__init__.py +25 -0
- sqlspec/adapters/psycopg/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/events/_hub.py +646 -0
- sqlspec/adapters/psycopg/events/backend.py +739 -0
- sqlspec/adapters/psycopg/events/store.py +82 -0
- sqlspec/adapters/psycopg/litestar/__init__.py +5 -0
- sqlspec/adapters/psycopg/litestar/store.py +595 -0
- sqlspec/adapters/psycopg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/tenant.py +226 -0
- sqlspec/adapters/psycopg/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/type_converter.py +94 -0
- sqlspec/adapters/pymssql/__init__.py +29 -0
- sqlspec/adapters/pymssql/_typing.py +156 -0
- sqlspec/adapters/pymssql/adk/__init__.py +5 -0
- sqlspec/adapters/pymssql/adk/store.py +1270 -0
- sqlspec/adapters/pymssql/config.py +299 -0
- sqlspec/adapters/pymssql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/core.py +527 -0
- sqlspec/adapters/pymssql/data_dictionary.py +417 -0
- sqlspec/adapters/pymssql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/driver.py +527 -0
- sqlspec/adapters/pymssql/events/__init__.py +5 -0
- sqlspec/adapters/pymssql/events/store.py +46 -0
- sqlspec/adapters/pymssql/litestar/__init__.py +5 -0
- sqlspec/adapters/pymssql/litestar/store.py +350 -0
- sqlspec/adapters/pymssql/migrations.py +162 -0
- sqlspec/adapters/pymssql/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/pool.py +417 -0
- sqlspec/adapters/pymssql/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/tenant.py +73 -0
- sqlspec/adapters/pymysql/__init__.py +27 -0
- sqlspec/adapters/pymysql/_typing.py +105 -0
- sqlspec/adapters/pymysql/adk/__init__.py +5 -0
- sqlspec/adapters/pymysql/adk/store.py +1646 -0
- sqlspec/adapters/pymysql/config.py +545 -0
- sqlspec/adapters/pymysql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/core.py +909 -0
- sqlspec/adapters/pymysql/data_dictionary.py +16 -0
- sqlspec/adapters/pymysql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/driver.py +370 -0
- sqlspec/adapters/pymysql/events/__init__.py +5 -0
- sqlspec/adapters/pymysql/events/store.py +42 -0
- sqlspec/adapters/pymysql/litestar/__init__.py +5 -0
- sqlspec/adapters/pymysql/litestar/store.py +299 -0
- sqlspec/adapters/pymysql/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/pool.py +480 -0
- sqlspec/adapters/snowflake/__init__.py +36 -0
- sqlspec/adapters/snowflake/_typing.py +62 -0
- sqlspec/adapters/snowflake/adk/__init__.py +5 -0
- sqlspec/adapters/snowflake/adk/store.py +778 -0
- sqlspec/adapters/snowflake/config.py +333 -0
- sqlspec/adapters/snowflake/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/core.py +683 -0
- sqlspec/adapters/snowflake/data_dictionary.py +355 -0
- sqlspec/adapters/snowflake/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/driver.py +872 -0
- sqlspec/adapters/snowflake/events/__init__.py +5 -0
- sqlspec/adapters/snowflake/events/store.py +28 -0
- sqlspec/adapters/snowflake/litestar/__init__.py +5 -0
- sqlspec/adapters/snowflake/litestar/store.py +162 -0
- sqlspec/adapters/snowflake/migrations.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/migrations.py +76 -0
- sqlspec/adapters/snowflake/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/pool.py +385 -0
- sqlspec/adapters/snowflake/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/tenant.py +200 -0
- sqlspec/adapters/snowflake/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/type_converter.py +33 -0
- sqlspec/adapters/spanner/__init__.py +57 -0
- sqlspec/adapters/spanner/_typing.py +300 -0
- sqlspec/adapters/spanner/adk/__init__.py +22 -0
- sqlspec/adapters/spanner/adk/artifact_store.py +693 -0
- sqlspec/adapters/spanner/adk/store.py +3053 -0
- sqlspec/adapters/spanner/config.py +1578 -0
- sqlspec/adapters/spanner/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/core.py +1244 -0
- sqlspec/adapters/spanner/data_dictionary.py +706 -0
- sqlspec/adapters/spanner/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/driver.py +1673 -0
- sqlspec/adapters/spanner/events/__init__.py +5 -0
- sqlspec/adapters/spanner/events/store.py +357 -0
- sqlspec/adapters/spanner/litestar/__init__.py +5 -0
- sqlspec/adapters/spanner/litestar/store.py +570 -0
- sqlspec/adapters/spanner/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/type_converter.py +466 -0
- sqlspec/adapters/sqlanywhere/__init__.py +40 -0
- sqlspec/adapters/sqlanywhere/_typing.py +139 -0
- sqlspec/adapters/sqlanywhere/adk/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/adk/store.py +1136 -0
- sqlspec/adapters/sqlanywhere/config.py +359 -0
- sqlspec/adapters/sqlanywhere/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/core.py +583 -0
- sqlspec/adapters/sqlanywhere/data_dictionary.py +282 -0
- sqlspec/adapters/sqlanywhere/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/driver.py +480 -0
- sqlspec/adapters/sqlanywhere/events/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/events/store.py +28 -0
- sqlspec/adapters/sqlanywhere/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/litestar/store.py +237 -0
- sqlspec/adapters/sqlanywhere/migrations.py +178 -0
- sqlspec/adapters/sqlanywhere/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/pool.py +397 -0
- sqlspec/adapters/sqlite/__init__.py +32 -0
- sqlspec/adapters/sqlite/_typing.py +91 -0
- sqlspec/adapters/sqlite/adk/__init__.py +5 -0
- sqlspec/adapters/sqlite/adk/store.py +1628 -0
- sqlspec/adapters/sqlite/config.py +520 -0
- sqlspec/adapters/sqlite/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/core.py +1035 -0
- sqlspec/adapters/sqlite/data_dictionary.py +327 -0
- sqlspec/adapters/sqlite/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/driver.py +432 -0
- sqlspec/adapters/sqlite/events/__init__.py +5 -0
- sqlspec/adapters/sqlite/events/store.py +54 -0
- sqlspec/adapters/sqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlite/litestar/store.py +367 -0
- sqlspec/adapters/sqlite/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/pool.py +935 -0
- sqlspec/adapters/sqlite/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/type_converter.py +114 -0
- sqlspec/adapters/sybase/__init__.py +37 -0
- sqlspec/adapters/sybase/_typing.py +150 -0
- sqlspec/adapters/sybase/adk/__init__.py +5 -0
- sqlspec/adapters/sybase/adk/store.py +1370 -0
- sqlspec/adapters/sybase/config.py +276 -0
- sqlspec/adapters/sybase/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/core.py +578 -0
- sqlspec/adapters/sybase/data_dictionary.py +358 -0
- sqlspec/adapters/sybase/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/driver.py +497 -0
- sqlspec/adapters/sybase/events/__init__.py +5 -0
- sqlspec/adapters/sybase/events/store.py +88 -0
- sqlspec/adapters/sybase/litestar/__init__.py +5 -0
- sqlspec/adapters/sybase/litestar/store.py +328 -0
- sqlspec/adapters/sybase/migrations.py +178 -0
- sqlspec/adapters/sybase/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/pool.py +435 -0
- sqlspec/adapters/teradata/__init__.py +59 -0
- sqlspec/adapters/teradata/_typing.py +145 -0
- sqlspec/adapters/teradata/adk/__init__.py +5 -0
- sqlspec/adapters/teradata/adk/store.py +1300 -0
- sqlspec/adapters/teradata/config.py +324 -0
- sqlspec/adapters/teradata/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/core.py +437 -0
- sqlspec/adapters/teradata/data_dictionary.py +316 -0
- sqlspec/adapters/teradata/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/driver.py +721 -0
- sqlspec/adapters/teradata/events/__init__.py +5 -0
- sqlspec/adapters/teradata/events/store.py +64 -0
- sqlspec/adapters/teradata/litestar/__init__.py +5 -0
- sqlspec/adapters/teradata/litestar/store.py +264 -0
- sqlspec/adapters/teradata/migrations.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/migrations.py +80 -0
- sqlspec/adapters/teradata/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/pool.py +377 -0
- sqlspec/adapters/teradata/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/type_converter.py +95 -0
- sqlspec/base.cp315-win_amd64.pyd +0 -0
- sqlspec/base.py +1275 -0
- sqlspec/builder/__init__.py +330 -0
- sqlspec/builder/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_base.py +1752 -0
- sqlspec/builder/_column.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_column.py +508 -0
- sqlspec/builder/_ddl.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_ddl.py +4503 -0
- sqlspec/builder/_delete.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_delete.py +75 -0
- sqlspec/builder/_dml.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_dml.py +639 -0
- sqlspec/builder/_explain.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_explain.py +650 -0
- sqlspec/builder/_expression_wrappers.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_expression_wrappers.py +77 -0
- sqlspec/builder/_factory.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_factory.py +1834 -0
- sqlspec/builder/_generation.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_generation.py +55 -0
- sqlspec/builder/_insert.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_insert.py +308 -0
- sqlspec/builder/_join.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_join.py +501 -0
- sqlspec/builder/_locking.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_locking.py +77 -0
- sqlspec/builder/_merge.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_merge.py +1047 -0
- sqlspec/builder/_parsing_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_parsing_utils.py +1197 -0
- sqlspec/builder/_select.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_select.py +1514 -0
- sqlspec/builder/_temporal.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_temporal.py +183 -0
- sqlspec/builder/_update.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_update.py +139 -0
- sqlspec/builder/_values.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_values.py +271 -0
- sqlspec/builder/_vector_distance.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_vector_distance.py +763 -0
- sqlspec/cli.py +1656 -0
- sqlspec/config.py +3402 -0
- sqlspec/core/__init__.py +542 -0
- sqlspec/core/_cursor.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_cursor.py +564 -0
- sqlspec/core/_operators.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_operators.py +167 -0
- sqlspec/core/_ordering.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_ordering.py +151 -0
- sqlspec/core/_pagination.py +66 -0
- sqlspec/core/_pipeline.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_pipeline.py +343 -0
- sqlspec/core/_pool.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_pool.py +72 -0
- sqlspec/core/cache.cp315-win_amd64.pyd +0 -0
- sqlspec/core/cache.py +1503 -0
- sqlspec/core/capabilities.cp315-win_amd64.pyd +0 -0
- sqlspec/core/capabilities.py +67 -0
- sqlspec/core/compiler.cp315-win_amd64.pyd +0 -0
- sqlspec/core/compiler.py +1667 -0
- sqlspec/core/config_runtime.cp315-win_amd64.pyd +0 -0
- sqlspec/core/config_runtime.py +219 -0
- sqlspec/core/correlation.cp315-win_amd64.pyd +0 -0
- sqlspec/core/correlation.py +135 -0
- sqlspec/core/explain.cp315-win_amd64.pyd +0 -0
- sqlspec/core/explain.py +284 -0
- sqlspec/core/filters.cp315-win_amd64.pyd +0 -0
- sqlspec/core/filters.py +1442 -0
- sqlspec/core/hashing.cp315-win_amd64.pyd +0 -0
- sqlspec/core/hashing.py +394 -0
- sqlspec/core/metrics.cp315-win_amd64.pyd +0 -0
- sqlspec/core/metrics.py +86 -0
- sqlspec/core/parameters/__init__.py +174 -0
- sqlspec/core/parameters/_alignment.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_alignment.py +321 -0
- sqlspec/core/parameters/_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_converter.py +956 -0
- sqlspec/core/parameters/_declared.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_declared.py +154 -0
- sqlspec/core/parameters/_processor.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_processor.py +1646 -0
- sqlspec/core/parameters/_registry.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_registry.py +207 -0
- sqlspec/core/parameters/_transformers.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_transformers.py +318 -0
- sqlspec/core/parameters/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_types.py +658 -0
- sqlspec/core/parameters/_validator.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_validator.py +699 -0
- sqlspec/core/query_modifiers.cp315-win_amd64.pyd +0 -0
- sqlspec/core/query_modifiers.py +559 -0
- sqlspec/core/result/__init__.py +67 -0
- sqlspec/core/result/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/core/result/_base.py +1772 -0
- sqlspec/core/routing.cp315-win_amd64.pyd +0 -0
- sqlspec/core/routing.py +270 -0
- sqlspec/core/splitter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/splitter.py +1126 -0
- sqlspec/core/sqlcommenter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/sqlcommenter.py +509 -0
- sqlspec/core/stack.cp315-win_amd64.pyd +0 -0
- sqlspec/core/stack.py +167 -0
- sqlspec/core/statement.cp315-win_amd64.pyd +0 -0
- sqlspec/core/statement.py +2253 -0
- sqlspec/core/tenant/__init__.py +64 -0
- sqlspec/core/tenant/base.cp315-win_amd64.pyd +0 -0
- sqlspec/core/tenant/base.py +123 -0
- sqlspec/core/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/type_converter.py +147 -0
- sqlspec/data_dictionary/__init__.py +237 -0
- sqlspec/data_dictionary/_capabilities.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_capabilities.py +142 -0
- sqlspec/data_dictionary/_dependencies.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_dependencies.py +602 -0
- sqlspec/data_dictionary/_index_ddl.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_index_ddl.py +562 -0
- sqlspec/data_dictionary/_loader.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_loader.py +344 -0
- sqlspec/data_dictionary/_registry.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_registry.py +152 -0
- sqlspec/data_dictionary/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_types.py +1852 -0
- sqlspec/data_dictionary/dialects/__init__.py +34 -0
- sqlspec/data_dictionary/dialects/bigquery/__init__.py +15 -0
- sqlspec/data_dictionary/dialects/bigquery/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/bigquery/config.py +128 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/columns.sql +63 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/constraints.sql +37 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/datasets.sql +14 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/ddl.sql +51 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/dependencies.sql +22 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/foreign_keys.sql +34 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/indexes.sql +59 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/objects.sql +13 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/routines.sql +50 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/system.sql +59 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/tables.sql +111 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/views.sql +31 -0
- sqlspec/data_dictionary/dialects/cockroachdb/__init__.py +17 -0
- sqlspec/data_dictionary/dialects/cockroachdb/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/cockroachdb/config.py +95 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/columns.sql +163 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/comments.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/constraints.sql +67 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/crdb_internal.sql +11 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/ddl.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/dependencies.sql +20 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/foreign_keys.sql +62 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/indexes.sql +32 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/objects.sql +15 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/tables.sql +15 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/views.sql +11 -0
- sqlspec/data_dictionary/dialects/db2/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/db2/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/db2/config.py +172 -0
- sqlspec/data_dictionary/dialects/db2/sql/columns.sql +98 -0
- sqlspec/data_dictionary/dialects/db2/sql/constraints.sql +49 -0
- sqlspec/data_dictionary/dialects/db2/sql/foreign_keys.sql +43 -0
- sqlspec/data_dictionary/dialects/db2/sql/indexes.sql +39 -0
- sqlspec/data_dictionary/dialects/db2/sql/objects.sql +53 -0
- sqlspec/data_dictionary/dialects/db2/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/db2/sql/tables.sql +77 -0
- sqlspec/data_dictionary/dialects/db2/sql/version.sql +8 -0
- sqlspec/data_dictionary/dialects/db2/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/duckdb/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/duckdb/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/duckdb/config.py +66 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/columns.sql +150 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/constraints.sql +34 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/databases.sql +11 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/ddl.sql +221 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/dependencies.sql +50 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/extensions.sql +14 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/foreign_keys.sql +46 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/functions.sql +18 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/indexes.sql +34 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/objects.sql +30 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/sequences.sql +19 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/system.sql +21 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/tables.sql +59 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/types.sql +12 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/mariadb/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/columns.sql +45 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/constraints.sql +30 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/ddl.sql +27 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/events.sql +29 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/foreign_keys.sql +42 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/indexes.sql +33 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/objects.sql +50 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/partitions.sql +27 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/plugins.sql +16 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/privileges.sql +24 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/system.sql +12 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/version.sql +7 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/mssql/__init__.py +51 -0
- sqlspec/data_dictionary/dialects/mssql/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/mssql/config.py +558 -0
- sqlspec/data_dictionary/dialects/mssql/sql/columns.sql +120 -0
- sqlspec/data_dictionary/dialects/mssql/sql/constraints.sql +106 -0
- sqlspec/data_dictionary/dialects/mssql/sql/ddl.sql +89 -0
- sqlspec/data_dictionary/dialects/mssql/sql/dependencies.sql +17 -0
- sqlspec/data_dictionary/dialects/mssql/sql/extended_properties.sql +16 -0
- sqlspec/data_dictionary/dialects/mssql/sql/foreign_keys.sql +40 -0
- sqlspec/data_dictionary/dialects/mssql/sql/indexes.sql +86 -0
- sqlspec/data_dictionary/dialects/mssql/sql/modules.sql +19 -0
- sqlspec/data_dictionary/dialects/mssql/sql/objects.sql +16 -0
- sqlspec/data_dictionary/dialects/mssql/sql/permissions.sql +31 -0
- sqlspec/data_dictionary/dialects/mssql/sql/routines.sql +39 -0
- sqlspec/data_dictionary/dialects/mssql/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/mssql/sql/sequences.sql +18 -0
- sqlspec/data_dictionary/dialects/mssql/sql/storage.sql +22 -0
- sqlspec/data_dictionary/dialects/mssql/sql/system.sql +38 -0
- sqlspec/data_dictionary/dialects/mssql/sql/tables.sql +97 -0
- sqlspec/data_dictionary/dialects/mssql/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mssql/sql/version.sql +7 -0
- sqlspec/data_dictionary/dialects/mssql/sql/views.sql +18 -0
- sqlspec/data_dictionary/dialects/mysql/__init__.py +34 -0
- sqlspec/data_dictionary/dialects/mysql/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/mysql/config.py +363 -0
- sqlspec/data_dictionary/dialects/mysql/dictionary.py +650 -0
- sqlspec/data_dictionary/dialects/mysql/sql/columns.sql +45 -0
- sqlspec/data_dictionary/dialects/mysql/sql/components.sql +8 -0
- sqlspec/data_dictionary/dialects/mysql/sql/constraints.sql +30 -0
- sqlspec/data_dictionary/dialects/mysql/sql/ddl.sql +23 -0
- sqlspec/data_dictionary/dialects/mysql/sql/events.sql +29 -0
- sqlspec/data_dictionary/dialects/mysql/sql/foreign_keys.sql +42 -0
- sqlspec/data_dictionary/dialects/mysql/sql/indexes.sql +33 -0
- sqlspec/data_dictionary/dialects/mysql/sql/objects.sql +38 -0
- sqlspec/data_dictionary/dialects/mysql/sql/partitions.sql +27 -0
- sqlspec/data_dictionary/dialects/mysql/sql/plugins.sql +16 -0
- sqlspec/data_dictionary/dialects/mysql/sql/privileges.sql +26 -0
- sqlspec/data_dictionary/dialects/mysql/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/mysql/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/mysql/sql/system.sql +25 -0
- sqlspec/data_dictionary/dialects/mysql/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/mysql/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mysql/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/mysql/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/oracle/__init__.py +39 -0
- sqlspec/data_dictionary/dialects/oracle/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/oracle/config.py +266 -0
- sqlspec/data_dictionary/dialects/oracle/sql/arguments.sql +29 -0
- sqlspec/data_dictionary/dialects/oracle/sql/columns.sql +103 -0
- sqlspec/data_dictionary/dialects/oracle/sql/comments.sql +22 -0
- sqlspec/data_dictionary/dialects/oracle/sql/constraints.sql +49 -0
- sqlspec/data_dictionary/dialects/oracle/sql/ddl.sql +4 -0
- sqlspec/data_dictionary/dialects/oracle/sql/dependencies.sql +16 -0
- sqlspec/data_dictionary/dialects/oracle/sql/foreign_keys.sql +48 -0
- sqlspec/data_dictionary/dialects/oracle/sql/grants.sql +34 -0
- sqlspec/data_dictionary/dialects/oracle/sql/indexes.sql +87 -0
- sqlspec/data_dictionary/dialects/oracle/sql/lob_storage.sql +28 -0
- sqlspec/data_dictionary/dialects/oracle/sql/materialized_views.sql +27 -0
- sqlspec/data_dictionary/dialects/oracle/sql/objects.sql +26 -0
- sqlspec/data_dictionary/dialects/oracle/sql/partitions.sql +44 -0
- sqlspec/data_dictionary/dialects/oracle/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/oracle/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/oracle/sql/sequences.sql +21 -0
- sqlspec/data_dictionary/dialects/oracle/sql/source.sql +13 -0
- sqlspec/data_dictionary/dialects/oracle/sql/system.sql +37 -0
- sqlspec/data_dictionary/dialects/oracle/sql/tables.sql +48 -0
- sqlspec/data_dictionary/dialects/oracle/sql/triggers.sql +29 -0
- sqlspec/data_dictionary/dialects/oracle/sql/version.sql +25 -0
- sqlspec/data_dictionary/dialects/oracle/sql/views.sql +49 -0
- sqlspec/data_dictionary/dialects/postgres/__init__.py +19 -0
- sqlspec/data_dictionary/dialects/postgres/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/postgres/config.py +119 -0
- sqlspec/data_dictionary/dialects/postgres/sql/columns.sql +130 -0
- sqlspec/data_dictionary/dialects/postgres/sql/comments.sql +27 -0
- sqlspec/data_dictionary/dialects/postgres/sql/constraints.sql +53 -0
- sqlspec/data_dictionary/dialects/postgres/sql/ddl.sql +55 -0
- sqlspec/data_dictionary/dialects/postgres/sql/dependencies.sql +42 -0
- sqlspec/data_dictionary/dialects/postgres/sql/extensions.sql +11 -0
- sqlspec/data_dictionary/dialects/postgres/sql/foreign_keys.sql +72 -0
- sqlspec/data_dictionary/dialects/postgres/sql/indexes.sql +84 -0
- sqlspec/data_dictionary/dialects/postgres/sql/materialized_views.sql +17 -0
- sqlspec/data_dictionary/dialects/postgres/sql/objects.sql +25 -0
- sqlspec/data_dictionary/dialects/postgres/sql/partitions.sql +19 -0
- sqlspec/data_dictionary/dialects/postgres/sql/privileges.sql +29 -0
- sqlspec/data_dictionary/dialects/postgres/sql/routines.sql +25 -0
- sqlspec/data_dictionary/dialects/postgres/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/postgres/sql/sequences.sql +32 -0
- sqlspec/data_dictionary/dialects/postgres/sql/system.sql +53 -0
- sqlspec/data_dictionary/dialects/postgres/sql/tables.sql +67 -0
- sqlspec/data_dictionary/dialects/postgres/sql/triggers.sql +20 -0
- sqlspec/data_dictionary/dialects/postgres/sql/types.sql +21 -0
- sqlspec/data_dictionary/dialects/postgres/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/postgres/sql/views.sql +17 -0
- sqlspec/data_dictionary/dialects/snowflake/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/snowflake/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/snowflake/config.py +321 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/columns.sql +48 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/constraints.sql +64 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/ddl.sql +3 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/foreign_keys.sql +7 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/objects.sql +34 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/routines.sql +79 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/schemas.sql +19 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/sequences.sql +45 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/tables.sql +29 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/views.sql +37 -0
- sqlspec/data_dictionary/dialects/spanner/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/spanner/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/spanner/config.py +67 -0
- sqlspec/data_dictionary/dialects/spanner/sql/columns.sql +58 -0
- sqlspec/data_dictionary/dialects/spanner/sql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/change_streams.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/columns.sql +46 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/constraints.sql +63 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/database.sql +9 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/indexes.sql +66 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/objects.sql +10 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/placements.sql +8 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/property_graphs.sql +11 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/routines.sql +33 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/system.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/tables.sql +30 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/views.sql +13 -0
- sqlspec/data_dictionary/dialects/spanner/sql/indexes.sql +30 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/change_streams.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/columns.sql +34 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/constraints.sql +63 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/indexes.sql +52 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/objects.sql +10 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/system.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/tables.sql +22 -0
- sqlspec/data_dictionary/dialects/spanner/sql/tables.sql +9 -0
- sqlspec/data_dictionary/dialects/spanner/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/config.py +191 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/columns.sql +97 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/constraints.sql +43 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/foreign_keys.sql +45 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/indexes.sql +39 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/objects.sql +18 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/schemas.sql +15 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/tables.sql +86 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/sqlite/__init__.py +19 -0
- sqlspec/data_dictionary/dialects/sqlite/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sqlite/config.py +412 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/columns.sql +59 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/compile_options.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/constraints.sql +67 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/ddl.sql +37 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/foreign_keys.sql +45 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/functions.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/indexes.sql +76 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/modules.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/objects.sql +13 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/schemas.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/system.sql +7 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/triggers.sql +10 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/views.sql +10 -0
- sqlspec/data_dictionary/dialects/sybase/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/sybase/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sybase/config.py +187 -0
- sqlspec/data_dictionary/dialects/sybase/sql/columns.sql +137 -0
- sqlspec/data_dictionary/dialects/sybase/sql/constraints.sql +85 -0
- sqlspec/data_dictionary/dialects/sybase/sql/foreign_keys.sql +81 -0
- sqlspec/data_dictionary/dialects/sybase/sql/indexes.sql +51 -0
- sqlspec/data_dictionary/dialects/sybase/sql/objects.sql +21 -0
- sqlspec/data_dictionary/dialects/sybase/sql/schemas.sql +16 -0
- sqlspec/data_dictionary/dialects/sybase/sql/tables.sql +46 -0
- sqlspec/data_dictionary/dialects/sybase/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sybase/sql/views.sql +19 -0
- sqlspec/data_dictionary/dialects/teradata/__init__.py +33 -0
- sqlspec/data_dictionary/dialects/teradata/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/teradata/config.py +228 -0
- sqlspec/data_dictionary/dialects/teradata/sql/columns.sql +22 -0
- sqlspec/data_dictionary/dialects/teradata/sql/constraints.sql +19 -0
- sqlspec/data_dictionary/dialects/teradata/sql/foreign_keys.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/indexes.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/objects.sql +4 -0
- sqlspec/data_dictionary/dialects/teradata/sql/schemas.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/tables.sql +22 -0
- sqlspec/data_dictionary/dialects/teradata/sql/version.sql +4 -0
- sqlspec/data_dictionary/dialects/teradata/sql/views.sql +4 -0
- sqlspec/dialects/__init__.py +44 -0
- sqlspec/dialects/db2/__init__.py +111 -0
- sqlspec/dialects/db2/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_generators.py +376 -0
- sqlspec/dialects/db2/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_parsers.py +657 -0
- sqlspec/dialects/db2/_transforms.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_transforms.py +175 -0
- sqlspec/dialects/postgres/__init__.py +10 -0
- sqlspec/dialects/postgres/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_generators.py +81 -0
- sqlspec/dialects/postgres/_operators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_operators.py +95 -0
- sqlspec/dialects/postgres/_paradedb.py +44 -0
- sqlspec/dialects/postgres/_pg_textsearch.py +38 -0
- sqlspec/dialects/postgres/_pgvector.py +36 -0
- sqlspec/dialects/spanner/__init__.py +69 -0
- sqlspec/dialects/spanner/_expressions.py +247 -0
- sqlspec/dialects/spanner/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/spanner/_generators.py +961 -0
- sqlspec/dialects/spanner/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/spanner/_parsers.py +871 -0
- sqlspec/dialects/spanner/_spangres.py +43 -0
- sqlspec/dialects/spanner/_spanner.py +57 -0
- sqlspec/dialects/sybase/__init__.py +115 -0
- sqlspec/dialects/sybase/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_generators.py +379 -0
- sqlspec/dialects/sybase/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_parsers.py +225 -0
- sqlspec/dialects/sybase/_transforms.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_transforms.py +68 -0
- sqlspec/dialects/teradata/__init__.py +42 -0
- sqlspec/dialects/teradata/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/teradata/_generators.py +203 -0
- sqlspec/driver/__init__.py +151 -0
- sqlspec/driver/_async.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_async.py +3244 -0
- sqlspec/driver/_common.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_common.py +4765 -0
- sqlspec/driver/_deferred.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_deferred.py +232 -0
- sqlspec/driver/_exception_handler.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_exception_handler.py +224 -0
- sqlspec/driver/_routing.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_routing.py +2891 -0
- sqlspec/driver/_session.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_session.py +180 -0
- sqlspec/driver/_sql_helpers.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_sql_helpers.py +140 -0
- sqlspec/driver/_stream.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_stream.py +392 -0
- sqlspec/driver/_sync.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_sync.py +3107 -0
- sqlspec/driver/_tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_tenant.py +326 -0
- sqlspec/exceptions.cp315-win_amd64.pyd +0 -0
- sqlspec/exceptions.py +568 -0
- sqlspec/extensions/__init__.py +3 -0
- sqlspec/extensions/adk/__init__.py +136 -0
- sqlspec/extensions/adk/_config_utils.py +306 -0
- sqlspec/extensions/adk/_table_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/_table_utils.py +126 -0
- sqlspec/extensions/adk/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/_types.py +59 -0
- sqlspec/extensions/adk/artifact/__init__.py +18 -0
- sqlspec/extensions/adk/artifact/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/artifact/_types.py +41 -0
- sqlspec/extensions/adk/artifact/service.py +657 -0
- sqlspec/extensions/adk/artifact/store.py +444 -0
- sqlspec/extensions/adk/converters.py +230 -0
- sqlspec/extensions/adk/maintenance.py +262 -0
- sqlspec/extensions/adk/memory/__init__.py +36 -0
- sqlspec/extensions/adk/memory/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/memory/_types.py +48 -0
- sqlspec/extensions/adk/memory/converters.py +271 -0
- sqlspec/extensions/adk/memory/service.py +474 -0
- sqlspec/extensions/adk/memory/store.py +586 -0
- sqlspec/extensions/adk/migrations/0001_create_adk_tables.py +181 -0
- sqlspec/extensions/adk/migrations/0002_create_mssql_python_memory.py +51 -0
- sqlspec/extensions/adk/migrations/__init__.py +3 -0
- sqlspec/extensions/adk/migrations/reconcile.py +282 -0
- sqlspec/extensions/adk/service.py +463 -0
- sqlspec/extensions/adk/store.py +1239 -0
- sqlspec/extensions/events/__init__.py +132 -0
- sqlspec/extensions/events/_buffer.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_buffer.py +38 -0
- sqlspec/extensions/events/_channel.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_channel.py +1144 -0
- sqlspec/extensions/events/_hints.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_hints.py +38 -0
- sqlspec/extensions/events/_models.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_models.py +22 -0
- sqlspec/extensions/events/_names.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_names.py +27 -0
- sqlspec/extensions/events/_payload.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_payload.py +139 -0
- sqlspec/extensions/events/_protocols.py +154 -0
- sqlspec/extensions/events/_queue.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_queue.py +1147 -0
- sqlspec/extensions/events/_store.py +318 -0
- sqlspec/extensions/events/migrations/0001_create_event_queue.py +106 -0
- sqlspec/extensions/events/migrations/__init__.py +3 -0
- sqlspec/extensions/events/migrations/reconcile.py +145 -0
- sqlspec/extensions/events/primitives.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/primitives.py +91 -0
- sqlspec/extensions/fastapi/__init__.py +26 -0
- sqlspec/extensions/fastapi/extension.py +360 -0
- sqlspec/extensions/fastapi/providers.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/fastapi/providers.py +1091 -0
- sqlspec/extensions/flask/__init__.py +20 -0
- sqlspec/extensions/flask/_portal.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_portal.py +212 -0
- sqlspec/extensions/flask/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_state.py +135 -0
- sqlspec/extensions/flask/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_utils.py +171 -0
- sqlspec/extensions/flask/extension.py +1234 -0
- sqlspec/extensions/litestar/__init__.py +52 -0
- sqlspec/extensions/litestar/_tenant_resolution.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/_tenant_resolution.py +314 -0
- sqlspec/extensions/litestar/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/_utils.py +222 -0
- sqlspec/extensions/litestar/channels.py +249 -0
- sqlspec/extensions/litestar/cli.py +100 -0
- sqlspec/extensions/litestar/config.py +5 -0
- sqlspec/extensions/litestar/handlers.py +796 -0
- sqlspec/extensions/litestar/migrations/0001_create_session_table.py +138 -0
- sqlspec/extensions/litestar/migrations/__init__.py +3 -0
- sqlspec/extensions/litestar/migrations/reconcile.py +132 -0
- sqlspec/extensions/litestar/plugin.py +2172 -0
- sqlspec/extensions/litestar/providers.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/providers.py +1239 -0
- sqlspec/extensions/litestar/store.py +613 -0
- sqlspec/extensions/litestar/tenant.py +292 -0
- sqlspec/extensions/otel/__init__.py +58 -0
- sqlspec/extensions/prometheus/__init__.py +5 -0
- sqlspec/extensions/prometheus/_observer.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/prometheus/_observer.py +152 -0
- sqlspec/extensions/sanic/__init__.py +28 -0
- sqlspec/extensions/sanic/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/sanic/_state.py +102 -0
- sqlspec/extensions/sanic/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/sanic/_utils.py +234 -0
- sqlspec/extensions/sanic/extension.py +1467 -0
- sqlspec/extensions/starlette/__init__.py +31 -0
- sqlspec/extensions/starlette/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/starlette/_state.py +103 -0
- sqlspec/extensions/starlette/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/starlette/_utils.py +267 -0
- sqlspec/extensions/starlette/extension.py +691 -0
- sqlspec/extensions/starlette/middleware.py +845 -0
- sqlspec/loader.cp315-win_amd64.pyd +0 -0
- sqlspec/loader.py +1733 -0
- sqlspec/migrations/__init__.py +104 -0
- sqlspec/migrations/_backup.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/_backup.py +36 -0
- sqlspec/migrations/base.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/base.py +1688 -0
- sqlspec/migrations/commands.py +4002 -0
- sqlspec/migrations/context.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/context.py +158 -0
- sqlspec/migrations/fix.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/fix.py +193 -0
- sqlspec/migrations/loaders.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/loaders.py +835 -0
- sqlspec/migrations/runner.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/runner.py +2144 -0
- sqlspec/migrations/schema.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/schema.py +1266 -0
- sqlspec/migrations/squash.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/squash.py +2452 -0
- sqlspec/migrations/templates.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/templates.py +310 -0
- sqlspec/migrations/tracker.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/tracker.py +1529 -0
- sqlspec/migrations/utils.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/utils.py +534 -0
- sqlspec/migrations/validation.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/validation.py +355 -0
- sqlspec/migrations/version.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/version.py +455 -0
- sqlspec/observability/__init__.py +122 -0
- sqlspec/observability/_common.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_common.py +307 -0
- sqlspec/observability/_config.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_config.py +362 -0
- sqlspec/observability/_diagnostics.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_diagnostics.py +75 -0
- sqlspec/observability/_dispatcher.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_dispatcher.py +320 -0
- sqlspec/observability/_formatters/__init__.py +13 -0
- sqlspec/observability/_formatters/_aws.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_aws.py +90 -0
- sqlspec/observability/_formatters/_azure.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_azure.py +84 -0
- sqlspec/observability/_formatters/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_base.py +40 -0
- sqlspec/observability/_formatters/_gcp.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_gcp.py +119 -0
- sqlspec/observability/_formatting.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatting.py +76 -0
- sqlspec/observability/_observer.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_observer.py +445 -0
- sqlspec/observability/_runtime.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_runtime.py +740 -0
- sqlspec/observability/_sampling.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_sampling.py +169 -0
- sqlspec/observability/_spans.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_spans.py +212 -0
- sqlspec/protocols.py +1235 -0
- sqlspec/py.typed +0 -0
- sqlspec/service/__init__.py +5 -0
- sqlspec/service/_base.py +1051 -0
- sqlspec/service/_core.cp315-win_amd64.pyd +0 -0
- sqlspec/service/_core.py +625 -0
- sqlspec/storage/__init__.py +111 -0
- sqlspec/storage/_arrow_payload.py +802 -0
- sqlspec/storage/_arrow_stream.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_arrow_stream.py +134 -0
- sqlspec/storage/_ingest.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_ingest.py +810 -0
- sqlspec/storage/_paths.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_paths.py +313 -0
- sqlspec/storage/_staging_sql.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_staging_sql.py +695 -0
- sqlspec/storage/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_utils.py +174 -0
- sqlspec/storage/backends/__init__.py +43 -0
- sqlspec/storage/backends/base.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/base.py +399 -0
- sqlspec/storage/backends/fsspec.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/fsspec.py +1390 -0
- sqlspec/storage/backends/local.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/local.py +968 -0
- sqlspec/storage/backends/obstore.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/obstore.py +1974 -0
- sqlspec/storage/errors.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/errors.py +127 -0
- sqlspec/storage/pipeline.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/pipeline.py +1270 -0
- sqlspec/storage/registry.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/registry.py +318 -0
- sqlspec/typing.py +261 -0
- sqlspec/utils/__init__.py +9 -0
- sqlspec/utils/adapters.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/adapters.py +186 -0
- sqlspec/utils/arrow_helpers.py +2157 -0
- sqlspec/utils/config_tools.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/config_tools.py +712 -0
- sqlspec/utils/correlation.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/correlation.py +137 -0
- sqlspec/utils/deprecation.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/deprecation.py +222 -0
- sqlspec/utils/dispatch.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/dispatch.py +104 -0
- sqlspec/utils/env.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/env.py +437 -0
- sqlspec/utils/fixtures.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/fixtures.py +2470 -0
- sqlspec/utils/logging.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/logging.py +267 -0
- sqlspec/utils/module_loader.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/module_loader.py +399 -0
- sqlspec/utils/portal.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/portal.py +411 -0
- sqlspec/utils/routing.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/routing.py +645 -0
- sqlspec/utils/schema.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/schema.py +1050 -0
- sqlspec/utils/serializers/__init__.py +69 -0
- sqlspec/utils/serializers/_json.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_json.py +525 -0
- sqlspec/utils/serializers/_numpy.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_numpy.py +65 -0
- sqlspec/utils/serializers/_schema.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_schema.py +340 -0
- sqlspec/utils/sync_tools.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/sync_tools.py +502 -0
- sqlspec/utils/tenant/__init__.py +71 -0
- sqlspec/utils/tenant/_context.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_context.py +550 -0
- sqlspec/utils/tenant/_cursor.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_cursor.py +43 -0
- sqlspec/utils/tenant/_mssql.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_mssql.py +189 -0
- sqlspec/utils/tenant/_postgres.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_postgres.py +142 -0
- sqlspec/utils/text.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/text.py +317 -0
- sqlspec/utils/type_converters.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/type_converters.py +220 -0
- sqlspec/utils/type_guards.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/type_guards.py +1505 -0
- sqlspec/utils/uuids.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/uuids.py +263 -0
- sqlspec-0.72.0.dist-info/METADATA +228 -0
- sqlspec-0.72.0.dist-info/RECORD +1144 -0
- sqlspec-0.72.0.dist-info/WHEEL +4 -0
- sqlspec-0.72.0.dist-info/entry_points.txt +13 -0
- sqlspec-0.72.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,3273 @@
|
|
|
1
|
+
"""Oracle Database driver implementation."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from itertools import chain
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from time import perf_counter
|
|
7
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Final, Literal, NamedTuple, cast, overload
|
|
8
|
+
|
|
9
|
+
from mypy_extensions import mypyc_attr
|
|
10
|
+
|
|
11
|
+
from sqlspec.adapters.oracledb._typing import (
|
|
12
|
+
DB_TYPE_BLOB,
|
|
13
|
+
DB_TYPE_CLOB,
|
|
14
|
+
OracleAsyncConnection,
|
|
15
|
+
OracleAsyncCursor,
|
|
16
|
+
OracleAsyncSessionContext,
|
|
17
|
+
OracleAsyncSessionlessTransactionContext,
|
|
18
|
+
OracleSyncConnection,
|
|
19
|
+
OracleSyncCursor,
|
|
20
|
+
OracleSyncSessionContext,
|
|
21
|
+
OracleSyncSessionlessTransactionContext,
|
|
22
|
+
oracledb_module,
|
|
23
|
+
)
|
|
24
|
+
from sqlspec.adapters.oracledb._typing import DatabaseError as OracleDatabaseError
|
|
25
|
+
from sqlspec.adapters.oracledb._typing import Error as OracleError
|
|
26
|
+
from sqlspec.adapters.oracledb._typing import oracledb_create_pipeline as create_oracle_pipeline
|
|
27
|
+
from sqlspec.adapters.oracledb.core import (
|
|
28
|
+
ORACLEDB_VERSION,
|
|
29
|
+
OracleAsyncStreamSource,
|
|
30
|
+
OracleCacheHitState,
|
|
31
|
+
OracleSyncStreamSource,
|
|
32
|
+
apply_oracle_transaction_priority,
|
|
33
|
+
apply_session_tracing,
|
|
34
|
+
build_arrow_fetch_kwargs,
|
|
35
|
+
build_dbms_cloud_copy_data_sql,
|
|
36
|
+
build_fetch_kwargs,
|
|
37
|
+
build_insert_statement,
|
|
38
|
+
build_pipeline_stack_result,
|
|
39
|
+
build_truncate_statement,
|
|
40
|
+
coerce_large_parameters_async,
|
|
41
|
+
coerce_large_parameters_sync,
|
|
42
|
+
coerce_many_parameters_async,
|
|
43
|
+
coerce_many_parameters_sync,
|
|
44
|
+
coerce_pipeline_rows_async,
|
|
45
|
+
collect_async_rows,
|
|
46
|
+
collect_sync_rows,
|
|
47
|
+
connection_is_thin,
|
|
48
|
+
create_mapped_exception,
|
|
49
|
+
default_statement_config,
|
|
50
|
+
driver_profile,
|
|
51
|
+
execute_cache_hit,
|
|
52
|
+
execute_cache_hit_async,
|
|
53
|
+
normalize_column_names,
|
|
54
|
+
resolve_dbms_cloud_source_uri,
|
|
55
|
+
resolve_row_metadata,
|
|
56
|
+
resolve_rowcount,
|
|
57
|
+
supports_df_batches,
|
|
58
|
+
supports_direct_path_load,
|
|
59
|
+
validate_sessionless_execution_options,
|
|
60
|
+
validate_sessionless_transaction_args,
|
|
61
|
+
)
|
|
62
|
+
from sqlspec.adapters.oracledb.data_dictionary import (
|
|
63
|
+
OracledbAsyncDataDictionary,
|
|
64
|
+
OracledbSyncDataDictionary,
|
|
65
|
+
OracleVersionCache,
|
|
66
|
+
resolve_oracle_connection_major,
|
|
67
|
+
)
|
|
68
|
+
from sqlspec.core.cache import get_cache_config
|
|
69
|
+
from sqlspec.core.explain import (
|
|
70
|
+
ORACLE_EXPLAIN_DISPLAY_CURSOR_META_KEY,
|
|
71
|
+
ORACLE_EXPLAIN_PREFIX,
|
|
72
|
+
ORACLE_EXPLAIN_XPLAN_FORMAT_META_KEY,
|
|
73
|
+
ORACLE_MANAGED_EXPLAIN_META_KEY,
|
|
74
|
+
)
|
|
75
|
+
from sqlspec.core.parameters._registry import register_driver_profile
|
|
76
|
+
from sqlspec.core.result._base import SQLResult, StackResult, build_arrow_result_from_table, create_arrow_result
|
|
77
|
+
from sqlspec.core.sqlcommenter import format_wire_sqlcomment, strip_sqlcomment
|
|
78
|
+
from sqlspec.core.stack import StatementStack
|
|
79
|
+
from sqlspec.core.statement import SQL, StatementConfig
|
|
80
|
+
from sqlspec.driver._async import AsyncDriverAdapterBase
|
|
81
|
+
from sqlspec.driver._common import (
|
|
82
|
+
StackExecutionObserver,
|
|
83
|
+
cache_hit_hooks_unchanged,
|
|
84
|
+
describe_stack_statement,
|
|
85
|
+
hash_stack_operations,
|
|
86
|
+
validate_load_from_storage_kwargs,
|
|
87
|
+
validate_savepoint_name,
|
|
88
|
+
)
|
|
89
|
+
from sqlspec.driver._exception_handler import BaseAsyncExceptionHandler, BaseSyncExceptionHandler
|
|
90
|
+
from sqlspec.driver._stream import AsyncRowStream, SyncRowStream
|
|
91
|
+
from sqlspec.driver._sync import SyncDriverAdapterBase
|
|
92
|
+
from sqlspec.exceptions import ImproperConfigurationError, SQLSpecError, StackExecutionError, with_cause
|
|
93
|
+
from sqlspec.storage._utils import import_pyarrow
|
|
94
|
+
from sqlspec.utils.arrow_helpers import coerce_oracle_df_to_arrow_table
|
|
95
|
+
from sqlspec.utils.logging import get_logger, log_with_context
|
|
96
|
+
from sqlspec.utils.module_loader import ensure_pyarrow
|
|
97
|
+
from sqlspec.utils.sync_tools import exit_async_context
|
|
98
|
+
from sqlspec.utils.text import normalize_identifier, quote_identifier, split_qualified_identifier
|
|
99
|
+
from sqlspec.utils.type_guards import has_pipeline_capability, is_async_readable
|
|
100
|
+
from sqlspec.utils.uuids import uuid4
|
|
101
|
+
|
|
102
|
+
if TYPE_CHECKING:
|
|
103
|
+
from collections.abc import AsyncIterator, Generator, Mapping, Sequence
|
|
104
|
+
|
|
105
|
+
from sqlglot.dialects.dialect import DialectType
|
|
106
|
+
|
|
107
|
+
from sqlspec.builder._base import QueryBuilder
|
|
108
|
+
from sqlspec.core.cache import CachedQuery
|
|
109
|
+
from sqlspec.core.filters import StatementFilter
|
|
110
|
+
from sqlspec.core.result._base import ArrowResult
|
|
111
|
+
from sqlspec.core.stack import StackOperation
|
|
112
|
+
from sqlspec.core.statement import Statement
|
|
113
|
+
from sqlspec.driver._common import ExecutionResult
|
|
114
|
+
from sqlspec.observability._runtime import ObservabilityRuntime
|
|
115
|
+
from sqlspec.storage.pipeline import StorageBridgeJob, StorageDestination, StorageFormat, StorageTelemetry
|
|
116
|
+
from sqlspec.typing import ArrowRecordBatch, ArrowReturnFormat, ArrowSchema, SchemaT, StatementParameters
|
|
117
|
+
|
|
118
|
+
__all__ = (
|
|
119
|
+
"OracleAsyncDriver",
|
|
120
|
+
"OracleAsyncExceptionHandler",
|
|
121
|
+
"OracleAsyncSessionContext",
|
|
122
|
+
"OracleSyncDriver",
|
|
123
|
+
"OracleSyncExceptionHandler",
|
|
124
|
+
"OracleSyncSessionContext",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
logger = get_logger(__name__)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
PLAN_STATEMENT_ID_MAX_LENGTH: Final[int] = 30
|
|
132
|
+
"""Width of the PLAN_TABLE STATEMENT_ID column."""
|
|
133
|
+
|
|
134
|
+
PLAN_STATEMENT_ID_PREFIX: Final[str] = "sqlspec_"
|
|
135
|
+
|
|
136
|
+
PLAN_DISPLAY_SQL: Final[str] = "SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY(NULL, :statement_id, 'TYPICAL'))"
|
|
137
|
+
|
|
138
|
+
PLAN_CLEANUP_SQL: Final[str] = "DELETE FROM plan_table WHERE statement_id = :statement_id"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
PIPELINE_MIN_DRIVER_VERSION: "tuple[int, int, int]" = (2, 4, 0)
|
|
142
|
+
"""Lowest python-oracledb version that supports pipelining."""
|
|
143
|
+
|
|
144
|
+
PIPELINE_MIN_DATABASE_MAJOR: int = 23
|
|
145
|
+
"""Lowest Oracle Database major version pipelining is used on.
|
|
146
|
+
|
|
147
|
+
This is a policy threshold for when pipelining is worth the round trips, not a
|
|
148
|
+
correctness guard: python-oracledb self-gates through ``supports_pipelining()``
|
|
149
|
+
and falls back to sequential execution on databases that cannot pipeline.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _oracle_apply_session_tracing(driver: Any, connection: Any = None) -> None:
|
|
154
|
+
if not (getattr(driver, "_session_tracing_enabled", False) or getattr(driver, "_otel_tracing_enabled", False)):
|
|
155
|
+
return
|
|
156
|
+
target_conn = connection if connection is not None else getattr(driver, "connection", None)
|
|
157
|
+
if target_conn is None:
|
|
158
|
+
return
|
|
159
|
+
apply_session_tracing(
|
|
160
|
+
target_conn,
|
|
161
|
+
driver.statement_config,
|
|
162
|
+
driver.driver_features,
|
|
163
|
+
enable_session_attributes=getattr(driver, "_session_tracing_enabled", False),
|
|
164
|
+
enable_otel_trace_context=getattr(driver, "_otel_tracing_enabled", False),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _oracle_format_wire_sql(driver: Any, sql: str, config: "StatementConfig | None" = None) -> str:
|
|
169
|
+
effective_config = config or driver.statement_config
|
|
170
|
+
if getattr(driver, "_session_tracing_enabled", False):
|
|
171
|
+
return strip_sqlcomment(sql)
|
|
172
|
+
if not effective_config.enable_sqlcommenter:
|
|
173
|
+
return sql
|
|
174
|
+
return format_wire_sqlcomment(sql, effective_config)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _oracle_stack_native_blocker(stack: "StatementStack") -> "str | None":
|
|
178
|
+
for operation in stack.operations:
|
|
179
|
+
if operation.method == "execute_arrow":
|
|
180
|
+
return "arrow_operation"
|
|
181
|
+
if operation.method == "execute_script":
|
|
182
|
+
return "script_operation"
|
|
183
|
+
return None
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _oracle_log_pipeline_skip(driver: Any, reason: str, stack: "StatementStack") -> None:
|
|
187
|
+
log_level = logging.INFO if reason == "env_override" else logging.DEBUG
|
|
188
|
+
log_with_context(
|
|
189
|
+
logger,
|
|
190
|
+
log_level,
|
|
191
|
+
"stack.native_pipeline.skip",
|
|
192
|
+
driver=type(driver).__name__,
|
|
193
|
+
reason=reason,
|
|
194
|
+
hashed_operations=hash_stack_operations(stack),
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _oracle_prepare_pipeline_operation(
|
|
199
|
+
driver: "OracleSyncDriver | OracleAsyncDriver", operation: "StackOperation"
|
|
200
|
+
) -> "_CompiledStackOperation":
|
|
201
|
+
kwargs = dict(operation.keyword_arguments) if operation.keyword_arguments else {}
|
|
202
|
+
statement_config = kwargs.pop("statement_config", None)
|
|
203
|
+
config = statement_config or driver.statement_config
|
|
204
|
+
|
|
205
|
+
if operation.method == "execute":
|
|
206
|
+
sql_statement = driver.prepare_statement(
|
|
207
|
+
operation.statement, operation.arguments, statement_config=config, kwargs=kwargs
|
|
208
|
+
)
|
|
209
|
+
elif operation.method == "execute_many":
|
|
210
|
+
if not operation.arguments:
|
|
211
|
+
msg = "execute_many stack operation requires parameter sets"
|
|
212
|
+
raise ValueError(msg)
|
|
213
|
+
parameter_sets = operation.arguments[0]
|
|
214
|
+
filters = operation.arguments[1:]
|
|
215
|
+
if isinstance(operation.statement, SQL):
|
|
216
|
+
statement_seed = operation.statement.raw_expression or operation.statement.raw_sql
|
|
217
|
+
sql_statement = SQL(statement_seed, parameter_sets, statement_config=config, is_many=True, **kwargs)
|
|
218
|
+
else:
|
|
219
|
+
base_statement = driver.prepare_statement(
|
|
220
|
+
operation.statement, filters, statement_config=config, kwargs=kwargs
|
|
221
|
+
)
|
|
222
|
+
statement_seed = base_statement.raw_expression or base_statement.raw_sql
|
|
223
|
+
sql_statement = SQL(statement_seed, parameter_sets, statement_config=config, is_many=True, **kwargs)
|
|
224
|
+
else:
|
|
225
|
+
msg = f"Unsupported stack operation method: {operation.method}"
|
|
226
|
+
raise ValueError(msg)
|
|
227
|
+
|
|
228
|
+
compiled_sql, prepared_parameters = driver._compiled_sql(sql_statement, config)
|
|
229
|
+
summary = describe_stack_statement(operation.statement)
|
|
230
|
+
return _CompiledStackOperation(
|
|
231
|
+
statement=sql_statement,
|
|
232
|
+
sql=compiled_sql,
|
|
233
|
+
parameters=prepared_parameters,
|
|
234
|
+
method=operation.method,
|
|
235
|
+
returns_rows=sql_statement.returns_rows()
|
|
236
|
+
and sql_statement.operation_type not in {"INSERT", "UPDATE", "DELETE"},
|
|
237
|
+
summary=summary,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _oracle_add_pipeline_operation(
|
|
242
|
+
driver: "OracleSyncDriver | OracleAsyncDriver", pipeline: Any, operation: "_CompiledStackOperation"
|
|
243
|
+
) -> None:
|
|
244
|
+
parameters = operation.parameters or []
|
|
245
|
+
if operation.method == "execute":
|
|
246
|
+
if operation.returns_rows:
|
|
247
|
+
fetch_kwargs = build_fetch_kwargs(driver.driver_features)
|
|
248
|
+
arraysize = driver.driver_features.get("arraysize")
|
|
249
|
+
if arraysize is not None:
|
|
250
|
+
fetch_kwargs["arraysize"] = arraysize
|
|
251
|
+
pipeline.add_fetchall(operation.sql, parameters, **fetch_kwargs)
|
|
252
|
+
else:
|
|
253
|
+
pipeline.add_execute(operation.sql, parameters)
|
|
254
|
+
return
|
|
255
|
+
|
|
256
|
+
if operation.method == "execute_many":
|
|
257
|
+
pipeline.add_executemany(operation.sql, parameters)
|
|
258
|
+
return
|
|
259
|
+
|
|
260
|
+
msg = f"Unsupported pipeline operation: {operation.method}"
|
|
261
|
+
raise ValueError(msg)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _oracle_build_stack_results_from_pipeline(
|
|
265
|
+
driver: "OracleSyncDriver | OracleAsyncDriver",
|
|
266
|
+
compiled_operations: "Sequence[_CompiledStackOperation]",
|
|
267
|
+
pipeline_results: "Sequence[Any]",
|
|
268
|
+
continue_on_error: bool,
|
|
269
|
+
observer: StackExecutionObserver,
|
|
270
|
+
*,
|
|
271
|
+
coerced_rows_by_index: "Mapping[int, Sequence[Any] | None] | None" = None,
|
|
272
|
+
) -> "list[StackResult]":
|
|
273
|
+
stack_results: list[StackResult] = []
|
|
274
|
+
for index, (compiled, result) in enumerate(zip(compiled_operations, pipeline_results, strict=False)):
|
|
275
|
+
try:
|
|
276
|
+
error = result.error
|
|
277
|
+
except AttributeError:
|
|
278
|
+
error = None
|
|
279
|
+
if error is not None:
|
|
280
|
+
mapped_error = create_mapped_exception(error) if not isinstance(error, SQLSpecError) else error
|
|
281
|
+
stack_error = StackExecutionError(
|
|
282
|
+
index,
|
|
283
|
+
compiled.summary,
|
|
284
|
+
mapped_error,
|
|
285
|
+
adapter=type(driver).__name__,
|
|
286
|
+
mode="continue-on-error" if continue_on_error else "fail-fast",
|
|
287
|
+
)
|
|
288
|
+
if continue_on_error:
|
|
289
|
+
observer.record_operation_error(stack_error)
|
|
290
|
+
stack_results.append(StackResult.from_error(stack_error))
|
|
291
|
+
continue
|
|
292
|
+
raise stack_error
|
|
293
|
+
|
|
294
|
+
stack_results.append(
|
|
295
|
+
build_pipeline_stack_result(
|
|
296
|
+
compiled.statement,
|
|
297
|
+
compiled.method,
|
|
298
|
+
compiled.returns_rows,
|
|
299
|
+
compiled.parameters,
|
|
300
|
+
result,
|
|
301
|
+
driver.driver_features,
|
|
302
|
+
coerced_rows=coerced_rows_by_index.get(index) if coerced_rows_by_index is not None else None,
|
|
303
|
+
)
|
|
304
|
+
)
|
|
305
|
+
return stack_results
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _oracle_check_pipeline_commit_result(result: Any) -> None:
|
|
309
|
+
error = getattr(result, "error", None)
|
|
310
|
+
if error is not None:
|
|
311
|
+
raise create_mapped_exception(error)
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def _oracle_wrap_pipeline_error(driver: Any, error: Exception, continue_on_error: bool) -> StackExecutionError:
|
|
315
|
+
mode = "continue-on-error" if continue_on_error else "fail-fast"
|
|
316
|
+
mapped_error = create_mapped_exception(error) if not isinstance(error, SQLSpecError) else error
|
|
317
|
+
wrapped = StackExecutionError(
|
|
318
|
+
-1, "Oracle pipeline execution failed", mapped_error, adapter=type(driver).__name__, mode=mode
|
|
319
|
+
)
|
|
320
|
+
wrapped.__cause__ = error
|
|
321
|
+
return wrapped
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
class _OracleAsyncArrowBatchIterator:
|
|
325
|
+
"""Async iterator yielding Oracle DataFrame batches as Arrow record batches."""
|
|
326
|
+
|
|
327
|
+
__slots__ = ("_arrow_schema", "_closed", "_driver_features", "_oracle_dfs", "_pending_batches", "_yielded")
|
|
328
|
+
|
|
329
|
+
def __init__(
|
|
330
|
+
self,
|
|
331
|
+
connection: Any,
|
|
332
|
+
sql: str,
|
|
333
|
+
parameters: "StatementParameters | None",
|
|
334
|
+
batch_size: int | None,
|
|
335
|
+
driver_features: Any,
|
|
336
|
+
arrow_schema: "ArrowSchema | None",
|
|
337
|
+
) -> None:
|
|
338
|
+
self._oracle_dfs = _fetch_dataframe_batches(
|
|
339
|
+
connection, sql, parameters, batch_size, driver_features, arrow_schema
|
|
340
|
+
)
|
|
341
|
+
self._driver_features = driver_features
|
|
342
|
+
self._arrow_schema = arrow_schema
|
|
343
|
+
self._pending_batches: list[Any] = []
|
|
344
|
+
self._yielded = False
|
|
345
|
+
self._closed = False
|
|
346
|
+
|
|
347
|
+
def __aiter__(self) -> "_OracleAsyncArrowBatchIterator":
|
|
348
|
+
return self
|
|
349
|
+
|
|
350
|
+
async def aclose(self) -> None:
|
|
351
|
+
if self._closed:
|
|
352
|
+
return
|
|
353
|
+
self._closed = True
|
|
354
|
+
aclose_dfs = getattr(self._oracle_dfs, "aclose", None)
|
|
355
|
+
if callable(aclose_dfs):
|
|
356
|
+
await cast("Any", aclose_dfs)()
|
|
357
|
+
return
|
|
358
|
+
close_dfs = getattr(self._oracle_dfs, "close", None)
|
|
359
|
+
if callable(close_dfs):
|
|
360
|
+
close_dfs()
|
|
361
|
+
|
|
362
|
+
async def __anext__(self) -> "ArrowRecordBatch":
|
|
363
|
+
while not self._pending_batches:
|
|
364
|
+
next_error: BaseException | None = None
|
|
365
|
+
oracle_df: Any = None
|
|
366
|
+
stop_iteration = False
|
|
367
|
+
try:
|
|
368
|
+
oracle_df = await self._oracle_dfs.__anext__()
|
|
369
|
+
except StopAsyncIteration:
|
|
370
|
+
stop_iteration = True
|
|
371
|
+
except OracleError as exc:
|
|
372
|
+
next_error = exc
|
|
373
|
+
except BaseException as exc:
|
|
374
|
+
next_error = exc
|
|
375
|
+
if next_error is not None:
|
|
376
|
+
await self.aclose()
|
|
377
|
+
if isinstance(next_error, OracleError):
|
|
378
|
+
raise with_cause(create_mapped_exception(next_error), next_error) from next_error
|
|
379
|
+
raise next_error
|
|
380
|
+
if stop_iteration:
|
|
381
|
+
await self.aclose()
|
|
382
|
+
if not self._yielded and self._arrow_schema is not None:
|
|
383
|
+
self._yielded = True
|
|
384
|
+
return cast(
|
|
385
|
+
"ArrowRecordBatch", import_pyarrow().RecordBatch.from_pylist([], schema=self._arrow_schema)
|
|
386
|
+
)
|
|
387
|
+
raise StopAsyncIteration
|
|
388
|
+
batch_table = _coerce_oracle_arrow_batch_table(oracle_df, self._driver_features, self._arrow_schema)
|
|
389
|
+
if batch_table.num_rows:
|
|
390
|
+
batches = list(batch_table.to_batches())
|
|
391
|
+
batches.reverse()
|
|
392
|
+
self._pending_batches = batches
|
|
393
|
+
else:
|
|
394
|
+
self._yielded = True
|
|
395
|
+
return cast("ArrowRecordBatch", import_pyarrow().RecordBatch.from_pylist([], schema=batch_table.schema))
|
|
396
|
+
self._yielded = True
|
|
397
|
+
return cast("ArrowRecordBatch", self._pending_batches.pop())
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
401
|
+
class OracleSyncExceptionHandler(BaseSyncExceptionHandler):
|
|
402
|
+
"""Synchronous context manager for handling Oracle database exceptions.
|
|
403
|
+
|
|
404
|
+
Maps Oracle ``ORA-XXXXX`` error codes to SQLSpec exceptions stored on
|
|
405
|
+
``pending_exception``.
|
|
406
|
+
"""
|
|
407
|
+
|
|
408
|
+
__slots__ = ()
|
|
409
|
+
|
|
410
|
+
def _handle_exception(self, exc_type: "type[BaseException] | None", exc_val: "BaseException") -> bool:
|
|
411
|
+
|
|
412
|
+
if exc_type is None:
|
|
413
|
+
return False
|
|
414
|
+
if issubclass(exc_type, OracleDatabaseError):
|
|
415
|
+
self.pending_exception = create_mapped_exception(exc_val)
|
|
416
|
+
return True
|
|
417
|
+
return False
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
421
|
+
class OracleAsyncExceptionHandler(BaseAsyncExceptionHandler):
|
|
422
|
+
"""Async context manager for handling Oracle database exceptions.
|
|
423
|
+
|
|
424
|
+
Maps Oracle ``ORA-XXXXX`` error codes to SQLSpec exceptions stored on
|
|
425
|
+
``pending_exception``.
|
|
426
|
+
"""
|
|
427
|
+
|
|
428
|
+
__slots__ = ()
|
|
429
|
+
|
|
430
|
+
def _handle_exception(self, exc_type: "type[BaseException] | None", exc_val: "BaseException") -> bool:
|
|
431
|
+
|
|
432
|
+
if exc_type is None:
|
|
433
|
+
return False
|
|
434
|
+
if issubclass(exc_type, OracleDatabaseError):
|
|
435
|
+
self.pending_exception = create_mapped_exception(exc_val)
|
|
436
|
+
return True
|
|
437
|
+
return False
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
441
|
+
class OracleSyncDriver(SyncDriverAdapterBase):
|
|
442
|
+
"""Synchronous Oracle Database driver.
|
|
443
|
+
|
|
444
|
+
Provides Oracle Database connectivity with parameter style conversion,
|
|
445
|
+
error handling, and transaction management.
|
|
446
|
+
"""
|
|
447
|
+
|
|
448
|
+
__slots__ = (
|
|
449
|
+
"_data_dictionary",
|
|
450
|
+
"_fetch_kwargs",
|
|
451
|
+
"_migration_schema_restore",
|
|
452
|
+
"_row_metadata_cache",
|
|
453
|
+
"_session_tracing_enabled",
|
|
454
|
+
"_sessionless_cleanup_error",
|
|
455
|
+
"_sessionless_transaction_id",
|
|
456
|
+
"_transaction_active",
|
|
457
|
+
)
|
|
458
|
+
dialect: "DialectType | None" = "oracle"
|
|
459
|
+
export_integers_may_widen: ClassVar[bool] = True
|
|
460
|
+
native_arrow_export: ClassVar[bool] = True
|
|
461
|
+
_pipeline_support: ClassVar[bool] = False
|
|
462
|
+
_pipeline_support_reason: ClassVar[str] = "asyncio_thin_required"
|
|
463
|
+
|
|
464
|
+
def __init__(
|
|
465
|
+
self,
|
|
466
|
+
connection: OracleSyncConnection,
|
|
467
|
+
statement_config: "StatementConfig | None" = None,
|
|
468
|
+
driver_features: "dict[str, Any] | None" = None,
|
|
469
|
+
) -> None:
|
|
470
|
+
if statement_config is None:
|
|
471
|
+
statement_config = default_statement_config.replace(
|
|
472
|
+
enable_caching=get_cache_config().compiled_cache_enabled
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
super().__init__(connection=connection, statement_config=statement_config, driver_features=driver_features)
|
|
476
|
+
self._data_dictionary: OracledbSyncDataDictionary | None = None
|
|
477
|
+
self._migration_schema_restore: str | None = None
|
|
478
|
+
self._row_metadata_cache: dict[int, tuple[Any, list[str], bool]] = {}
|
|
479
|
+
self._transaction_active = False
|
|
480
|
+
self._sessionless_transaction_id: bytes | None = None
|
|
481
|
+
self._sessionless_cleanup_error: BaseException | None = None
|
|
482
|
+
self._fetch_kwargs = build_fetch_kwargs(self.driver_features)
|
|
483
|
+
self._session_tracing_enabled = bool(
|
|
484
|
+
self.driver_features.get("enable_session_tracing", False) or self.statement_config.enable_sqlcommenter
|
|
485
|
+
)
|
|
486
|
+
self._cache_hit_executor = (
|
|
487
|
+
execute_cache_hit if cache_hit_hooks_unchanged(type(self), OracleSyncDriver) else None
|
|
488
|
+
)
|
|
489
|
+
self._cache_hit_state = OracleCacheHitState(
|
|
490
|
+
self.driver_features, self._fetch_kwargs, self._row_metadata_cache, self._session_tracing_enabled
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
@property
|
|
494
|
+
def sessionless_transaction_id(self) -> bytes | None:
|
|
495
|
+
"""Return the sessionless transaction currently attached to this connection."""
|
|
496
|
+
return self._sessionless_transaction_id
|
|
497
|
+
|
|
498
|
+
@property
|
|
499
|
+
def _oracle_version_cache(self) -> "OracleVersionCache | None":
|
|
500
|
+
return cast("OracleVersionCache | None", cast("OracleCacheHitState", self._cache_hit_state).version_cache)
|
|
501
|
+
|
|
502
|
+
@_oracle_version_cache.setter
|
|
503
|
+
def _oracle_version_cache(self, value: "OracleVersionCache | None") -> None:
|
|
504
|
+
cast("OracleCacheHitState", self._cache_hit_state).version_cache = value
|
|
505
|
+
|
|
506
|
+
@property
|
|
507
|
+
def _otel_tracing_enabled(self) -> bool:
|
|
508
|
+
return cast("OracleCacheHitState", self._cache_hit_state).otel_tracing_enabled
|
|
509
|
+
|
|
510
|
+
@_otel_tracing_enabled.setter
|
|
511
|
+
def _otel_tracing_enabled(self, value: bool) -> None:
|
|
512
|
+
cast("OracleCacheHitState", self._cache_hit_state).otel_tracing_enabled = bool(value)
|
|
513
|
+
|
|
514
|
+
def attach_observability(self, runtime: "ObservabilityRuntime") -> None:
|
|
515
|
+
"""Refresh trace propagation when the session receives its runtime."""
|
|
516
|
+
super().attach_observability(runtime)
|
|
517
|
+
self._otel_tracing_enabled = (
|
|
518
|
+
bool(self.driver_features.get("enable_otel_trace_context", True)) and runtime.span_manager.is_enabled
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
def _apply_session_tracing(self, connection: Any = None) -> None:
|
|
522
|
+
_oracle_apply_session_tracing(self, connection)
|
|
523
|
+
|
|
524
|
+
def _format_wire_sql(self, sql: str, config: "StatementConfig | None" = None) -> str:
|
|
525
|
+
return _oracle_format_wire_sql(self, sql, config)
|
|
526
|
+
|
|
527
|
+
def _compiled_sql(
|
|
528
|
+
self, statement: "SQL", statement_config: "StatementConfig", flatten_single_parameters: bool = False
|
|
529
|
+
) -> "tuple[str, Any]":
|
|
530
|
+
compiled_sql, prepared_parameters = super()._compiled_sql(
|
|
531
|
+
statement, statement_config, flatten_single_parameters=flatten_single_parameters
|
|
532
|
+
)
|
|
533
|
+
if self._session_tracing_enabled:
|
|
534
|
+
return strip_sqlcomment(compiled_sql), prepared_parameters
|
|
535
|
+
return compiled_sql, prepared_parameters
|
|
536
|
+
|
|
537
|
+
def _stack_native_blocker(self, stack: "StatementStack") -> "str | None":
|
|
538
|
+
return _oracle_stack_native_blocker(stack)
|
|
539
|
+
|
|
540
|
+
def _log_pipeline_skip(self, reason: str, stack: "StatementStack") -> None:
|
|
541
|
+
_oracle_log_pipeline_skip(self, reason, stack)
|
|
542
|
+
|
|
543
|
+
def _prepare_pipeline_operation(self, operation: "StackOperation") -> "_CompiledStackOperation":
|
|
544
|
+
return _oracle_prepare_pipeline_operation(self, operation)
|
|
545
|
+
|
|
546
|
+
def _add_pipeline_operation(self, pipeline: Any, operation: "_CompiledStackOperation") -> None:
|
|
547
|
+
_oracle_add_pipeline_operation(self, pipeline, operation)
|
|
548
|
+
|
|
549
|
+
def _build_stack_results_from_pipeline(
|
|
550
|
+
self,
|
|
551
|
+
compiled_operations: "Sequence[_CompiledStackOperation]",
|
|
552
|
+
pipeline_results: "Sequence[Any]",
|
|
553
|
+
continue_on_error: bool,
|
|
554
|
+
observer: StackExecutionObserver,
|
|
555
|
+
*,
|
|
556
|
+
coerced_rows_by_index: "Mapping[int, Sequence[Any] | None] | None" = None,
|
|
557
|
+
) -> "list[StackResult]":
|
|
558
|
+
return _oracle_build_stack_results_from_pipeline(
|
|
559
|
+
self,
|
|
560
|
+
compiled_operations,
|
|
561
|
+
pipeline_results,
|
|
562
|
+
continue_on_error,
|
|
563
|
+
observer,
|
|
564
|
+
coerced_rows_by_index=coerced_rows_by_index,
|
|
565
|
+
)
|
|
566
|
+
|
|
567
|
+
def _check_pipeline_commit_result(self, result: Any) -> None:
|
|
568
|
+
_oracle_check_pipeline_commit_result(result)
|
|
569
|
+
|
|
570
|
+
def _wrap_pipeline_error(
|
|
571
|
+
self, error: Exception, stack: "StatementStack", continue_on_error: bool
|
|
572
|
+
) -> StackExecutionError:
|
|
573
|
+
return _oracle_wrap_pipeline_error(self, error, continue_on_error)
|
|
574
|
+
|
|
575
|
+
@property
|
|
576
|
+
def data_dictionary(self) -> "OracledbSyncDataDictionary":
|
|
577
|
+
"""Get the data dictionary for this driver.
|
|
578
|
+
|
|
579
|
+
Returns:
|
|
580
|
+
Data dictionary instance for metadata queries
|
|
581
|
+
"""
|
|
582
|
+
if self._data_dictionary is None:
|
|
583
|
+
self._data_dictionary = OracledbSyncDataDictionary()
|
|
584
|
+
return self._data_dictionary
|
|
585
|
+
|
|
586
|
+
def set_transaction_priority(self, priority: Any) -> None:
|
|
587
|
+
"""Set native transaction priority as a zero-round-trip connection field."""
|
|
588
|
+
apply_oracle_transaction_priority(self.connection, priority)
|
|
589
|
+
|
|
590
|
+
def begin_sessionless_transaction(
|
|
591
|
+
self, transaction_id: str | bytes | None = None, *, timeout: int = 60, defer_round_trip: bool = True
|
|
592
|
+
) -> bytes:
|
|
593
|
+
"""Begin an explicitly supported native sessionless transaction."""
|
|
594
|
+
resolved = validate_sessionless_transaction_args(
|
|
595
|
+
transaction_id, timeout=timeout, defer_round_trip=defer_round_trip
|
|
596
|
+
)
|
|
597
|
+
method = getattr(self.connection, "begin_sessionless_transaction", None)
|
|
598
|
+
if not callable(method):
|
|
599
|
+
msg = "Sessionless transactions require python-oracledb 26.1 or newer"
|
|
600
|
+
raise oracledb_module.NotSupportedError(msg)
|
|
601
|
+
try:
|
|
602
|
+
txid = method(resolved, timeout=timeout, defer_round_trip=defer_round_trip)
|
|
603
|
+
except OracleError as exc:
|
|
604
|
+
raise with_cause(create_mapped_exception(exc), exc) from exc
|
|
605
|
+
self._sessionless_transaction_id = cast("bytes", txid)
|
|
606
|
+
return self._sessionless_transaction_id
|
|
607
|
+
|
|
608
|
+
def resume_sessionless_transaction(
|
|
609
|
+
self, transaction_id: str | bytes, *, timeout: int = 60, defer_round_trip: bool = True
|
|
610
|
+
) -> bytes:
|
|
611
|
+
"""Attach a suspended native transaction to this connection."""
|
|
612
|
+
resolved = validate_sessionless_transaction_args(
|
|
613
|
+
transaction_id, timeout=timeout, is_resume=True, defer_round_trip=defer_round_trip
|
|
614
|
+
)
|
|
615
|
+
method = getattr(self.connection, "resume_sessionless_transaction", None)
|
|
616
|
+
if not callable(method):
|
|
617
|
+
msg = "Sessionless transactions require python-oracledb 26.1 or newer"
|
|
618
|
+
raise oracledb_module.NotSupportedError(msg)
|
|
619
|
+
try:
|
|
620
|
+
txid = method(cast("bytes", resolved), timeout=timeout, defer_round_trip=defer_round_trip)
|
|
621
|
+
except OracleError as exc:
|
|
622
|
+
raise with_cause(create_mapped_exception(exc), exc) from exc
|
|
623
|
+
self._sessionless_transaction_id = cast("bytes", txid)
|
|
624
|
+
return self._sessionless_transaction_id
|
|
625
|
+
|
|
626
|
+
def suspend_sessionless_transaction(self) -> None:
|
|
627
|
+
"""Detach the active transaction so another pooled connection can resume it."""
|
|
628
|
+
method = getattr(self.connection, "suspend_sessionless_transaction", None)
|
|
629
|
+
if not callable(method):
|
|
630
|
+
msg = "Sessionless transactions require python-oracledb 26.1 or newer"
|
|
631
|
+
raise oracledb_module.NotSupportedError(msg)
|
|
632
|
+
try:
|
|
633
|
+
method()
|
|
634
|
+
except BaseException as exc:
|
|
635
|
+
pending = create_mapped_exception(exc) if isinstance(exc, OracleError) else exc
|
|
636
|
+
if self._sessionless_transaction_id is not None:
|
|
637
|
+
self._sessionless_cleanup_error = pending
|
|
638
|
+
if pending is not exc:
|
|
639
|
+
pending.__cause__ = exc
|
|
640
|
+
raise pending from exc
|
|
641
|
+
raise
|
|
642
|
+
else:
|
|
643
|
+
self._sessionless_transaction_id = None
|
|
644
|
+
finally:
|
|
645
|
+
self._transaction_active = False
|
|
646
|
+
|
|
647
|
+
def sessionless_transaction(
|
|
648
|
+
self,
|
|
649
|
+
transaction_id: str | bytes | None = None,
|
|
650
|
+
*,
|
|
651
|
+
timeout: int = 60,
|
|
652
|
+
defer_round_trip: bool = True,
|
|
653
|
+
resume: bool = False,
|
|
654
|
+
rollback_on_error: bool = True,
|
|
655
|
+
) -> "OracleSyncSessionlessTransactionContext":
|
|
656
|
+
"""Scope a sessionless transaction and suspend it on successful exit."""
|
|
657
|
+
return OracleSyncSessionlessTransactionContext(
|
|
658
|
+
self,
|
|
659
|
+
transaction_id=transaction_id,
|
|
660
|
+
timeout=timeout,
|
|
661
|
+
defer_round_trip=defer_round_trip,
|
|
662
|
+
resume=resume,
|
|
663
|
+
rollback_on_error=rollback_on_error,
|
|
664
|
+
)
|
|
665
|
+
|
|
666
|
+
def execute(
|
|
667
|
+
self,
|
|
668
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
669
|
+
/,
|
|
670
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
671
|
+
statement_config: "StatementConfig | None" = None,
|
|
672
|
+
suspend_on_success: bool = False,
|
|
673
|
+
**kwargs: Any,
|
|
674
|
+
) -> SQLResult:
|
|
675
|
+
"""Execute a statement with optional native sessionless suspension."""
|
|
676
|
+
validate_sessionless_execution_options(suspend_on_success=suspend_on_success)
|
|
677
|
+
if suspend_on_success:
|
|
678
|
+
config = statement_config or self.statement_config
|
|
679
|
+
args = dict(config.execution_args or {})
|
|
680
|
+
args["oracle_suspend_on_success"] = True
|
|
681
|
+
statement_config = config.replace(execution_args=args)
|
|
682
|
+
if suspend_on_success:
|
|
683
|
+
prepared = self.prepare_statement(statement, parameters, statement_config=statement_config, kwargs=kwargs)
|
|
684
|
+
prepared = prepared.copy(statement_config=statement_config)
|
|
685
|
+
result = self.dispatch_statement_execution(prepared, self.connection)
|
|
686
|
+
else:
|
|
687
|
+
result = super().execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
688
|
+
if suspend_on_success:
|
|
689
|
+
self._sessionless_transaction_id = None
|
|
690
|
+
self._transaction_active = False
|
|
691
|
+
return result
|
|
692
|
+
|
|
693
|
+
def execute_many(
|
|
694
|
+
self,
|
|
695
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
696
|
+
/,
|
|
697
|
+
parameters: "Sequence[StatementParameters]",
|
|
698
|
+
*filters: "StatementParameters | StatementFilter",
|
|
699
|
+
statement_config: "StatementConfig | None" = None,
|
|
700
|
+
batch_size: int | None = None,
|
|
701
|
+
suspend_on_success: bool = False,
|
|
702
|
+
**kwargs: Any,
|
|
703
|
+
) -> SQLResult:
|
|
704
|
+
"""Execute a batch with validated native batching and suspension options."""
|
|
705
|
+
validate_sessionless_execution_options(suspend_on_success=suspend_on_success, batch_size=batch_size)
|
|
706
|
+
if suspend_on_success or batch_size is not None:
|
|
707
|
+
config = statement_config or self.statement_config
|
|
708
|
+
args = dict(config.execution_args or {})
|
|
709
|
+
if suspend_on_success:
|
|
710
|
+
args["oracle_suspend_on_success"] = True
|
|
711
|
+
if batch_size is not None:
|
|
712
|
+
args["oracle_batch_size"] = batch_size
|
|
713
|
+
statement_config = config.replace(execution_args=args)
|
|
714
|
+
result = super().execute_many(statement, parameters, *filters, statement_config=statement_config, **kwargs)
|
|
715
|
+
if suspend_on_success and parameters:
|
|
716
|
+
self._sessionless_transaction_id = None
|
|
717
|
+
self._transaction_active = False
|
|
718
|
+
return result
|
|
719
|
+
|
|
720
|
+
def dispatch_execute(self, cursor: Any, statement: "SQL") -> "ExecutionResult":
|
|
721
|
+
"""Execute single SQL statement with Oracle data handling.
|
|
722
|
+
|
|
723
|
+
For SELECT-like statements, fetches all rows, resolves row metadata, and
|
|
724
|
+
applies LOB coercion if needed. For non-SELECT statements, resolves and
|
|
725
|
+
returns the affected row count.
|
|
726
|
+
|
|
727
|
+
Args:
|
|
728
|
+
cursor: Oracle cursor object
|
|
729
|
+
statement: SQL statement to execute
|
|
730
|
+
|
|
731
|
+
Returns:
|
|
732
|
+
Execution result containing data for SELECT statements or row count for others
|
|
733
|
+
"""
|
|
734
|
+
|
|
735
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
736
|
+
|
|
737
|
+
prepared_parameters = coerce_large_parameters_sync(
|
|
738
|
+
self.connection,
|
|
739
|
+
prepared_parameters,
|
|
740
|
+
clob_type=DB_TYPE_CLOB,
|
|
741
|
+
blob_type=DB_TYPE_BLOB,
|
|
742
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
743
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
744
|
+
version_cache=self._oracle_version_cache,
|
|
745
|
+
)
|
|
746
|
+
prepared_parameters = cast("list[Any] | tuple[Any, ...] | dict[Any, Any] | None", prepared_parameters)
|
|
747
|
+
|
|
748
|
+
explained_sql = _managed_explain_statement(statement, sql)
|
|
749
|
+
if explained_sql is not None:
|
|
750
|
+
display_cursor, xplan_format = _managed_explain_options(statement)
|
|
751
|
+
return self._dispatch_explain_plan(
|
|
752
|
+
cursor, explained_sql, prepared_parameters, display_cursor=display_cursor, xplan_format=xplan_format
|
|
753
|
+
)
|
|
754
|
+
|
|
755
|
+
execution_args = statement.statement_config.execution_args or {}
|
|
756
|
+
fetch_kwargs = dict(self._fetch_kwargs)
|
|
757
|
+
if execution_args.get("oracle_suspend_on_success", False):
|
|
758
|
+
fetch_kwargs["suspend_on_success"] = True
|
|
759
|
+
cursor.execute(sql, prepared_parameters or {}, **fetch_kwargs)
|
|
760
|
+
|
|
761
|
+
is_select_like = statement.returns_rows() or self._should_force_select(statement, cursor)
|
|
762
|
+
|
|
763
|
+
if is_select_like and cursor.description is not None:
|
|
764
|
+
fetched_data = cursor.fetchall()
|
|
765
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
766
|
+
data, column_names = collect_sync_rows(
|
|
767
|
+
cast("list[Any] | None", fetched_data),
|
|
768
|
+
cursor.description,
|
|
769
|
+
self.driver_features,
|
|
770
|
+
column_names=column_names,
|
|
771
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
772
|
+
)
|
|
773
|
+
|
|
774
|
+
return self.create_execution_result(
|
|
775
|
+
cursor,
|
|
776
|
+
selected_data=data,
|
|
777
|
+
column_names=column_names,
|
|
778
|
+
data_row_count=len(data),
|
|
779
|
+
is_select_result=True,
|
|
780
|
+
row_format="tuple",
|
|
781
|
+
)
|
|
782
|
+
|
|
783
|
+
affected_rows = resolve_rowcount(cursor)
|
|
784
|
+
return self.create_execution_result(cursor, rowcount_override=affected_rows)
|
|
785
|
+
|
|
786
|
+
def dispatch_execute_many(self, cursor: Any, statement: "SQL") -> "ExecutionResult":
|
|
787
|
+
"""Execute SQL with multiple parameter sets using Oracle batch processing.
|
|
788
|
+
|
|
789
|
+
Args:
|
|
790
|
+
cursor: Oracle cursor object
|
|
791
|
+
statement: SQL statement with multiple parameter sets
|
|
792
|
+
|
|
793
|
+
Returns:
|
|
794
|
+
Execution result with affected row count
|
|
795
|
+
"""
|
|
796
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
797
|
+
|
|
798
|
+
prepared_parameters = coerce_many_parameters_sync(
|
|
799
|
+
self.connection,
|
|
800
|
+
prepared_parameters,
|
|
801
|
+
clob_type=DB_TYPE_CLOB,
|
|
802
|
+
blob_type=DB_TYPE_BLOB,
|
|
803
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
804
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
805
|
+
version_cache=self._oracle_version_cache,
|
|
806
|
+
)
|
|
807
|
+
execution_args = statement.statement_config.execution_args or {}
|
|
808
|
+
batch_errors = bool(execution_args.get("oracle_batch_errors", False))
|
|
809
|
+
array_dml_row_counts = bool(execution_args.get("oracle_array_dml_row_counts", False))
|
|
810
|
+
cursor.executemany(
|
|
811
|
+
sql,
|
|
812
|
+
prepared_parameters,
|
|
813
|
+
batcherrors=batch_errors,
|
|
814
|
+
arraydmlrowcounts=array_dml_row_counts,
|
|
815
|
+
**{
|
|
816
|
+
key: value
|
|
817
|
+
for key, value in {
|
|
818
|
+
"suspend_on_success": execution_args.get("oracle_suspend_on_success"),
|
|
819
|
+
"batch_size": execution_args.get("oracle_batch_size"),
|
|
820
|
+
}.items()
|
|
821
|
+
if value is not None
|
|
822
|
+
},
|
|
823
|
+
)
|
|
824
|
+
|
|
825
|
+
affected_rows = len(prepared_parameters)
|
|
826
|
+
special_data: dict[str, Any] | None = None
|
|
827
|
+
if batch_errors or array_dml_row_counts:
|
|
828
|
+
special_data = {}
|
|
829
|
+
if batch_errors:
|
|
830
|
+
special_data["oracle_batch_errors"] = [
|
|
831
|
+
{
|
|
832
|
+
"offset": cast("int | None", getattr(error, "offset", None)),
|
|
833
|
+
"code": cast("int | None", getattr(error, "code", None)),
|
|
834
|
+
"message": cast("str", getattr(error, "message", str(error))),
|
|
835
|
+
}
|
|
836
|
+
for error in cursor.getbatcherrors()
|
|
837
|
+
]
|
|
838
|
+
if array_dml_row_counts:
|
|
839
|
+
row_counts = list(cursor.getarraydmlrowcounts())
|
|
840
|
+
special_data["oracle_dml_row_counts"] = row_counts
|
|
841
|
+
affected_rows = sum(row_counts)
|
|
842
|
+
|
|
843
|
+
return self.create_execution_result(
|
|
844
|
+
cursor, rowcount_override=affected_rows, special_data=special_data, is_many_result=True
|
|
845
|
+
)
|
|
846
|
+
|
|
847
|
+
def dispatch_execute_script(self, cursor: Any, statement: "SQL") -> "ExecutionResult":
|
|
848
|
+
"""Execute SQL script with statement splitting and parameter handling."""
|
|
849
|
+
bound_statements = self._bound_script_statements(statement)
|
|
850
|
+
if bound_statements is not None:
|
|
851
|
+
return self._dispatch_bound_script(cursor, bound_statements)
|
|
852
|
+
|
|
853
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
854
|
+
prepared_parameters = coerce_large_parameters_sync(
|
|
855
|
+
self.connection,
|
|
856
|
+
prepared_parameters,
|
|
857
|
+
clob_type=DB_TYPE_CLOB,
|
|
858
|
+
blob_type=DB_TYPE_BLOB,
|
|
859
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
860
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
861
|
+
version_cache=self._oracle_version_cache,
|
|
862
|
+
)
|
|
863
|
+
statements = self.split_script_statements(sql, statement.statement_config, strip_trailing_semicolon=True)
|
|
864
|
+
|
|
865
|
+
successful_count = 0
|
|
866
|
+
last_cursor = cursor
|
|
867
|
+
pos_offset = 0
|
|
868
|
+
total_statements = len(statements)
|
|
869
|
+
runtime = self._observability
|
|
870
|
+
has_observers = runtime is not None and runtime.has_statement_observers
|
|
871
|
+
|
|
872
|
+
for idx, stmt in enumerate(statements):
|
|
873
|
+
stmt_params, pos_offset = _slice_script_parameters(stmt, prepared_parameters, pos_offset)
|
|
874
|
+
stmt_started = perf_counter() if has_observers else 0.0
|
|
875
|
+
cursor.execute(stmt, stmt_params)
|
|
876
|
+
successful_count += 1
|
|
877
|
+
if has_observers:
|
|
878
|
+
stmt_duration = perf_counter() - stmt_started
|
|
879
|
+
single_stmt = self._sub_statement(stmt, stmt_params)
|
|
880
|
+
try:
|
|
881
|
+
stmt_operation = single_stmt.operation_type
|
|
882
|
+
finally:
|
|
883
|
+
self._release_pooled_statement(single_stmt)
|
|
884
|
+
self._emit_script_statement_event(
|
|
885
|
+
sql=stmt,
|
|
886
|
+
parameters=stmt_params,
|
|
887
|
+
operation=stmt_operation,
|
|
888
|
+
rows_affected=resolve_rowcount(cursor),
|
|
889
|
+
duration_s=stmt_duration,
|
|
890
|
+
started_at=stmt_started,
|
|
891
|
+
profile=None,
|
|
892
|
+
script_ordinal=idx,
|
|
893
|
+
script_statement_count=total_statements,
|
|
894
|
+
)
|
|
895
|
+
|
|
896
|
+
self._pending_statement_profile = None
|
|
897
|
+
return self.create_execution_result(
|
|
898
|
+
last_cursor, statement_count=total_statements, successful_statements=successful_count, is_script_result=True
|
|
899
|
+
)
|
|
900
|
+
|
|
901
|
+
def begin(self) -> None:
|
|
902
|
+
"""Begin a database transaction.
|
|
903
|
+
|
|
904
|
+
Oracle starts a transaction implicitly on the first DML, so no explicit
|
|
905
|
+
statement is issued; the active-transaction flag is set here.
|
|
906
|
+
"""
|
|
907
|
+
self._transaction_active = True
|
|
908
|
+
|
|
909
|
+
def commit(self) -> None:
|
|
910
|
+
"""Commit the current transaction.
|
|
911
|
+
|
|
912
|
+
Raises:
|
|
913
|
+
SQLSpecError: If commit fails
|
|
914
|
+
"""
|
|
915
|
+
|
|
916
|
+
try:
|
|
917
|
+
self.connection.commit()
|
|
918
|
+
except BaseException as exc:
|
|
919
|
+
pending = create_mapped_exception(exc) if isinstance(exc, OracleError) else exc
|
|
920
|
+
if self._sessionless_transaction_id is not None:
|
|
921
|
+
self._sessionless_cleanup_error = pending
|
|
922
|
+
if pending is not exc:
|
|
923
|
+
pending.__cause__ = exc
|
|
924
|
+
raise pending from exc
|
|
925
|
+
raise
|
|
926
|
+
else:
|
|
927
|
+
self._sessionless_transaction_id = None
|
|
928
|
+
finally:
|
|
929
|
+
self._transaction_active = False
|
|
930
|
+
|
|
931
|
+
def rollback(self) -> None:
|
|
932
|
+
"""Rollback the current transaction.
|
|
933
|
+
|
|
934
|
+
Raises:
|
|
935
|
+
SQLSpecError: If rollback fails
|
|
936
|
+
"""
|
|
937
|
+
|
|
938
|
+
try:
|
|
939
|
+
self.connection.rollback()
|
|
940
|
+
except BaseException as exc:
|
|
941
|
+
pending = create_mapped_exception(exc) if isinstance(exc, OracleError) else exc
|
|
942
|
+
if self._sessionless_transaction_id is not None:
|
|
943
|
+
self._sessionless_cleanup_error = pending
|
|
944
|
+
if pending is not exc:
|
|
945
|
+
pending.__cause__ = exc
|
|
946
|
+
raise pending from exc
|
|
947
|
+
raise
|
|
948
|
+
else:
|
|
949
|
+
self._sessionless_transaction_id = None
|
|
950
|
+
finally:
|
|
951
|
+
self._transaction_active = False
|
|
952
|
+
|
|
953
|
+
def release_savepoint(self, name: str) -> None:
|
|
954
|
+
"""Validate the savepoint name; Oracle releases savepoints when the transaction ends."""
|
|
955
|
+
validate_savepoint_name(name)
|
|
956
|
+
|
|
957
|
+
def set_migration_session_schema(self, schema: str) -> None:
|
|
958
|
+
"""Set Oracle CURRENT_SCHEMA for migration SQL, remembering the schema in effect on the first switch.
|
|
959
|
+
|
|
960
|
+
Args:
|
|
961
|
+
schema: Schema to make current. Unquoted lowercase names fold to uppercase.
|
|
962
|
+
"""
|
|
963
|
+
normalized_schema = normalize_identifier(schema, "oracle")
|
|
964
|
+
quoted_schema = quote_identifier(normalized_schema)
|
|
965
|
+
with self.with_cursor(self.connection) as cursor:
|
|
966
|
+
if self._migration_schema_restore is None:
|
|
967
|
+
cursor.execute("SELECT SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA') FROM DUAL")
|
|
968
|
+
row = cursor.fetchone()
|
|
969
|
+
self._migration_schema_restore = str(row[0])
|
|
970
|
+
cursor.execute(f"ALTER SESSION SET CURRENT_SCHEMA = {quoted_schema}")
|
|
971
|
+
|
|
972
|
+
def reset_migration_session_schema(self) -> None:
|
|
973
|
+
"""Restore the schema captured by ``set_migration_session_schema`` with its exact catalog case."""
|
|
974
|
+
previous_schema = self._migration_schema_restore
|
|
975
|
+
if previous_schema is None:
|
|
976
|
+
return
|
|
977
|
+
with self.with_cursor(self.connection) as cursor:
|
|
978
|
+
cursor.execute(f"ALTER SESSION SET CURRENT_SCHEMA = {quote_identifier(previous_schema)}")
|
|
979
|
+
self._migration_schema_restore = None
|
|
980
|
+
|
|
981
|
+
def has_schema(self, schema: str) -> bool:
|
|
982
|
+
"""Return whether an Oracle schema/user exists."""
|
|
983
|
+
normalized_schema = normalize_identifier(schema, "oracle")
|
|
984
|
+
with self.with_cursor(self.connection) as cursor:
|
|
985
|
+
cursor.execute("SELECT 1 FROM ALL_USERS WHERE USERNAME = :schema_name", {"schema_name": normalized_schema})
|
|
986
|
+
return cursor.fetchone() is not None
|
|
987
|
+
|
|
988
|
+
def with_cursor(self, connection: OracleSyncConnection) -> OracleSyncCursor:
|
|
989
|
+
"""Create context manager for Oracle cursor.
|
|
990
|
+
|
|
991
|
+
Args:
|
|
992
|
+
connection: Oracle database connection
|
|
993
|
+
|
|
994
|
+
Returns:
|
|
995
|
+
Context manager for cursor operations
|
|
996
|
+
"""
|
|
997
|
+
return OracleSyncCursor(
|
|
998
|
+
connection,
|
|
999
|
+
arraysize=self.driver_features.get("arraysize"),
|
|
1000
|
+
prefetchrows=self.driver_features.get("prefetchrows"),
|
|
1001
|
+
on_enter=self._apply_session_tracing
|
|
1002
|
+
if self._session_tracing_enabled or self._otel_tracing_enabled
|
|
1003
|
+
else None,
|
|
1004
|
+
)
|
|
1005
|
+
|
|
1006
|
+
@overload
|
|
1007
|
+
def select_stream(
|
|
1008
|
+
self,
|
|
1009
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1010
|
+
/,
|
|
1011
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1012
|
+
schema_type: "type[SchemaT]",
|
|
1013
|
+
statement_config: "StatementConfig | None" = None,
|
|
1014
|
+
chunk_size: int = 1000,
|
|
1015
|
+
native_only: bool = False,
|
|
1016
|
+
**kwargs: Any,
|
|
1017
|
+
) -> "SyncRowStream[SchemaT]": ...
|
|
1018
|
+
@overload
|
|
1019
|
+
def select_stream(
|
|
1020
|
+
self,
|
|
1021
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1022
|
+
/,
|
|
1023
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1024
|
+
schema_type: None = None,
|
|
1025
|
+
statement_config: "StatementConfig | None" = None,
|
|
1026
|
+
chunk_size: int = 1000,
|
|
1027
|
+
native_only: bool = False,
|
|
1028
|
+
**kwargs: Any,
|
|
1029
|
+
) -> "SyncRowStream[dict[str, Any]]": ...
|
|
1030
|
+
def select_stream(
|
|
1031
|
+
self,
|
|
1032
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1033
|
+
/,
|
|
1034
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1035
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
1036
|
+
statement_config: "StatementConfig | None" = None,
|
|
1037
|
+
chunk_size: int = 1000,
|
|
1038
|
+
native_only: bool = False,
|
|
1039
|
+
**kwargs: Any,
|
|
1040
|
+
) -> "SyncRowStream[SchemaT] | SyncRowStream[dict[str, Any]]":
|
|
1041
|
+
"""Execute a query and stream rows in chunks with Oracle fetch tuning."""
|
|
1042
|
+
fetch_lobs = cast("bool | None", kwargs.pop("fetch_lobs", None))
|
|
1043
|
+
if chunk_size < 1:
|
|
1044
|
+
msg = "chunk_size must be greater than or equal to 1"
|
|
1045
|
+
raise ValueError(msg)
|
|
1046
|
+
config = statement_config or self.statement_config
|
|
1047
|
+
sql_statement = self.prepare_statement(statement, parameters, statement_config=config, kwargs=kwargs)
|
|
1048
|
+
stream = self.dispatch_select_stream(sql_statement, chunk_size, fetch_lobs=fetch_lobs)
|
|
1049
|
+
if stream is not None:
|
|
1050
|
+
return self._register_open_stream(stream._with_schema_type(schema_type))
|
|
1051
|
+
return super().select_stream(
|
|
1052
|
+
sql_statement,
|
|
1053
|
+
schema_type=schema_type,
|
|
1054
|
+
statement_config=config,
|
|
1055
|
+
chunk_size=chunk_size,
|
|
1056
|
+
native_only=native_only,
|
|
1057
|
+
)
|
|
1058
|
+
|
|
1059
|
+
def dispatch_select_stream(
|
|
1060
|
+
self, statement: "SQL", chunk_size: int, fetch_lobs: bool | None = None
|
|
1061
|
+
) -> "SyncRowStream[dict[str, Any]] | None":
|
|
1062
|
+
"""Return a native oracledb row stream backed by chunked ``fetchmany``."""
|
|
1063
|
+
if not statement.returns_rows():
|
|
1064
|
+
return None
|
|
1065
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
1066
|
+
stream_parameters = cast("list[object] | tuple[object, ...] | dict[object, object] | None", prepared_parameters)
|
|
1067
|
+
return SyncRowStream(OracleSyncStreamSource(self, sql, stream_parameters, chunk_size, fetch_lobs=fetch_lobs))
|
|
1068
|
+
|
|
1069
|
+
def handle_database_exceptions(self) -> "OracleSyncExceptionHandler":
|
|
1070
|
+
"""Handle database-specific exceptions and wrap them appropriately."""
|
|
1071
|
+
return OracleSyncExceptionHandler()
|
|
1072
|
+
|
|
1073
|
+
def select_to_arrow(
|
|
1074
|
+
self,
|
|
1075
|
+
statement: "Statement | QueryBuilder",
|
|
1076
|
+
/,
|
|
1077
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1078
|
+
statement_config: "StatementConfig | None" = None,
|
|
1079
|
+
return_format: "ArrowReturnFormat" = "table",
|
|
1080
|
+
native_only: bool = False,
|
|
1081
|
+
batch_size: int | None = None,
|
|
1082
|
+
arrow_schema: Any = None,
|
|
1083
|
+
**kwargs: Any,
|
|
1084
|
+
) -> "ArrowResult":
|
|
1085
|
+
"""Execute query and return results as Apache Arrow format using Oracle native support.
|
|
1086
|
+
|
|
1087
|
+
This implementation uses Oracle's native execute_df()/fetch_df_all() methods
|
|
1088
|
+
which return OracleDataFrame objects with Arrow C Stream interface, providing
|
|
1089
|
+
zero-copy data transfer and 5-10x performance improvement over dict conversion.
|
|
1090
|
+
If native Arrow is unavailable and native_only is False, it falls back to the
|
|
1091
|
+
conversion path.
|
|
1092
|
+
|
|
1093
|
+
Args:
|
|
1094
|
+
statement: SQL query string, Statement, or QueryBuilder
|
|
1095
|
+
*parameters: Query parameters (same format as execute()/select())
|
|
1096
|
+
statement_config: Optional statement configuration override
|
|
1097
|
+
return_format: "table" for pyarrow.Table (default), "batch" for RecordBatch,
|
|
1098
|
+
"batches" for list of RecordBatch, "reader" for RecordBatchReader
|
|
1099
|
+
native_only: If True, raise error if native Arrow is unavailable
|
|
1100
|
+
batch_size: Rows per batch when using "batch" or "batches" format
|
|
1101
|
+
arrow_schema: Optional pyarrow.Schema for type casting
|
|
1102
|
+
**kwargs: Additional keyword arguments
|
|
1103
|
+
|
|
1104
|
+
Returns:
|
|
1105
|
+
ArrowResult containing pyarrow.Table or RecordBatch
|
|
1106
|
+
"""
|
|
1107
|
+
ensure_pyarrow()
|
|
1108
|
+
|
|
1109
|
+
config = statement_config or self.statement_config
|
|
1110
|
+
prepared_statement = self.prepare_statement(statement, parameters, statement_config=config, kwargs=kwargs)
|
|
1111
|
+
sql, prepared_parameters = self._compiled_sql(prepared_statement, config)
|
|
1112
|
+
|
|
1113
|
+
prepared_parameters = coerce_large_parameters_sync(
|
|
1114
|
+
self.connection,
|
|
1115
|
+
prepared_parameters,
|
|
1116
|
+
clob_type=DB_TYPE_CLOB,
|
|
1117
|
+
blob_type=DB_TYPE_BLOB,
|
|
1118
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
1119
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
1120
|
+
version_cache=self._oracle_version_cache,
|
|
1121
|
+
)
|
|
1122
|
+
prepared_parameters = cast("list[Any] | tuple[Any, ...] | dict[Any, Any] | None", prepared_parameters)
|
|
1123
|
+
|
|
1124
|
+
exc_handler = self.handle_database_exceptions()
|
|
1125
|
+
try:
|
|
1126
|
+
self._apply_session_tracing(self.connection)
|
|
1127
|
+
if return_format == "reader" and supports_df_batches(self.connection):
|
|
1128
|
+
batch_generator = self._iter_arrow_record_batches(sql, prepared_parameters, batch_size, arrow_schema)
|
|
1129
|
+
try:
|
|
1130
|
+
first_batch = next(batch_generator)
|
|
1131
|
+
except StopIteration:
|
|
1132
|
+
pa = import_pyarrow()
|
|
1133
|
+
empty_schema = arrow_schema if arrow_schema is not None else pa.schema([])
|
|
1134
|
+
reader = pa.RecordBatchReader.from_batches(empty_schema, ())
|
|
1135
|
+
return create_arrow_result(prepared_statement, reader, rows_affected=0)
|
|
1136
|
+
pa = import_pyarrow()
|
|
1137
|
+
schema = arrow_schema if arrow_schema is not None else first_batch.schema
|
|
1138
|
+
lazy_reader = pa.RecordBatchReader.from_batches(schema, chain((first_batch,), batch_generator))
|
|
1139
|
+
return create_arrow_result(
|
|
1140
|
+
prepared_statement, lazy_reader, rows_affected=-1, metadata={"stream_close": batch_generator.close}
|
|
1141
|
+
)
|
|
1142
|
+
|
|
1143
|
+
if return_format == "batches" and supports_df_batches(self.connection):
|
|
1144
|
+
batches_result = cast(
|
|
1145
|
+
"tuple[list[ArrowRecordBatch], ArrowSchema | None]",
|
|
1146
|
+
self._run_with_exception_handler(
|
|
1147
|
+
exc_handler,
|
|
1148
|
+
self._fetch_arrow_record_batches,
|
|
1149
|
+
sql,
|
|
1150
|
+
prepared_parameters,
|
|
1151
|
+
batch_size,
|
|
1152
|
+
arrow_schema,
|
|
1153
|
+
),
|
|
1154
|
+
)
|
|
1155
|
+
self._check_pending_exception(exc_handler)
|
|
1156
|
+
record_batches, _ = batches_result
|
|
1157
|
+
rows_affected = sum(batch.num_rows for batch in record_batches)
|
|
1158
|
+
return create_arrow_result(prepared_statement, record_batches, rows_affected=rows_affected)
|
|
1159
|
+
|
|
1160
|
+
oracle_df = self._run_with_exception_handler(
|
|
1161
|
+
exc_handler, self._execute_arrow_dataframe, sql, prepared_parameters, batch_size
|
|
1162
|
+
)
|
|
1163
|
+
except AttributeError as exc:
|
|
1164
|
+
if native_only:
|
|
1165
|
+
msg = "Oracle native Arrow support is not available for this connection."
|
|
1166
|
+
error = ImproperConfigurationError(msg)
|
|
1167
|
+
error.__cause__ = exc
|
|
1168
|
+
raise error from exc
|
|
1169
|
+
return super().select_to_arrow(
|
|
1170
|
+
prepared_statement,
|
|
1171
|
+
statement_config=config,
|
|
1172
|
+
return_format=return_format,
|
|
1173
|
+
native_only=native_only,
|
|
1174
|
+
batch_size=batch_size,
|
|
1175
|
+
arrow_schema=arrow_schema,
|
|
1176
|
+
)
|
|
1177
|
+
self._check_pending_exception(exc_handler)
|
|
1178
|
+
|
|
1179
|
+
arrow_table = coerce_oracle_df_to_arrow_table(oracle_df, import_pyarrow())
|
|
1180
|
+
column_names = normalize_column_names(arrow_table.column_names, self.driver_features)
|
|
1181
|
+
if column_names != arrow_table.column_names:
|
|
1182
|
+
arrow_table = arrow_table.rename_columns(column_names)
|
|
1183
|
+
|
|
1184
|
+
return build_arrow_result_from_table(
|
|
1185
|
+
prepared_statement,
|
|
1186
|
+
arrow_table,
|
|
1187
|
+
return_format=return_format,
|
|
1188
|
+
batch_size=batch_size,
|
|
1189
|
+
arrow_schema=arrow_schema,
|
|
1190
|
+
)
|
|
1191
|
+
|
|
1192
|
+
def execute_stack(self, stack: "StatementStack", *, continue_on_error: bool = False) -> "tuple[StackResult, ...]":
|
|
1193
|
+
"""Execute a StatementStack sequentially on the sync driver."""
|
|
1194
|
+
self._log_pipeline_skip("asyncio_thin_required", stack)
|
|
1195
|
+
return super().execute_stack(stack, continue_on_error=continue_on_error)
|
|
1196
|
+
|
|
1197
|
+
def select_to_storage(
|
|
1198
|
+
self,
|
|
1199
|
+
statement: "Statement | QueryBuilder | SQL | str",
|
|
1200
|
+
destination: "StorageDestination",
|
|
1201
|
+
/,
|
|
1202
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1203
|
+
statement_config: "StatementConfig | None" = None,
|
|
1204
|
+
partitioner: "dict[str, object] | None" = None,
|
|
1205
|
+
format_hint: "StorageFormat | None" = None,
|
|
1206
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
1207
|
+
**kwargs: Any,
|
|
1208
|
+
) -> "StorageBridgeJob":
|
|
1209
|
+
"""Execute a query and stream Arrow-formatted output to storage (sync)."""
|
|
1210
|
+
self._require_capability("arrow_export_enabled")
|
|
1211
|
+
arrow_result = self._select_for_storage(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
1212
|
+
sync_pipeline = self._storage_pipeline()
|
|
1213
|
+
telemetry_payload = self._write_storage_result(
|
|
1214
|
+
arrow_result, destination, format_hint=format_hint, pipeline=sync_pipeline
|
|
1215
|
+
)
|
|
1216
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
1217
|
+
return self._storage_job(telemetry_payload, telemetry)
|
|
1218
|
+
|
|
1219
|
+
def load_from_arrow(
|
|
1220
|
+
self,
|
|
1221
|
+
table: str,
|
|
1222
|
+
source: "ArrowResult | Any",
|
|
1223
|
+
*,
|
|
1224
|
+
partitioner: "dict[str, object] | None" = None,
|
|
1225
|
+
overwrite: bool = False,
|
|
1226
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
1227
|
+
stage_table: "bool | str | None" = False,
|
|
1228
|
+
conflict_keys: "Sequence[str] | None" = None,
|
|
1229
|
+
on_conflict: Literal["update", "nothing"] = "update",
|
|
1230
|
+
exclude_update_columns: "Sequence[str] | None" = None,
|
|
1231
|
+
drop_stage_table: bool = True,
|
|
1232
|
+
drop_indexes: bool = False,
|
|
1233
|
+
concurrent_indexes: bool = True,
|
|
1234
|
+
type_casts: "Mapping[str, str] | None" = None,
|
|
1235
|
+
) -> "StorageBridgeJob":
|
|
1236
|
+
"""Load Arrow data into Oracle using batched executemany calls."""
|
|
1237
|
+
self._require_capability("arrow_import_enabled")
|
|
1238
|
+
if drop_indexes:
|
|
1239
|
+
with self.without_indexes(table, concurrent=concurrent_indexes):
|
|
1240
|
+
return self.load_from_arrow(
|
|
1241
|
+
table,
|
|
1242
|
+
source,
|
|
1243
|
+
partitioner=partitioner,
|
|
1244
|
+
overwrite=overwrite,
|
|
1245
|
+
telemetry=telemetry,
|
|
1246
|
+
stage_table=stage_table,
|
|
1247
|
+
conflict_keys=conflict_keys,
|
|
1248
|
+
on_conflict=on_conflict,
|
|
1249
|
+
exclude_update_columns=exclude_update_columns,
|
|
1250
|
+
drop_stage_table=drop_stage_table,
|
|
1251
|
+
drop_indexes=False,
|
|
1252
|
+
concurrent_indexes=concurrent_indexes,
|
|
1253
|
+
type_casts=type_casts,
|
|
1254
|
+
)
|
|
1255
|
+
if stage_table or conflict_keys:
|
|
1256
|
+
return self._execute_staged_load_sync(
|
|
1257
|
+
table,
|
|
1258
|
+
source,
|
|
1259
|
+
raw_loader=self.load_from_arrow,
|
|
1260
|
+
partitioner=partitioner,
|
|
1261
|
+
overwrite=overwrite,
|
|
1262
|
+
telemetry=telemetry,
|
|
1263
|
+
stage_table=stage_table,
|
|
1264
|
+
conflict_keys=conflict_keys,
|
|
1265
|
+
on_conflict=on_conflict,
|
|
1266
|
+
exclude_update_columns=exclude_update_columns,
|
|
1267
|
+
drop_stage_table=drop_stage_table,
|
|
1268
|
+
drop_indexes=False,
|
|
1269
|
+
concurrent_indexes=concurrent_indexes,
|
|
1270
|
+
type_casts=type_casts,
|
|
1271
|
+
)
|
|
1272
|
+
arrow_table = self._coerce_arrow_table(source)
|
|
1273
|
+
if overwrite:
|
|
1274
|
+
statement = build_truncate_statement(table)
|
|
1275
|
+
exc_handler = self.handle_database_exceptions()
|
|
1276
|
+
|
|
1277
|
+
def _truncate() -> None:
|
|
1278
|
+
cursor = self.connection.cursor()
|
|
1279
|
+
try:
|
|
1280
|
+
cursor.execute(statement)
|
|
1281
|
+
finally:
|
|
1282
|
+
cursor.close()
|
|
1283
|
+
|
|
1284
|
+
self._run_with_exception_handler(exc_handler, _truncate)
|
|
1285
|
+
self._check_pending_exception(exc_handler)
|
|
1286
|
+
use_direct_path = (
|
|
1287
|
+
self.driver_features.get("enable_direct_path_load", True) is not False
|
|
1288
|
+
and supports_direct_path_load(self.connection)
|
|
1289
|
+
and _arrow_schema_supports_direct_path(arrow_table)
|
|
1290
|
+
)
|
|
1291
|
+
if arrow_table.num_rows:
|
|
1292
|
+
if use_direct_path:
|
|
1293
|
+
schema_name, table_name = _resolve_direct_path_target(self.connection, table)
|
|
1294
|
+
exc_handler = self.handle_database_exceptions()
|
|
1295
|
+
self._run_with_exception_handler(
|
|
1296
|
+
exc_handler,
|
|
1297
|
+
self.connection.direct_path_load,
|
|
1298
|
+
schema_name=schema_name,
|
|
1299
|
+
table_name=table_name,
|
|
1300
|
+
column_names=list(arrow_table.column_names),
|
|
1301
|
+
data=arrow_table,
|
|
1302
|
+
)
|
|
1303
|
+
self._check_pending_exception(exc_handler)
|
|
1304
|
+
else:
|
|
1305
|
+
columns = list(arrow_table.column_names)
|
|
1306
|
+
statement = build_insert_statement(table, columns)
|
|
1307
|
+
exc_handler = self.handle_database_exceptions()
|
|
1308
|
+
|
|
1309
|
+
def _insert_batches() -> None:
|
|
1310
|
+
with self.with_cursor(self.connection) as cursor:
|
|
1311
|
+
for batch in arrow_table.to_batches(max_chunksize=5000):
|
|
1312
|
+
batch_rows = self._arrow_batch_to_rows(batch, columns)
|
|
1313
|
+
coerced_rows = coerce_many_parameters_sync(
|
|
1314
|
+
self.connection,
|
|
1315
|
+
batch_rows,
|
|
1316
|
+
clob_type=DB_TYPE_CLOB,
|
|
1317
|
+
blob_type=DB_TYPE_BLOB,
|
|
1318
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
1319
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
1320
|
+
version_cache=self._oracle_version_cache,
|
|
1321
|
+
)
|
|
1322
|
+
cursor.executemany(statement, coerced_rows)
|
|
1323
|
+
|
|
1324
|
+
self._run_with_exception_handler(exc_handler, _insert_batches)
|
|
1325
|
+
self._check_pending_exception(exc_handler)
|
|
1326
|
+
telemetry_payload = self._ingest_telemetry(arrow_table)
|
|
1327
|
+
telemetry_payload["destination"] = table
|
|
1328
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
1329
|
+
return self._storage_job(telemetry_payload, telemetry)
|
|
1330
|
+
|
|
1331
|
+
def load_from_storage(
|
|
1332
|
+
self,
|
|
1333
|
+
table: str,
|
|
1334
|
+
source: "StorageDestination",
|
|
1335
|
+
*,
|
|
1336
|
+
file_format: "StorageFormat",
|
|
1337
|
+
partitioner: "dict[str, object] | None" = None,
|
|
1338
|
+
overwrite: bool = False,
|
|
1339
|
+
credential_name: str | None = None,
|
|
1340
|
+
format_options: "Mapping[str, Any] | None" = None,
|
|
1341
|
+
**kwargs: Any,
|
|
1342
|
+
) -> "StorageBridgeJob":
|
|
1343
|
+
"""Load staged artifacts into Oracle via ``DBMS_CLOUD.COPY_DATA`` or client-side Arrow."""
|
|
1344
|
+
raw_credential = (
|
|
1345
|
+
credential_name if credential_name is not None else self.driver_features.get("dbms_cloud_credential")
|
|
1346
|
+
)
|
|
1347
|
+
effective_credential = (
|
|
1348
|
+
raw_credential.strip() if isinstance(raw_credential, str) and raw_credential.strip() else None
|
|
1349
|
+
)
|
|
1350
|
+
if effective_credential is not None and not kwargs:
|
|
1351
|
+
resolved_source: StorageDestination = (
|
|
1352
|
+
self._storage_pipeline().resolve_destination(source).uri
|
|
1353
|
+
if isinstance(source, str) and source.startswith("alias://")
|
|
1354
|
+
else source
|
|
1355
|
+
)
|
|
1356
|
+
remote_uri = (
|
|
1357
|
+
resolve_dbms_cloud_source_uri(resolved_source, file_format=file_format)
|
|
1358
|
+
if isinstance(resolved_source, (str, Path))
|
|
1359
|
+
else None
|
|
1360
|
+
)
|
|
1361
|
+
if remote_uri is not None:
|
|
1362
|
+
plsql, binds = build_dbms_cloud_copy_data_sql(
|
|
1363
|
+
table,
|
|
1364
|
+
credential_name=effective_credential,
|
|
1365
|
+
file_uri=remote_uri,
|
|
1366
|
+
file_format=file_format,
|
|
1367
|
+
format_options=format_options,
|
|
1368
|
+
)
|
|
1369
|
+
truncate_sql = build_truncate_statement(table) if overwrite else None
|
|
1370
|
+
rows_processed = 0
|
|
1371
|
+
exc_handler = self.handle_database_exceptions()
|
|
1372
|
+
|
|
1373
|
+
def _run_dbms_cloud() -> None:
|
|
1374
|
+
nonlocal rows_processed
|
|
1375
|
+
with self.with_cursor(self.connection) as cursor:
|
|
1376
|
+
if truncate_sql is not None:
|
|
1377
|
+
cursor.execute(truncate_sql)
|
|
1378
|
+
cursor.execute(plsql, binds)
|
|
1379
|
+
rows_processed = resolve_rowcount(cursor)
|
|
1380
|
+
|
|
1381
|
+
self._run_with_exception_handler(exc_handler, _run_dbms_cloud)
|
|
1382
|
+
self._check_pending_exception(exc_handler)
|
|
1383
|
+
telemetry_payload: StorageTelemetry = {
|
|
1384
|
+
"destination": table,
|
|
1385
|
+
"backend": "dbms_cloud",
|
|
1386
|
+
"format": file_format,
|
|
1387
|
+
"rows_processed": rows_processed,
|
|
1388
|
+
"extra": {"source_uri": remote_uri, "credential_name": effective_credential},
|
|
1389
|
+
}
|
|
1390
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
1391
|
+
return self._storage_job(telemetry_payload)
|
|
1392
|
+
if kwargs:
|
|
1393
|
+
validate_load_from_storage_kwargs(kwargs)
|
|
1394
|
+
return super().load_from_storage(
|
|
1395
|
+
table,
|
|
1396
|
+
source,
|
|
1397
|
+
file_format=file_format,
|
|
1398
|
+
partitioner=partitioner,
|
|
1399
|
+
overwrite=overwrite,
|
|
1400
|
+
storage_options=kwargs.get("storage_options"),
|
|
1401
|
+
stage_table=kwargs.get("stage_table"),
|
|
1402
|
+
conflict_keys=kwargs.get("conflict_keys"),
|
|
1403
|
+
on_conflict=kwargs.get("on_conflict", "update"),
|
|
1404
|
+
exclude_update_columns=kwargs.get("exclude_update_columns"),
|
|
1405
|
+
drop_stage_table=kwargs.get("drop_stage_table", True),
|
|
1406
|
+
drop_indexes=kwargs.get("drop_indexes", False),
|
|
1407
|
+
concurrent_indexes=kwargs.get("concurrent_indexes", False),
|
|
1408
|
+
checkpoint_table=kwargs.get("checkpoint_table"),
|
|
1409
|
+
checkpoint_phase=kwargs.get("checkpoint_phase", "default"),
|
|
1410
|
+
max_workers=kwargs.get("max_workers", 1),
|
|
1411
|
+
executor=kwargs.get("executor", "thread"),
|
|
1412
|
+
arrow_schema=kwargs.get("arrow_schema"),
|
|
1413
|
+
type_casts=kwargs.get("type_casts"),
|
|
1414
|
+
)
|
|
1415
|
+
arrow_table, inbound = self._read_storage_arrow(source, file_format=file_format)
|
|
1416
|
+
return self.load_from_arrow(table, arrow_table, partitioner=partitioner, overwrite=overwrite, telemetry=inbound)
|
|
1417
|
+
|
|
1418
|
+
def collect_rows(self, cursor: Any, fetched: "list[Any]") -> "tuple[list[Any], list[str], int]":
|
|
1419
|
+
"""Collect Oracle sync rows for the direct execution path."""
|
|
1420
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
1421
|
+
data, column_names = collect_sync_rows(
|
|
1422
|
+
cast("list[Any] | None", fetched),
|
|
1423
|
+
cursor.description,
|
|
1424
|
+
self.driver_features,
|
|
1425
|
+
column_names=column_names,
|
|
1426
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
1427
|
+
)
|
|
1428
|
+
return data, column_names, len(data)
|
|
1429
|
+
|
|
1430
|
+
def resolve_rowcount(self, cursor: Any) -> int:
|
|
1431
|
+
"""Resolve rowcount from Oracle cursor for the direct execution path."""
|
|
1432
|
+
return resolve_rowcount(cursor)
|
|
1433
|
+
|
|
1434
|
+
def _pipeline_native_supported(self) -> bool:
|
|
1435
|
+
"""Sync Oracle connections do not support native pipelining."""
|
|
1436
|
+
return False
|
|
1437
|
+
|
|
1438
|
+
def _execute_cache_hit_with_cursor(
|
|
1439
|
+
self, sql: str, params: "tuple[Any, ...] | list[Any] | dict[str, Any]", cached: "CachedQuery"
|
|
1440
|
+
) -> "SQLResult":
|
|
1441
|
+
"""Execute a cached query through the compiled Oracle cache-hit executor."""
|
|
1442
|
+
return execute_cache_hit(self.connection, sql, params, cached, self.statement_config, self._cache_hit_state)
|
|
1443
|
+
|
|
1444
|
+
def _connection_in_transaction(self) -> bool:
|
|
1445
|
+
"""Report whether a transaction is open on the connection.
|
|
1446
|
+
|
|
1447
|
+
Oracle opens a transaction implicitly on the first DML, which the
|
|
1448
|
+
ownership flag alone cannot see, while ``begin()`` sets the flag without
|
|
1449
|
+
issuing SQL, which the native predicate alone cannot see. Both signals
|
|
1450
|
+
are required.
|
|
1451
|
+
"""
|
|
1452
|
+
return (
|
|
1453
|
+
self._sessionless_transaction_id is not None
|
|
1454
|
+
or self._transaction_active
|
|
1455
|
+
or bool(self.connection.transaction_in_progress)
|
|
1456
|
+
)
|
|
1457
|
+
|
|
1458
|
+
def _detect_oracledb_version(self) -> "tuple[int, int, int]":
|
|
1459
|
+
return ORACLEDB_VERSION
|
|
1460
|
+
|
|
1461
|
+
def _resolve_row_metadata(self, description: Any) -> "tuple[list[str], bool]":
|
|
1462
|
+
return resolve_row_metadata(description, self.driver_features, self._row_metadata_cache)
|
|
1463
|
+
|
|
1464
|
+
def _dispatch_explain_plan(
|
|
1465
|
+
self,
|
|
1466
|
+
cursor: Any,
|
|
1467
|
+
explained_sql: str,
|
|
1468
|
+
parameters: Any,
|
|
1469
|
+
*,
|
|
1470
|
+
display_cursor: bool = False,
|
|
1471
|
+
xplan_format: str = "TYPICAL",
|
|
1472
|
+
) -> "ExecutionResult":
|
|
1473
|
+
"""Request a plan, read it back, and release the plan table rows.
|
|
1474
|
+
|
|
1475
|
+
Oracle writes the plan to a table instead of returning it, so the plan is
|
|
1476
|
+
tagged with a generated statement id, formatted through ``DBMS_XPLAN``, and
|
|
1477
|
+
deleted again. All three statements run in the caller's transaction, so the
|
|
1478
|
+
plan is read before a rollback can discard it. When ``display_cursor`` is
|
|
1479
|
+
enabled, the statement is executed first and formatted through
|
|
1480
|
+
``DBMS_XPLAN.DISPLAY_CURSOR``.
|
|
1481
|
+
|
|
1482
|
+
Args:
|
|
1483
|
+
cursor: Oracle cursor object.
|
|
1484
|
+
explained_sql: Statement whose plan is wanted.
|
|
1485
|
+
parameters: Bind values for the explained statement.
|
|
1486
|
+
display_cursor: Whether to inspect actual cursor execution statistics via ``DBMS_XPLAN.DISPLAY_CURSOR``.
|
|
1487
|
+
xplan_format: ``DBMS_XPLAN`` format string.
|
|
1488
|
+
|
|
1489
|
+
Returns:
|
|
1490
|
+
Execution result carrying the formatted plan rows.
|
|
1491
|
+
"""
|
|
1492
|
+
if display_cursor:
|
|
1493
|
+
cursor.execute(explained_sql, parameters or {}, **self._fetch_kwargs)
|
|
1494
|
+
if cursor.description is not None:
|
|
1495
|
+
cursor.fetchall()
|
|
1496
|
+
cursor.execute(_format_display_cursor_sql(xplan_format), {}, **self._fetch_kwargs)
|
|
1497
|
+
fetched_data = cursor.fetchall()
|
|
1498
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
1499
|
+
data, column_names = collect_sync_rows(
|
|
1500
|
+
cast("list[Any] | None", fetched_data),
|
|
1501
|
+
cursor.description,
|
|
1502
|
+
self.driver_features,
|
|
1503
|
+
column_names=column_names,
|
|
1504
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
1505
|
+
)
|
|
1506
|
+
return self.create_execution_result(
|
|
1507
|
+
cursor,
|
|
1508
|
+
selected_data=data,
|
|
1509
|
+
column_names=column_names,
|
|
1510
|
+
data_row_count=len(data),
|
|
1511
|
+
is_select_result=True,
|
|
1512
|
+
row_format="tuple",
|
|
1513
|
+
)
|
|
1514
|
+
|
|
1515
|
+
statement_id = _new_plan_statement_id()
|
|
1516
|
+
cursor.execute(_tagged_explain_plan_sql(statement_id, explained_sql), parameters or {})
|
|
1517
|
+
display_sql = PLAN_DISPLAY_SQL if xplan_format == "TYPICAL" else _format_plan_display_sql(xplan_format)
|
|
1518
|
+
|
|
1519
|
+
try:
|
|
1520
|
+
cursor.execute(display_sql, {"statement_id": statement_id}, **self._fetch_kwargs)
|
|
1521
|
+
fetched_data = cursor.fetchall()
|
|
1522
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
1523
|
+
data, column_names = collect_sync_rows(
|
|
1524
|
+
cast("list[Any] | None", fetched_data),
|
|
1525
|
+
cursor.description,
|
|
1526
|
+
self.driver_features,
|
|
1527
|
+
column_names=column_names,
|
|
1528
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
1529
|
+
)
|
|
1530
|
+
result = self.create_execution_result(
|
|
1531
|
+
cursor,
|
|
1532
|
+
selected_data=data,
|
|
1533
|
+
column_names=column_names,
|
|
1534
|
+
data_row_count=len(data),
|
|
1535
|
+
is_select_result=True,
|
|
1536
|
+
row_format="tuple",
|
|
1537
|
+
)
|
|
1538
|
+
except Exception:
|
|
1539
|
+
try:
|
|
1540
|
+
cursor.execute(PLAN_CLEANUP_SQL, {"statement_id": statement_id})
|
|
1541
|
+
except Exception:
|
|
1542
|
+
logger.warning("Failed to clean up Oracle plan rows after plan retrieval failed", exc_info=True)
|
|
1543
|
+
raise
|
|
1544
|
+
else:
|
|
1545
|
+
cursor.execute(PLAN_CLEANUP_SQL, {"statement_id": statement_id})
|
|
1546
|
+
return result
|
|
1547
|
+
|
|
1548
|
+
def _execute_arrow_dataframe(self, sql: str, parameters: "Any", batch_size: int | None) -> "Any":
|
|
1549
|
+
"""Execute SQL and return an Oracle DataFrame."""
|
|
1550
|
+
params = parameters if parameters is not None else []
|
|
1551
|
+
try:
|
|
1552
|
+
execute_df = self.connection.execute_df
|
|
1553
|
+
except AttributeError:
|
|
1554
|
+
execute_df = None
|
|
1555
|
+
if execute_df is not None:
|
|
1556
|
+
try:
|
|
1557
|
+
return execute_df(sql, params, arraysize=batch_size or 1000)
|
|
1558
|
+
except TypeError:
|
|
1559
|
+
return execute_df(sql, params)
|
|
1560
|
+
fetch_kwargs = build_arrow_fetch_kwargs(self.driver_features)
|
|
1561
|
+
try:
|
|
1562
|
+
return self.connection.fetch_df_all(
|
|
1563
|
+
statement=sql, parameters=params, arraysize=batch_size or 1000, **fetch_kwargs
|
|
1564
|
+
)
|
|
1565
|
+
except TypeError as exc:
|
|
1566
|
+
retry_kwargs = _retry_arrow_without_fetch_lobs(exc, fetch_kwargs)
|
|
1567
|
+
if retry_kwargs is None:
|
|
1568
|
+
raise
|
|
1569
|
+
return self.connection.fetch_df_all(
|
|
1570
|
+
statement=sql, parameters=params, arraysize=batch_size or 1000, **retry_kwargs
|
|
1571
|
+
)
|
|
1572
|
+
|
|
1573
|
+
def _iter_arrow_record_batches(
|
|
1574
|
+
self,
|
|
1575
|
+
sql: str,
|
|
1576
|
+
parameters: "StatementParameters | None",
|
|
1577
|
+
batch_size: int | None,
|
|
1578
|
+
arrow_schema: "ArrowSchema | None",
|
|
1579
|
+
) -> "Generator[ArrowRecordBatch, None, None]":
|
|
1580
|
+
oracle_dfs = _fetch_dataframe_batches(
|
|
1581
|
+
self.connection, sql, parameters, batch_size, self.driver_features, arrow_schema
|
|
1582
|
+
)
|
|
1583
|
+
try:
|
|
1584
|
+
for oracle_df in oracle_dfs:
|
|
1585
|
+
batch_table = _coerce_oracle_arrow_batch_table(oracle_df, self.driver_features, arrow_schema)
|
|
1586
|
+
if batch_table.num_rows:
|
|
1587
|
+
yield from batch_table.to_batches()
|
|
1588
|
+
else:
|
|
1589
|
+
yield import_pyarrow().RecordBatch.from_pylist([], schema=batch_table.schema)
|
|
1590
|
+
except OracleError as exc:
|
|
1591
|
+
raise with_cause(create_mapped_exception(exc), exc) from exc
|
|
1592
|
+
finally:
|
|
1593
|
+
close_dfs = getattr(oracle_dfs, "close", None)
|
|
1594
|
+
if callable(close_dfs):
|
|
1595
|
+
close_dfs()
|
|
1596
|
+
|
|
1597
|
+
def _fetch_arrow_record_batches(
|
|
1598
|
+
self,
|
|
1599
|
+
sql: str,
|
|
1600
|
+
parameters: "StatementParameters | None",
|
|
1601
|
+
batch_size: int | None,
|
|
1602
|
+
arrow_schema: "ArrowSchema | None",
|
|
1603
|
+
) -> "tuple[list[ArrowRecordBatch], ArrowSchema | None]":
|
|
1604
|
+
record_batches: list[ArrowRecordBatch] = []
|
|
1605
|
+
batch_schema: ArrowSchema | None = None
|
|
1606
|
+
oracle_dfs = _fetch_dataframe_batches(
|
|
1607
|
+
self.connection, sql, parameters, batch_size, self.driver_features, arrow_schema
|
|
1608
|
+
)
|
|
1609
|
+
try:
|
|
1610
|
+
for oracle_df in oracle_dfs:
|
|
1611
|
+
batch_table = _coerce_oracle_arrow_batch_table(oracle_df, self.driver_features, arrow_schema)
|
|
1612
|
+
if batch_schema is None:
|
|
1613
|
+
batch_schema = batch_table.schema
|
|
1614
|
+
record_batches.extend(batch_table.to_batches())
|
|
1615
|
+
except OracleError as exc:
|
|
1616
|
+
raise with_cause(create_mapped_exception(exc), exc) from exc
|
|
1617
|
+
finally:
|
|
1618
|
+
close_dfs = getattr(oracle_dfs, "close", None)
|
|
1619
|
+
if callable(close_dfs):
|
|
1620
|
+
close_dfs()
|
|
1621
|
+
return record_batches, batch_schema
|
|
1622
|
+
|
|
1623
|
+
|
|
1624
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
1625
|
+
class OracleAsyncDriver(AsyncDriverAdapterBase):
|
|
1626
|
+
"""Asynchronous Oracle Database driver.
|
|
1627
|
+
|
|
1628
|
+
Provides Oracle Database connectivity with parameter style conversion,
|
|
1629
|
+
error handling, and transaction management for async operations.
|
|
1630
|
+
"""
|
|
1631
|
+
|
|
1632
|
+
__slots__ = (
|
|
1633
|
+
"_data_dictionary",
|
|
1634
|
+
"_fetch_kwargs",
|
|
1635
|
+
"_migration_schema_restore",
|
|
1636
|
+
"_pipeline_support",
|
|
1637
|
+
"_pipeline_support_reason",
|
|
1638
|
+
"_row_metadata_cache",
|
|
1639
|
+
"_session_tracing_enabled",
|
|
1640
|
+
"_sessionless_cleanup_error",
|
|
1641
|
+
"_sessionless_transaction_id",
|
|
1642
|
+
"_transaction_active",
|
|
1643
|
+
)
|
|
1644
|
+
dialect: "DialectType | None" = "oracle"
|
|
1645
|
+
export_integers_may_widen: ClassVar[bool] = True
|
|
1646
|
+
|
|
1647
|
+
def __init__(
|
|
1648
|
+
self,
|
|
1649
|
+
connection: OracleAsyncConnection,
|
|
1650
|
+
statement_config: "StatementConfig | None" = None,
|
|
1651
|
+
driver_features: "dict[str, Any] | None" = None,
|
|
1652
|
+
) -> None:
|
|
1653
|
+
if statement_config is None:
|
|
1654
|
+
statement_config = default_statement_config.replace(
|
|
1655
|
+
enable_caching=get_cache_config().compiled_cache_enabled
|
|
1656
|
+
)
|
|
1657
|
+
|
|
1658
|
+
super().__init__(connection=connection, statement_config=statement_config, driver_features=driver_features)
|
|
1659
|
+
self._data_dictionary: OracledbAsyncDataDictionary | None = None
|
|
1660
|
+
self._migration_schema_restore: str | None = None
|
|
1661
|
+
self._pipeline_support: bool | None = None
|
|
1662
|
+
self._pipeline_support_reason: str | None = None
|
|
1663
|
+
self._row_metadata_cache: dict[int, tuple[Any, list[str], bool]] = {}
|
|
1664
|
+
self._transaction_active = False
|
|
1665
|
+
self._sessionless_transaction_id: bytes | None = None
|
|
1666
|
+
self._sessionless_cleanup_error: BaseException | None = None
|
|
1667
|
+
self._fetch_kwargs = build_fetch_kwargs(self.driver_features)
|
|
1668
|
+
self._session_tracing_enabled = bool(
|
|
1669
|
+
self.driver_features.get("enable_session_tracing", False) or self.statement_config.enable_sqlcommenter
|
|
1670
|
+
)
|
|
1671
|
+
self._cache_hit_executor = (
|
|
1672
|
+
execute_cache_hit_async if cache_hit_hooks_unchanged(type(self), OracleAsyncDriver) else None
|
|
1673
|
+
)
|
|
1674
|
+
self._cache_hit_state = OracleCacheHitState(
|
|
1675
|
+
self.driver_features, self._fetch_kwargs, self._row_metadata_cache, self._session_tracing_enabled
|
|
1676
|
+
)
|
|
1677
|
+
|
|
1678
|
+
@property
|
|
1679
|
+
def sessionless_transaction_id(self) -> bytes | None:
|
|
1680
|
+
"""Return the sessionless transaction currently attached to this connection."""
|
|
1681
|
+
return self._sessionless_transaction_id
|
|
1682
|
+
|
|
1683
|
+
@property
|
|
1684
|
+
def _oracle_version_cache(self) -> "OracleVersionCache | None":
|
|
1685
|
+
return cast("OracleVersionCache | None", cast("OracleCacheHitState", self._cache_hit_state).version_cache)
|
|
1686
|
+
|
|
1687
|
+
@_oracle_version_cache.setter
|
|
1688
|
+
def _oracle_version_cache(self, value: "OracleVersionCache | None") -> None:
|
|
1689
|
+
cast("OracleCacheHitState", self._cache_hit_state).version_cache = value
|
|
1690
|
+
|
|
1691
|
+
@property
|
|
1692
|
+
def _otel_tracing_enabled(self) -> bool:
|
|
1693
|
+
return cast("OracleCacheHitState", self._cache_hit_state).otel_tracing_enabled
|
|
1694
|
+
|
|
1695
|
+
@_otel_tracing_enabled.setter
|
|
1696
|
+
def _otel_tracing_enabled(self, value: bool) -> None:
|
|
1697
|
+
cast("OracleCacheHitState", self._cache_hit_state).otel_tracing_enabled = bool(value)
|
|
1698
|
+
|
|
1699
|
+
def attach_observability(self, runtime: "ObservabilityRuntime") -> None:
|
|
1700
|
+
"""Refresh trace propagation when the session receives its runtime."""
|
|
1701
|
+
super().attach_observability(runtime)
|
|
1702
|
+
self._otel_tracing_enabled = (
|
|
1703
|
+
bool(self.driver_features.get("enable_otel_trace_context", True)) and runtime.span_manager.is_enabled
|
|
1704
|
+
)
|
|
1705
|
+
|
|
1706
|
+
def _apply_session_tracing(self, connection: Any = None) -> None:
|
|
1707
|
+
_oracle_apply_session_tracing(self, connection)
|
|
1708
|
+
|
|
1709
|
+
def _format_wire_sql(self, sql: str, config: "StatementConfig | None" = None) -> str:
|
|
1710
|
+
return _oracle_format_wire_sql(self, sql, config)
|
|
1711
|
+
|
|
1712
|
+
def _compiled_sql(
|
|
1713
|
+
self, statement: "SQL", statement_config: "StatementConfig", flatten_single_parameters: bool = False
|
|
1714
|
+
) -> "tuple[str, Any]":
|
|
1715
|
+
compiled_sql, prepared_parameters = super()._compiled_sql(
|
|
1716
|
+
statement, statement_config, flatten_single_parameters=flatten_single_parameters
|
|
1717
|
+
)
|
|
1718
|
+
if self._session_tracing_enabled:
|
|
1719
|
+
return strip_sqlcomment(compiled_sql), prepared_parameters
|
|
1720
|
+
return compiled_sql, prepared_parameters
|
|
1721
|
+
|
|
1722
|
+
def _stack_native_blocker(self, stack: "StatementStack") -> "str | None":
|
|
1723
|
+
return _oracle_stack_native_blocker(stack)
|
|
1724
|
+
|
|
1725
|
+
def _log_pipeline_skip(self, reason: str, stack: "StatementStack") -> None:
|
|
1726
|
+
_oracle_log_pipeline_skip(self, reason, stack)
|
|
1727
|
+
|
|
1728
|
+
def _prepare_pipeline_operation(self, operation: "StackOperation") -> "_CompiledStackOperation":
|
|
1729
|
+
return _oracle_prepare_pipeline_operation(self, operation)
|
|
1730
|
+
|
|
1731
|
+
def _add_pipeline_operation(self, pipeline: Any, operation: "_CompiledStackOperation") -> None:
|
|
1732
|
+
_oracle_add_pipeline_operation(self, pipeline, operation)
|
|
1733
|
+
|
|
1734
|
+
def _build_stack_results_from_pipeline(
|
|
1735
|
+
self,
|
|
1736
|
+
compiled_operations: "Sequence[_CompiledStackOperation]",
|
|
1737
|
+
pipeline_results: "Sequence[Any]",
|
|
1738
|
+
continue_on_error: bool,
|
|
1739
|
+
observer: StackExecutionObserver,
|
|
1740
|
+
*,
|
|
1741
|
+
coerced_rows_by_index: "Mapping[int, Sequence[Any] | None] | None" = None,
|
|
1742
|
+
) -> "list[StackResult]":
|
|
1743
|
+
return _oracle_build_stack_results_from_pipeline(
|
|
1744
|
+
self,
|
|
1745
|
+
compiled_operations,
|
|
1746
|
+
pipeline_results,
|
|
1747
|
+
continue_on_error,
|
|
1748
|
+
observer,
|
|
1749
|
+
coerced_rows_by_index=coerced_rows_by_index,
|
|
1750
|
+
)
|
|
1751
|
+
|
|
1752
|
+
def _check_pipeline_commit_result(self, result: Any) -> None:
|
|
1753
|
+
_oracle_check_pipeline_commit_result(result)
|
|
1754
|
+
|
|
1755
|
+
def _wrap_pipeline_error(
|
|
1756
|
+
self, error: Exception, stack: "StatementStack", continue_on_error: bool
|
|
1757
|
+
) -> StackExecutionError:
|
|
1758
|
+
return _oracle_wrap_pipeline_error(self, error, continue_on_error)
|
|
1759
|
+
|
|
1760
|
+
@property
|
|
1761
|
+
def data_dictionary(self) -> "OracledbAsyncDataDictionary":
|
|
1762
|
+
"""Get the data dictionary for this driver.
|
|
1763
|
+
|
|
1764
|
+
Returns:
|
|
1765
|
+
Data dictionary instance for metadata queries
|
|
1766
|
+
"""
|
|
1767
|
+
if self._data_dictionary is None:
|
|
1768
|
+
self._data_dictionary = OracledbAsyncDataDictionary()
|
|
1769
|
+
return self._data_dictionary
|
|
1770
|
+
|
|
1771
|
+
def set_transaction_priority(self, priority: Any) -> None:
|
|
1772
|
+
"""Set native transaction priority as a zero-round-trip connection field."""
|
|
1773
|
+
apply_oracle_transaction_priority(self.connection, priority)
|
|
1774
|
+
|
|
1775
|
+
async def begin_sessionless_transaction(
|
|
1776
|
+
self, transaction_id: str | bytes | None = None, *, timeout: int = 60, defer_round_trip: bool = True
|
|
1777
|
+
) -> bytes:
|
|
1778
|
+
"""Begin an explicitly supported native sessionless transaction."""
|
|
1779
|
+
resolved = validate_sessionless_transaction_args(
|
|
1780
|
+
transaction_id, timeout=timeout, defer_round_trip=defer_round_trip
|
|
1781
|
+
)
|
|
1782
|
+
method = getattr(self.connection, "begin_sessionless_transaction", None)
|
|
1783
|
+
if not callable(method):
|
|
1784
|
+
msg = "Sessionless transactions require python-oracledb 26.1 or newer"
|
|
1785
|
+
raise oracledb_module.NotSupportedError(msg)
|
|
1786
|
+
try:
|
|
1787
|
+
txid = await cast("Any", method)(resolved, timeout=timeout, defer_round_trip=defer_round_trip)
|
|
1788
|
+
except OracleError as exc:
|
|
1789
|
+
raise with_cause(create_mapped_exception(exc), exc) from exc
|
|
1790
|
+
self._sessionless_transaction_id = cast("bytes", txid)
|
|
1791
|
+
return self._sessionless_transaction_id
|
|
1792
|
+
|
|
1793
|
+
async def resume_sessionless_transaction(
|
|
1794
|
+
self, transaction_id: str | bytes, *, timeout: int = 60, defer_round_trip: bool = True
|
|
1795
|
+
) -> bytes:
|
|
1796
|
+
"""Attach a suspended native transaction to this connection."""
|
|
1797
|
+
resolved = validate_sessionless_transaction_args(
|
|
1798
|
+
transaction_id, timeout=timeout, is_resume=True, defer_round_trip=defer_round_trip
|
|
1799
|
+
)
|
|
1800
|
+
method = getattr(self.connection, "resume_sessionless_transaction", None)
|
|
1801
|
+
if not callable(method):
|
|
1802
|
+
msg = "Sessionless transactions require python-oracledb 26.1 or newer"
|
|
1803
|
+
raise oracledb_module.NotSupportedError(msg)
|
|
1804
|
+
try:
|
|
1805
|
+
txid = await cast("Any", method)(
|
|
1806
|
+
cast("bytes", resolved), timeout=timeout, defer_round_trip=defer_round_trip
|
|
1807
|
+
)
|
|
1808
|
+
except OracleError as exc:
|
|
1809
|
+
raise with_cause(create_mapped_exception(exc), exc) from exc
|
|
1810
|
+
self._sessionless_transaction_id = cast("bytes", txid)
|
|
1811
|
+
return self._sessionless_transaction_id
|
|
1812
|
+
|
|
1813
|
+
async def suspend_sessionless_transaction(self) -> None:
|
|
1814
|
+
"""Detach the active transaction so another pooled connection can resume it."""
|
|
1815
|
+
method = getattr(self.connection, "suspend_sessionless_transaction", None)
|
|
1816
|
+
if not callable(method):
|
|
1817
|
+
msg = "Sessionless transactions require python-oracledb 26.1 or newer"
|
|
1818
|
+
raise oracledb_module.NotSupportedError(msg)
|
|
1819
|
+
try:
|
|
1820
|
+
await cast("Any", method)()
|
|
1821
|
+
except BaseException as exc:
|
|
1822
|
+
pending = create_mapped_exception(exc) if isinstance(exc, OracleError) else exc
|
|
1823
|
+
if self._sessionless_transaction_id is not None:
|
|
1824
|
+
self._sessionless_cleanup_error = pending
|
|
1825
|
+
if pending is not exc:
|
|
1826
|
+
pending.__cause__ = exc
|
|
1827
|
+
raise pending from exc
|
|
1828
|
+
raise
|
|
1829
|
+
else:
|
|
1830
|
+
self._sessionless_transaction_id = None
|
|
1831
|
+
finally:
|
|
1832
|
+
self._transaction_active = False
|
|
1833
|
+
|
|
1834
|
+
def sessionless_transaction(
|
|
1835
|
+
self,
|
|
1836
|
+
transaction_id: str | bytes | None = None,
|
|
1837
|
+
*,
|
|
1838
|
+
timeout: int = 60,
|
|
1839
|
+
defer_round_trip: bool = True,
|
|
1840
|
+
resume: bool = False,
|
|
1841
|
+
rollback_on_error: bool = True,
|
|
1842
|
+
) -> "OracleAsyncSessionlessTransactionContext":
|
|
1843
|
+
"""Scope a sessionless transaction and suspend it on successful exit."""
|
|
1844
|
+
return OracleAsyncSessionlessTransactionContext(
|
|
1845
|
+
self,
|
|
1846
|
+
transaction_id=transaction_id,
|
|
1847
|
+
timeout=timeout,
|
|
1848
|
+
defer_round_trip=defer_round_trip,
|
|
1849
|
+
resume=resume,
|
|
1850
|
+
rollback_on_error=rollback_on_error,
|
|
1851
|
+
)
|
|
1852
|
+
|
|
1853
|
+
async def execute(
|
|
1854
|
+
self,
|
|
1855
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1856
|
+
/,
|
|
1857
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
1858
|
+
statement_config: "StatementConfig | None" = None,
|
|
1859
|
+
suspend_on_success: bool = False,
|
|
1860
|
+
**kwargs: Any,
|
|
1861
|
+
) -> SQLResult:
|
|
1862
|
+
"""Execute a statement with optional native sessionless suspension."""
|
|
1863
|
+
validate_sessionless_execution_options(suspend_on_success=suspend_on_success)
|
|
1864
|
+
if suspend_on_success:
|
|
1865
|
+
config = statement_config or self.statement_config
|
|
1866
|
+
args = dict(config.execution_args or {})
|
|
1867
|
+
args["oracle_suspend_on_success"] = True
|
|
1868
|
+
statement_config = config.replace(execution_args=args)
|
|
1869
|
+
if suspend_on_success:
|
|
1870
|
+
prepared = self.prepare_statement(statement, parameters, statement_config=statement_config, kwargs=kwargs)
|
|
1871
|
+
prepared = prepared.copy(statement_config=statement_config)
|
|
1872
|
+
result = await self.dispatch_statement_execution(prepared, self.connection)
|
|
1873
|
+
else:
|
|
1874
|
+
result = await super().execute(statement, *parameters, statement_config=statement_config, **kwargs)
|
|
1875
|
+
if suspend_on_success:
|
|
1876
|
+
self._sessionless_transaction_id = None
|
|
1877
|
+
self._transaction_active = False
|
|
1878
|
+
return result
|
|
1879
|
+
|
|
1880
|
+
async def execute_many(
|
|
1881
|
+
self,
|
|
1882
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
1883
|
+
/,
|
|
1884
|
+
parameters: "Sequence[StatementParameters]",
|
|
1885
|
+
*filters: "StatementParameters | StatementFilter",
|
|
1886
|
+
statement_config: "StatementConfig | None" = None,
|
|
1887
|
+
batch_size: int | None = None,
|
|
1888
|
+
suspend_on_success: bool = False,
|
|
1889
|
+
**kwargs: Any,
|
|
1890
|
+
) -> SQLResult:
|
|
1891
|
+
"""Execute a batch with validated native batching and suspension options."""
|
|
1892
|
+
validate_sessionless_execution_options(suspend_on_success=suspend_on_success, batch_size=batch_size)
|
|
1893
|
+
if suspend_on_success or batch_size is not None:
|
|
1894
|
+
config = statement_config or self.statement_config
|
|
1895
|
+
args = dict(config.execution_args or {})
|
|
1896
|
+
if suspend_on_success:
|
|
1897
|
+
args["oracle_suspend_on_success"] = True
|
|
1898
|
+
if batch_size is not None:
|
|
1899
|
+
args["oracle_batch_size"] = batch_size
|
|
1900
|
+
statement_config = config.replace(execution_args=args)
|
|
1901
|
+
result = await super().execute_many(
|
|
1902
|
+
statement, parameters, *filters, statement_config=statement_config, **kwargs
|
|
1903
|
+
)
|
|
1904
|
+
if suspend_on_success and parameters:
|
|
1905
|
+
self._sessionless_transaction_id = None
|
|
1906
|
+
self._transaction_active = False
|
|
1907
|
+
return result
|
|
1908
|
+
|
|
1909
|
+
async def dispatch_execute(self, cursor: Any, statement: "SQL") -> "ExecutionResult":
|
|
1910
|
+
"""Execute single SQL statement with Oracle data handling.
|
|
1911
|
+
|
|
1912
|
+
For SELECT-like statements, fetches all rows, resolves row metadata, and
|
|
1913
|
+
applies LOB coercion if needed. For non-SELECT statements, resolves and
|
|
1914
|
+
returns the affected row count.
|
|
1915
|
+
|
|
1916
|
+
Args:
|
|
1917
|
+
cursor: Oracle cursor object
|
|
1918
|
+
statement: SQL statement to execute
|
|
1919
|
+
|
|
1920
|
+
Returns:
|
|
1921
|
+
Execution result containing data for SELECT statements or row count for others
|
|
1922
|
+
"""
|
|
1923
|
+
|
|
1924
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
1925
|
+
|
|
1926
|
+
prepared_parameters = await coerce_large_parameters_async(
|
|
1927
|
+
self.connection,
|
|
1928
|
+
prepared_parameters,
|
|
1929
|
+
clob_type=DB_TYPE_CLOB,
|
|
1930
|
+
blob_type=DB_TYPE_BLOB,
|
|
1931
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
1932
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
1933
|
+
version_cache=self._oracle_version_cache,
|
|
1934
|
+
)
|
|
1935
|
+
prepared_parameters = cast("list[Any] | tuple[Any, ...] | dict[Any, Any] | None", prepared_parameters)
|
|
1936
|
+
|
|
1937
|
+
explained_sql = _managed_explain_statement(statement, sql)
|
|
1938
|
+
if explained_sql is not None:
|
|
1939
|
+
display_cursor, xplan_format = _managed_explain_options(statement)
|
|
1940
|
+
return await self._dispatch_explain_plan(
|
|
1941
|
+
cursor, explained_sql, prepared_parameters, display_cursor=display_cursor, xplan_format=xplan_format
|
|
1942
|
+
)
|
|
1943
|
+
|
|
1944
|
+
execution_args = statement.statement_config.execution_args or {}
|
|
1945
|
+
fetch_kwargs = dict(self._fetch_kwargs)
|
|
1946
|
+
if execution_args.get("oracle_suspend_on_success", False):
|
|
1947
|
+
fetch_kwargs["suspend_on_success"] = True
|
|
1948
|
+
await cursor.execute(sql, prepared_parameters or {}, **fetch_kwargs)
|
|
1949
|
+
|
|
1950
|
+
is_select_like = statement.returns_rows() or self._should_force_select(statement, cursor)
|
|
1951
|
+
|
|
1952
|
+
if is_select_like and cursor.description is not None:
|
|
1953
|
+
fetched_data = await cursor.fetchall()
|
|
1954
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
1955
|
+
data, column_names = await collect_async_rows(
|
|
1956
|
+
cast("list[Any] | None", fetched_data),
|
|
1957
|
+
cursor.description,
|
|
1958
|
+
self.driver_features,
|
|
1959
|
+
column_names=column_names,
|
|
1960
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
1961
|
+
)
|
|
1962
|
+
|
|
1963
|
+
return self.create_execution_result(
|
|
1964
|
+
cursor,
|
|
1965
|
+
selected_data=data,
|
|
1966
|
+
column_names=column_names,
|
|
1967
|
+
data_row_count=len(data),
|
|
1968
|
+
is_select_result=True,
|
|
1969
|
+
row_format="tuple",
|
|
1970
|
+
)
|
|
1971
|
+
|
|
1972
|
+
affected_rows = resolve_rowcount(cursor)
|
|
1973
|
+
return self.create_execution_result(cursor, rowcount_override=affected_rows)
|
|
1974
|
+
|
|
1975
|
+
async def dispatch_execute_many(self, cursor: Any, statement: "SQL") -> "ExecutionResult":
|
|
1976
|
+
"""Execute SQL with multiple parameter sets using Oracle batch processing.
|
|
1977
|
+
|
|
1978
|
+
Args:
|
|
1979
|
+
cursor: Oracle cursor object
|
|
1980
|
+
statement: SQL statement with multiple parameter sets
|
|
1981
|
+
|
|
1982
|
+
Returns:
|
|
1983
|
+
Execution result with affected row count
|
|
1984
|
+
"""
|
|
1985
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
1986
|
+
|
|
1987
|
+
prepared_parameters = await coerce_many_parameters_async(
|
|
1988
|
+
self.connection,
|
|
1989
|
+
prepared_parameters,
|
|
1990
|
+
clob_type=DB_TYPE_CLOB,
|
|
1991
|
+
blob_type=DB_TYPE_BLOB,
|
|
1992
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
1993
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
1994
|
+
version_cache=self._oracle_version_cache,
|
|
1995
|
+
)
|
|
1996
|
+
execution_args = statement.statement_config.execution_args or {}
|
|
1997
|
+
batch_errors = bool(execution_args.get("oracle_batch_errors", False))
|
|
1998
|
+
array_dml_row_counts = bool(execution_args.get("oracle_array_dml_row_counts", False))
|
|
1999
|
+
await cursor.executemany(
|
|
2000
|
+
sql,
|
|
2001
|
+
prepared_parameters,
|
|
2002
|
+
batcherrors=batch_errors,
|
|
2003
|
+
arraydmlrowcounts=array_dml_row_counts,
|
|
2004
|
+
**{
|
|
2005
|
+
key: value
|
|
2006
|
+
for key, value in {
|
|
2007
|
+
"suspend_on_success": execution_args.get("oracle_suspend_on_success"),
|
|
2008
|
+
"batch_size": execution_args.get("oracle_batch_size"),
|
|
2009
|
+
}.items()
|
|
2010
|
+
if value is not None
|
|
2011
|
+
},
|
|
2012
|
+
)
|
|
2013
|
+
|
|
2014
|
+
affected_rows = len(prepared_parameters)
|
|
2015
|
+
special_data: dict[str, Any] | None = None
|
|
2016
|
+
if batch_errors or array_dml_row_counts:
|
|
2017
|
+
special_data = {}
|
|
2018
|
+
if batch_errors:
|
|
2019
|
+
special_data["oracle_batch_errors"] = [
|
|
2020
|
+
{
|
|
2021
|
+
"offset": cast("int | None", getattr(error, "offset", None)),
|
|
2022
|
+
"code": cast("int | None", getattr(error, "code", None)),
|
|
2023
|
+
"message": cast("str", getattr(error, "message", str(error))),
|
|
2024
|
+
}
|
|
2025
|
+
for error in cursor.getbatcherrors()
|
|
2026
|
+
]
|
|
2027
|
+
if array_dml_row_counts:
|
|
2028
|
+
row_counts = list(cursor.getarraydmlrowcounts())
|
|
2029
|
+
special_data["oracle_dml_row_counts"] = row_counts
|
|
2030
|
+
affected_rows = sum(row_counts)
|
|
2031
|
+
|
|
2032
|
+
return self.create_execution_result(
|
|
2033
|
+
cursor, rowcount_override=affected_rows, special_data=special_data, is_many_result=True
|
|
2034
|
+
)
|
|
2035
|
+
|
|
2036
|
+
async def dispatch_execute_script(self, cursor: Any, statement: "SQL") -> "ExecutionResult":
|
|
2037
|
+
"""Execute async SQL script with statement splitting and parameter handling."""
|
|
2038
|
+
bound_statements = self._bound_script_statements(statement)
|
|
2039
|
+
if bound_statements is not None:
|
|
2040
|
+
return await self._dispatch_bound_script(cursor, bound_statements)
|
|
2041
|
+
|
|
2042
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
2043
|
+
prepared_parameters = await coerce_large_parameters_async(
|
|
2044
|
+
self.connection,
|
|
2045
|
+
prepared_parameters,
|
|
2046
|
+
clob_type=DB_TYPE_CLOB,
|
|
2047
|
+
blob_type=DB_TYPE_BLOB,
|
|
2048
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
2049
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
2050
|
+
version_cache=self._oracle_version_cache,
|
|
2051
|
+
)
|
|
2052
|
+
statements = self.split_script_statements(sql, statement.statement_config, strip_trailing_semicolon=True)
|
|
2053
|
+
|
|
2054
|
+
successful_count = 0
|
|
2055
|
+
last_cursor = cursor
|
|
2056
|
+
pos_offset = 0
|
|
2057
|
+
total_statements = len(statements)
|
|
2058
|
+
runtime = self._observability
|
|
2059
|
+
has_observers = runtime is not None and runtime.has_statement_observers
|
|
2060
|
+
|
|
2061
|
+
for idx, stmt in enumerate(statements):
|
|
2062
|
+
stmt_params, pos_offset = _slice_script_parameters(stmt, prepared_parameters, pos_offset)
|
|
2063
|
+
stmt_started = perf_counter() if has_observers else 0.0
|
|
2064
|
+
await cursor.execute(stmt, stmt_params)
|
|
2065
|
+
successful_count += 1
|
|
2066
|
+
if has_observers:
|
|
2067
|
+
stmt_duration = perf_counter() - stmt_started
|
|
2068
|
+
single_stmt = self._sub_statement(stmt, stmt_params)
|
|
2069
|
+
try:
|
|
2070
|
+
stmt_operation = single_stmt.operation_type
|
|
2071
|
+
finally:
|
|
2072
|
+
self._release_pooled_statement(single_stmt)
|
|
2073
|
+
self._emit_script_statement_event(
|
|
2074
|
+
sql=stmt,
|
|
2075
|
+
parameters=stmt_params,
|
|
2076
|
+
operation=stmt_operation,
|
|
2077
|
+
rows_affected=resolve_rowcount(cursor),
|
|
2078
|
+
duration_s=stmt_duration,
|
|
2079
|
+
started_at=stmt_started,
|
|
2080
|
+
profile=None,
|
|
2081
|
+
script_ordinal=idx,
|
|
2082
|
+
script_statement_count=total_statements,
|
|
2083
|
+
)
|
|
2084
|
+
|
|
2085
|
+
self._pending_statement_profile = None
|
|
2086
|
+
return self.create_execution_result(
|
|
2087
|
+
last_cursor, statement_count=total_statements, successful_statements=successful_count, is_script_result=True
|
|
2088
|
+
)
|
|
2089
|
+
|
|
2090
|
+
async def begin(self) -> None:
|
|
2091
|
+
"""Begin a database transaction.
|
|
2092
|
+
|
|
2093
|
+
Oracle starts a transaction implicitly on the first DML, so no explicit
|
|
2094
|
+
statement is issued; the active-transaction flag is set here.
|
|
2095
|
+
"""
|
|
2096
|
+
self._transaction_active = True
|
|
2097
|
+
|
|
2098
|
+
async def commit(self) -> None:
|
|
2099
|
+
"""Commit the current transaction.
|
|
2100
|
+
|
|
2101
|
+
Raises:
|
|
2102
|
+
SQLSpecError: If commit fails
|
|
2103
|
+
"""
|
|
2104
|
+
|
|
2105
|
+
try:
|
|
2106
|
+
await self.connection.commit()
|
|
2107
|
+
except BaseException as exc:
|
|
2108
|
+
pending = create_mapped_exception(exc) if isinstance(exc, OracleError) else exc
|
|
2109
|
+
if self._sessionless_transaction_id is not None:
|
|
2110
|
+
self._sessionless_cleanup_error = pending
|
|
2111
|
+
if pending is not exc:
|
|
2112
|
+
pending.__cause__ = exc
|
|
2113
|
+
raise pending from exc
|
|
2114
|
+
raise
|
|
2115
|
+
else:
|
|
2116
|
+
self._sessionless_transaction_id = None
|
|
2117
|
+
finally:
|
|
2118
|
+
self._transaction_active = False
|
|
2119
|
+
|
|
2120
|
+
async def rollback(self) -> None:
|
|
2121
|
+
"""Rollback the current transaction.
|
|
2122
|
+
|
|
2123
|
+
Raises:
|
|
2124
|
+
SQLSpecError: If rollback fails
|
|
2125
|
+
"""
|
|
2126
|
+
|
|
2127
|
+
try:
|
|
2128
|
+
await self.connection.rollback()
|
|
2129
|
+
except BaseException as exc:
|
|
2130
|
+
pending = create_mapped_exception(exc) if isinstance(exc, OracleError) else exc
|
|
2131
|
+
if self._sessionless_transaction_id is not None:
|
|
2132
|
+
self._sessionless_cleanup_error = pending
|
|
2133
|
+
if pending is not exc:
|
|
2134
|
+
pending.__cause__ = exc
|
|
2135
|
+
raise pending from exc
|
|
2136
|
+
raise
|
|
2137
|
+
else:
|
|
2138
|
+
self._sessionless_transaction_id = None
|
|
2139
|
+
finally:
|
|
2140
|
+
self._transaction_active = False
|
|
2141
|
+
|
|
2142
|
+
async def release_savepoint(self, name: str) -> None:
|
|
2143
|
+
"""Validate the savepoint name; Oracle releases savepoints when the transaction ends."""
|
|
2144
|
+
validate_savepoint_name(name)
|
|
2145
|
+
|
|
2146
|
+
async def set_migration_session_schema(self, schema: str) -> None:
|
|
2147
|
+
"""Set Oracle CURRENT_SCHEMA for migration SQL, remembering the schema in effect on the first switch.
|
|
2148
|
+
|
|
2149
|
+
Args:
|
|
2150
|
+
schema: Schema to make current. Unquoted lowercase names fold to uppercase.
|
|
2151
|
+
"""
|
|
2152
|
+
normalized_schema = normalize_identifier(schema, "oracle")
|
|
2153
|
+
quoted_schema = quote_identifier(normalized_schema)
|
|
2154
|
+
async with self.with_cursor(self.connection) as cursor:
|
|
2155
|
+
if self._migration_schema_restore is None:
|
|
2156
|
+
await cursor.execute("SELECT SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA') FROM DUAL")
|
|
2157
|
+
row = await cursor.fetchone()
|
|
2158
|
+
self._migration_schema_restore = str(row[0])
|
|
2159
|
+
await cursor.execute(f"ALTER SESSION SET CURRENT_SCHEMA = {quoted_schema}")
|
|
2160
|
+
|
|
2161
|
+
async def reset_migration_session_schema(self) -> None:
|
|
2162
|
+
"""Restore the schema captured by ``set_migration_session_schema`` with its exact catalog case."""
|
|
2163
|
+
previous_schema = self._migration_schema_restore
|
|
2164
|
+
if previous_schema is None:
|
|
2165
|
+
return
|
|
2166
|
+
async with self.with_cursor(self.connection) as cursor:
|
|
2167
|
+
await cursor.execute(f"ALTER SESSION SET CURRENT_SCHEMA = {quote_identifier(previous_schema)}")
|
|
2168
|
+
self._migration_schema_restore = None
|
|
2169
|
+
|
|
2170
|
+
async def has_schema(self, schema: str) -> bool:
|
|
2171
|
+
"""Return whether an Oracle schema/user exists."""
|
|
2172
|
+
normalized_schema = normalize_identifier(schema, "oracle")
|
|
2173
|
+
async with self.with_cursor(self.connection) as cursor:
|
|
2174
|
+
await cursor.execute(
|
|
2175
|
+
"SELECT 1 FROM ALL_USERS WHERE USERNAME = :schema_name", {"schema_name": normalized_schema}
|
|
2176
|
+
)
|
|
2177
|
+
row = await cursor.fetchone()
|
|
2178
|
+
return row is not None
|
|
2179
|
+
|
|
2180
|
+
def with_cursor(self, connection: OracleAsyncConnection) -> OracleAsyncCursor:
|
|
2181
|
+
"""Create context manager for Oracle cursor.
|
|
2182
|
+
|
|
2183
|
+
Args:
|
|
2184
|
+
connection: Oracle database connection
|
|
2185
|
+
|
|
2186
|
+
Returns:
|
|
2187
|
+
Context manager for cursor operations
|
|
2188
|
+
"""
|
|
2189
|
+
return OracleAsyncCursor(
|
|
2190
|
+
connection,
|
|
2191
|
+
arraysize=self.driver_features.get("arraysize"),
|
|
2192
|
+
prefetchrows=self.driver_features.get("prefetchrows"),
|
|
2193
|
+
on_enter=self._apply_session_tracing
|
|
2194
|
+
if self._session_tracing_enabled or self._otel_tracing_enabled
|
|
2195
|
+
else None,
|
|
2196
|
+
)
|
|
2197
|
+
|
|
2198
|
+
@overload
|
|
2199
|
+
def select_stream(
|
|
2200
|
+
self,
|
|
2201
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
2202
|
+
/,
|
|
2203
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
2204
|
+
schema_type: "type[SchemaT]",
|
|
2205
|
+
statement_config: "StatementConfig | None" = None,
|
|
2206
|
+
chunk_size: int = 1000,
|
|
2207
|
+
native_only: bool = False,
|
|
2208
|
+
**kwargs: Any,
|
|
2209
|
+
) -> "AsyncRowStream[SchemaT]": ...
|
|
2210
|
+
@overload
|
|
2211
|
+
def select_stream(
|
|
2212
|
+
self,
|
|
2213
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
2214
|
+
/,
|
|
2215
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
2216
|
+
schema_type: None = None,
|
|
2217
|
+
statement_config: "StatementConfig | None" = None,
|
|
2218
|
+
chunk_size: int = 1000,
|
|
2219
|
+
native_only: bool = False,
|
|
2220
|
+
**kwargs: Any,
|
|
2221
|
+
) -> "AsyncRowStream[dict[str, Any]]": ...
|
|
2222
|
+
def select_stream(
|
|
2223
|
+
self,
|
|
2224
|
+
statement: "SQL | Statement | QueryBuilder",
|
|
2225
|
+
/,
|
|
2226
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
2227
|
+
schema_type: "type[SchemaT] | None" = None,
|
|
2228
|
+
statement_config: "StatementConfig | None" = None,
|
|
2229
|
+
chunk_size: int = 1000,
|
|
2230
|
+
native_only: bool = False,
|
|
2231
|
+
**kwargs: Any,
|
|
2232
|
+
) -> "AsyncRowStream[SchemaT] | AsyncRowStream[dict[str, Any]]":
|
|
2233
|
+
"""Execute a query and stream rows in chunks with Oracle fetch tuning."""
|
|
2234
|
+
fetch_lobs = cast("bool | None", kwargs.pop("fetch_lobs", None))
|
|
2235
|
+
if chunk_size < 1:
|
|
2236
|
+
msg = "chunk_size must be greater than or equal to 1"
|
|
2237
|
+
raise ValueError(msg)
|
|
2238
|
+
config = statement_config or self.statement_config
|
|
2239
|
+
sql_statement = self.prepare_statement(statement, parameters, statement_config=config, kwargs=kwargs)
|
|
2240
|
+
stream = self.dispatch_select_stream(sql_statement, chunk_size, fetch_lobs=fetch_lobs)
|
|
2241
|
+
if stream is not None:
|
|
2242
|
+
return self._register_open_stream(stream._with_schema_type(schema_type))
|
|
2243
|
+
return super().select_stream(
|
|
2244
|
+
sql_statement,
|
|
2245
|
+
schema_type=schema_type,
|
|
2246
|
+
statement_config=config,
|
|
2247
|
+
chunk_size=chunk_size,
|
|
2248
|
+
native_only=native_only,
|
|
2249
|
+
)
|
|
2250
|
+
|
|
2251
|
+
def dispatch_select_stream(
|
|
2252
|
+
self, statement: "SQL", chunk_size: int, fetch_lobs: bool | None = None
|
|
2253
|
+
) -> "AsyncRowStream[dict[str, Any]] | None":
|
|
2254
|
+
"""Return a native oracledb row stream backed by chunked ``fetchmany``."""
|
|
2255
|
+
if not statement.returns_rows():
|
|
2256
|
+
return None
|
|
2257
|
+
sql, prepared_parameters = self._compiled_sql(statement, self.statement_config)
|
|
2258
|
+
stream_parameters = cast("list[object] | tuple[object, ...] | dict[object, object] | None", prepared_parameters)
|
|
2259
|
+
return AsyncRowStream(OracleAsyncStreamSource(self, sql, stream_parameters, chunk_size, fetch_lobs=fetch_lobs))
|
|
2260
|
+
|
|
2261
|
+
def handle_database_exceptions(self) -> "OracleAsyncExceptionHandler":
|
|
2262
|
+
"""Handle database-specific exceptions and wrap them appropriately."""
|
|
2263
|
+
return OracleAsyncExceptionHandler()
|
|
2264
|
+
|
|
2265
|
+
async def select_to_arrow(
|
|
2266
|
+
self,
|
|
2267
|
+
statement: "Statement | QueryBuilder",
|
|
2268
|
+
/,
|
|
2269
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
2270
|
+
statement_config: "StatementConfig | None" = None,
|
|
2271
|
+
return_format: "ArrowReturnFormat" = "table",
|
|
2272
|
+
native_only: bool = False,
|
|
2273
|
+
batch_size: int | None = None,
|
|
2274
|
+
arrow_schema: Any = None,
|
|
2275
|
+
**kwargs: Any,
|
|
2276
|
+
) -> "ArrowResult":
|
|
2277
|
+
"""Execute query and return results as Apache Arrow format using Oracle native support.
|
|
2278
|
+
|
|
2279
|
+
This implementation uses Oracle's native execute_df()/fetch_df_all() methods
|
|
2280
|
+
which return OracleDataFrame objects with Arrow C Stream interface, providing
|
|
2281
|
+
zero-copy data transfer and 5-10x performance improvement over dict conversion.
|
|
2282
|
+
If native Arrow is unavailable and native_only is False, it falls back to the
|
|
2283
|
+
conversion path.
|
|
2284
|
+
|
|
2285
|
+
Args:
|
|
2286
|
+
statement: SQL query string, Statement, or QueryBuilder
|
|
2287
|
+
*parameters: Query parameters (same format as execute()/select())
|
|
2288
|
+
statement_config: Optional statement configuration override
|
|
2289
|
+
return_format: "table" for pyarrow.Table (default), "batch" for RecordBatch,
|
|
2290
|
+
"batches" for list of RecordBatch, "reader" for RecordBatchReader
|
|
2291
|
+
native_only: If True, raise error if native Arrow is unavailable
|
|
2292
|
+
batch_size: Rows per batch when using "batch" or "batches" format
|
|
2293
|
+
arrow_schema: Optional pyarrow.Schema for type casting
|
|
2294
|
+
**kwargs: Additional keyword arguments
|
|
2295
|
+
|
|
2296
|
+
Returns:
|
|
2297
|
+
ArrowResult containing pyarrow.Table or RecordBatch
|
|
2298
|
+
"""
|
|
2299
|
+
ensure_pyarrow()
|
|
2300
|
+
|
|
2301
|
+
config = statement_config or self.statement_config
|
|
2302
|
+
prepared_statement = self.prepare_statement(statement, parameters, statement_config=config, kwargs=kwargs)
|
|
2303
|
+
sql, prepared_parameters = self._compiled_sql(prepared_statement, config)
|
|
2304
|
+
|
|
2305
|
+
prepared_parameters = await coerce_large_parameters_async(
|
|
2306
|
+
self.connection,
|
|
2307
|
+
prepared_parameters,
|
|
2308
|
+
clob_type=DB_TYPE_CLOB,
|
|
2309
|
+
blob_type=DB_TYPE_BLOB,
|
|
2310
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
2311
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
2312
|
+
version_cache=self._oracle_version_cache,
|
|
2313
|
+
)
|
|
2314
|
+
prepared_parameters = cast("list[Any] | tuple[Any, ...] | dict[Any, Any] | None", prepared_parameters)
|
|
2315
|
+
|
|
2316
|
+
exc_handler = self.handle_database_exceptions()
|
|
2317
|
+
arrow_fallback_error: AttributeError | None = None
|
|
2318
|
+
oracle_df: Any = None
|
|
2319
|
+
try:
|
|
2320
|
+
self._apply_session_tracing(self.connection)
|
|
2321
|
+
if return_format in {"batches", "reader"} and supports_df_batches(self.connection):
|
|
2322
|
+
batches_result = cast(
|
|
2323
|
+
"tuple[list[ArrowRecordBatch], ArrowSchema | None]",
|
|
2324
|
+
await self._run_with_exception_handler(
|
|
2325
|
+
exc_handler,
|
|
2326
|
+
self._fetch_arrow_record_batches,
|
|
2327
|
+
sql,
|
|
2328
|
+
prepared_parameters,
|
|
2329
|
+
batch_size,
|
|
2330
|
+
arrow_schema,
|
|
2331
|
+
),
|
|
2332
|
+
)
|
|
2333
|
+
self._check_pending_exception(exc_handler)
|
|
2334
|
+
record_batches, batch_schema = batches_result
|
|
2335
|
+
rows_affected = sum(batch.num_rows for batch in record_batches)
|
|
2336
|
+
pa = import_pyarrow()
|
|
2337
|
+
if batch_schema is None:
|
|
2338
|
+
batch_schema = arrow_schema if arrow_schema is not None else pa.schema([])
|
|
2339
|
+
arrow_data: object
|
|
2340
|
+
if return_format == "reader":
|
|
2341
|
+
arrow_data = pa.RecordBatchReader.from_batches(batch_schema, record_batches)
|
|
2342
|
+
else:
|
|
2343
|
+
arrow_data = record_batches
|
|
2344
|
+
return create_arrow_result(prepared_statement, arrow_data, rows_affected=rows_affected)
|
|
2345
|
+
|
|
2346
|
+
oracle_df = await self._run_with_exception_handler(
|
|
2347
|
+
exc_handler, self._execute_arrow_dataframe, sql, prepared_parameters, batch_size
|
|
2348
|
+
)
|
|
2349
|
+
except AttributeError as exc:
|
|
2350
|
+
arrow_fallback_error = exc
|
|
2351
|
+
if arrow_fallback_error is not None:
|
|
2352
|
+
if native_only:
|
|
2353
|
+
msg = "Oracle native Arrow support is not available for this connection."
|
|
2354
|
+
error = ImproperConfigurationError(msg)
|
|
2355
|
+
error.__cause__ = arrow_fallback_error
|
|
2356
|
+
raise error from arrow_fallback_error
|
|
2357
|
+
return await super().select_to_arrow(
|
|
2358
|
+
prepared_statement,
|
|
2359
|
+
statement_config=config,
|
|
2360
|
+
return_format=return_format,
|
|
2361
|
+
native_only=native_only,
|
|
2362
|
+
batch_size=batch_size,
|
|
2363
|
+
arrow_schema=arrow_schema,
|
|
2364
|
+
)
|
|
2365
|
+
self._check_pending_exception(exc_handler)
|
|
2366
|
+
|
|
2367
|
+
arrow_table = coerce_oracle_df_to_arrow_table(oracle_df, import_pyarrow())
|
|
2368
|
+
column_names = normalize_column_names(arrow_table.column_names, self.driver_features)
|
|
2369
|
+
if column_names != arrow_table.column_names:
|
|
2370
|
+
arrow_table = arrow_table.rename_columns(column_names)
|
|
2371
|
+
|
|
2372
|
+
return build_arrow_result_from_table(
|
|
2373
|
+
prepared_statement,
|
|
2374
|
+
arrow_table,
|
|
2375
|
+
return_format=return_format,
|
|
2376
|
+
batch_size=batch_size,
|
|
2377
|
+
arrow_schema=arrow_schema,
|
|
2378
|
+
)
|
|
2379
|
+
|
|
2380
|
+
async def execute_stack(
|
|
2381
|
+
self, stack: "StatementStack", *, continue_on_error: bool = False
|
|
2382
|
+
) -> "tuple[StackResult, ...]":
|
|
2383
|
+
"""Execute a StatementStack using Oracle's pipeline when available."""
|
|
2384
|
+
if not isinstance(stack, StatementStack) or not stack:
|
|
2385
|
+
return await super().execute_stack(stack, continue_on_error=continue_on_error)
|
|
2386
|
+
|
|
2387
|
+
blocker = self._stack_native_blocker(stack)
|
|
2388
|
+
if blocker is not None:
|
|
2389
|
+
self._log_pipeline_skip(blocker, stack)
|
|
2390
|
+
return await super().execute_stack(stack, continue_on_error=continue_on_error)
|
|
2391
|
+
|
|
2392
|
+
if not await self._pipeline_native_supported():
|
|
2393
|
+
self._log_pipeline_skip(self._pipeline_support_reason or "database_version", stack)
|
|
2394
|
+
return await super().execute_stack(stack, continue_on_error=continue_on_error)
|
|
2395
|
+
|
|
2396
|
+
return await self._execute_stack_native(stack, continue_on_error=continue_on_error)
|
|
2397
|
+
|
|
2398
|
+
async def select_to_storage(
|
|
2399
|
+
self,
|
|
2400
|
+
statement: "Statement | QueryBuilder | SQL | str",
|
|
2401
|
+
destination: "StorageDestination",
|
|
2402
|
+
/,
|
|
2403
|
+
*parameters: "StatementParameters | StatementFilter",
|
|
2404
|
+
statement_config: "StatementConfig | None" = None,
|
|
2405
|
+
partitioner: "dict[str, object] | None" = None,
|
|
2406
|
+
format_hint: "StorageFormat | None" = None,
|
|
2407
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
2408
|
+
**kwargs: Any,
|
|
2409
|
+
) -> "StorageBridgeJob":
|
|
2410
|
+
"""Execute a query and write Arrow-compatible output to storage (async)."""
|
|
2411
|
+
self._require_capability("arrow_export_enabled")
|
|
2412
|
+
arrow_result = await self._select_for_storage(
|
|
2413
|
+
statement, *parameters, statement_config=statement_config, **kwargs
|
|
2414
|
+
)
|
|
2415
|
+
async_pipeline = self._storage_pipeline()
|
|
2416
|
+
telemetry_payload = await self._write_storage_result(
|
|
2417
|
+
arrow_result, destination, format_hint=format_hint, pipeline=async_pipeline
|
|
2418
|
+
)
|
|
2419
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
2420
|
+
return self._storage_job(telemetry_payload, telemetry)
|
|
2421
|
+
|
|
2422
|
+
async def load_from_arrow(
|
|
2423
|
+
self,
|
|
2424
|
+
table: str,
|
|
2425
|
+
source: "ArrowResult | Any",
|
|
2426
|
+
*,
|
|
2427
|
+
partitioner: "dict[str, object] | None" = None,
|
|
2428
|
+
overwrite: bool = False,
|
|
2429
|
+
telemetry: "StorageTelemetry | None" = None,
|
|
2430
|
+
stage_table: "bool | str | None" = False,
|
|
2431
|
+
conflict_keys: "Sequence[str] | None" = None,
|
|
2432
|
+
on_conflict: Literal["update", "nothing"] = "update",
|
|
2433
|
+
exclude_update_columns: "Sequence[str] | None" = None,
|
|
2434
|
+
drop_stage_table: bool = True,
|
|
2435
|
+
drop_indexes: bool = False,
|
|
2436
|
+
concurrent_indexes: bool = True,
|
|
2437
|
+
type_casts: "Mapping[str, str] | None" = None,
|
|
2438
|
+
) -> "StorageBridgeJob":
|
|
2439
|
+
"""Asynchronously load Arrow data into Oracle."""
|
|
2440
|
+
self._require_capability("arrow_import_enabled")
|
|
2441
|
+
if drop_indexes:
|
|
2442
|
+
index_context = self.without_indexes(table, concurrent=concurrent_indexes)
|
|
2443
|
+
await index_context.__aenter__()
|
|
2444
|
+
index_error: BaseException | None = None
|
|
2445
|
+
index_job: StorageBridgeJob | None = None
|
|
2446
|
+
try:
|
|
2447
|
+
index_job = await self.load_from_arrow(
|
|
2448
|
+
table,
|
|
2449
|
+
source,
|
|
2450
|
+
partitioner=partitioner,
|
|
2451
|
+
overwrite=overwrite,
|
|
2452
|
+
telemetry=telemetry,
|
|
2453
|
+
stage_table=stage_table,
|
|
2454
|
+
conflict_keys=conflict_keys,
|
|
2455
|
+
on_conflict=on_conflict,
|
|
2456
|
+
exclude_update_columns=exclude_update_columns,
|
|
2457
|
+
drop_stage_table=drop_stage_table,
|
|
2458
|
+
drop_indexes=False,
|
|
2459
|
+
concurrent_indexes=concurrent_indexes,
|
|
2460
|
+
type_casts=type_casts,
|
|
2461
|
+
)
|
|
2462
|
+
except BaseException as exc:
|
|
2463
|
+
index_error = exc
|
|
2464
|
+
await exit_async_context(index_context, index_error)
|
|
2465
|
+
assert index_job is not None
|
|
2466
|
+
return index_job
|
|
2467
|
+
if stage_table or conflict_keys:
|
|
2468
|
+
return await self._execute_staged_load_async(
|
|
2469
|
+
table,
|
|
2470
|
+
source,
|
|
2471
|
+
raw_loader=self.load_from_arrow,
|
|
2472
|
+
partitioner=partitioner,
|
|
2473
|
+
overwrite=overwrite,
|
|
2474
|
+
telemetry=telemetry,
|
|
2475
|
+
stage_table=stage_table,
|
|
2476
|
+
conflict_keys=conflict_keys,
|
|
2477
|
+
on_conflict=on_conflict,
|
|
2478
|
+
exclude_update_columns=exclude_update_columns,
|
|
2479
|
+
drop_stage_table=drop_stage_table,
|
|
2480
|
+
drop_indexes=False,
|
|
2481
|
+
concurrent_indexes=concurrent_indexes,
|
|
2482
|
+
type_casts=type_casts,
|
|
2483
|
+
)
|
|
2484
|
+
arrow_table = self._coerce_arrow_table(source)
|
|
2485
|
+
if overwrite:
|
|
2486
|
+
statement = build_truncate_statement(table)
|
|
2487
|
+
exc_handler = self.handle_database_exceptions()
|
|
2488
|
+
await self._run_with_exception_handler(exc_handler, self.connection.execute, statement)
|
|
2489
|
+
self._check_pending_exception(exc_handler)
|
|
2490
|
+
use_direct_path = (
|
|
2491
|
+
self.driver_features.get("enable_direct_path_load", True) is not False
|
|
2492
|
+
and supports_direct_path_load(self.connection)
|
|
2493
|
+
and _arrow_schema_supports_direct_path(arrow_table)
|
|
2494
|
+
)
|
|
2495
|
+
if arrow_table.num_rows:
|
|
2496
|
+
if use_direct_path:
|
|
2497
|
+
schema_name, table_name = _resolve_direct_path_target(self.connection, table)
|
|
2498
|
+
exc_handler = self.handle_database_exceptions()
|
|
2499
|
+
await self._run_with_exception_handler(
|
|
2500
|
+
exc_handler,
|
|
2501
|
+
self.connection.direct_path_load,
|
|
2502
|
+
schema_name=schema_name,
|
|
2503
|
+
table_name=table_name,
|
|
2504
|
+
column_names=list(arrow_table.column_names),
|
|
2505
|
+
data=arrow_table,
|
|
2506
|
+
)
|
|
2507
|
+
self._check_pending_exception(exc_handler)
|
|
2508
|
+
else:
|
|
2509
|
+
columns = list(arrow_table.column_names)
|
|
2510
|
+
statement = build_insert_statement(table, columns)
|
|
2511
|
+
exc_handler = self.handle_database_exceptions()
|
|
2512
|
+
|
|
2513
|
+
async def _insert_batches() -> None:
|
|
2514
|
+
async with self.with_cursor(self.connection) as cursor:
|
|
2515
|
+
for batch in arrow_table.to_batches(max_chunksize=5000):
|
|
2516
|
+
batch_rows = self._arrow_batch_to_rows(batch, columns)
|
|
2517
|
+
coerced_rows = await coerce_many_parameters_async(
|
|
2518
|
+
self.connection,
|
|
2519
|
+
batch_rows,
|
|
2520
|
+
clob_type=DB_TYPE_CLOB,
|
|
2521
|
+
blob_type=DB_TYPE_BLOB,
|
|
2522
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
2523
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
2524
|
+
version_cache=self._oracle_version_cache,
|
|
2525
|
+
)
|
|
2526
|
+
await cursor.executemany(statement, coerced_rows)
|
|
2527
|
+
|
|
2528
|
+
await self._run_with_exception_handler(exc_handler, _insert_batches)
|
|
2529
|
+
self._check_pending_exception(exc_handler)
|
|
2530
|
+
telemetry_payload = self._ingest_telemetry(arrow_table)
|
|
2531
|
+
telemetry_payload["destination"] = table
|
|
2532
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
2533
|
+
return self._storage_job(telemetry_payload, telemetry)
|
|
2534
|
+
|
|
2535
|
+
async def load_from_storage(
|
|
2536
|
+
self,
|
|
2537
|
+
table: str,
|
|
2538
|
+
source: "StorageDestination",
|
|
2539
|
+
*,
|
|
2540
|
+
file_format: "StorageFormat",
|
|
2541
|
+
partitioner: "dict[str, object] | None" = None,
|
|
2542
|
+
overwrite: bool = False,
|
|
2543
|
+
credential_name: str | None = None,
|
|
2544
|
+
format_options: "Mapping[str, Any] | None" = None,
|
|
2545
|
+
**kwargs: Any,
|
|
2546
|
+
) -> "StorageBridgeJob":
|
|
2547
|
+
"""Asynchronously load staged artifacts into Oracle via ``DBMS_CLOUD.COPY_DATA`` or client-side Arrow."""
|
|
2548
|
+
raw_credential = (
|
|
2549
|
+
credential_name if credential_name is not None else self.driver_features.get("dbms_cloud_credential")
|
|
2550
|
+
)
|
|
2551
|
+
effective_credential = (
|
|
2552
|
+
raw_credential.strip() if isinstance(raw_credential, str) and raw_credential.strip() else None
|
|
2553
|
+
)
|
|
2554
|
+
if effective_credential is not None and not kwargs:
|
|
2555
|
+
resolved_source: StorageDestination = (
|
|
2556
|
+
self._storage_pipeline().resolve_destination(source).uri
|
|
2557
|
+
if isinstance(source, str) and source.startswith("alias://")
|
|
2558
|
+
else source
|
|
2559
|
+
)
|
|
2560
|
+
remote_uri = (
|
|
2561
|
+
resolve_dbms_cloud_source_uri(resolved_source, file_format=file_format)
|
|
2562
|
+
if isinstance(resolved_source, (str, Path))
|
|
2563
|
+
else None
|
|
2564
|
+
)
|
|
2565
|
+
if remote_uri is not None:
|
|
2566
|
+
plsql, binds = build_dbms_cloud_copy_data_sql(
|
|
2567
|
+
table,
|
|
2568
|
+
credential_name=effective_credential,
|
|
2569
|
+
file_uri=remote_uri,
|
|
2570
|
+
file_format=file_format,
|
|
2571
|
+
format_options=format_options,
|
|
2572
|
+
)
|
|
2573
|
+
truncate_sql = build_truncate_statement(table) if overwrite else None
|
|
2574
|
+
rows_processed = 0
|
|
2575
|
+
exc_handler = self.handle_database_exceptions()
|
|
2576
|
+
|
|
2577
|
+
async def _run_dbms_cloud_async() -> None:
|
|
2578
|
+
nonlocal rows_processed
|
|
2579
|
+
async with self.with_cursor(self.connection) as cursor:
|
|
2580
|
+
if truncate_sql is not None:
|
|
2581
|
+
await cursor.execute(truncate_sql)
|
|
2582
|
+
await cursor.execute(plsql, binds)
|
|
2583
|
+
rows_processed = resolve_rowcount(cursor)
|
|
2584
|
+
|
|
2585
|
+
await self._run_with_exception_handler(exc_handler, _run_dbms_cloud_async)
|
|
2586
|
+
self._check_pending_exception(exc_handler)
|
|
2587
|
+
telemetry_payload: StorageTelemetry = {
|
|
2588
|
+
"destination": table,
|
|
2589
|
+
"backend": "dbms_cloud",
|
|
2590
|
+
"format": file_format,
|
|
2591
|
+
"rows_processed": rows_processed,
|
|
2592
|
+
"extra": {"source_uri": remote_uri, "credential_name": effective_credential},
|
|
2593
|
+
}
|
|
2594
|
+
self._attach_partition_telemetry(telemetry_payload, partitioner)
|
|
2595
|
+
return self._storage_job(telemetry_payload)
|
|
2596
|
+
if kwargs:
|
|
2597
|
+
validate_load_from_storage_kwargs(kwargs)
|
|
2598
|
+
return await super().load_from_storage(
|
|
2599
|
+
table,
|
|
2600
|
+
source,
|
|
2601
|
+
file_format=file_format,
|
|
2602
|
+
partitioner=partitioner,
|
|
2603
|
+
overwrite=overwrite,
|
|
2604
|
+
storage_options=kwargs.get("storage_options"),
|
|
2605
|
+
stage_table=kwargs.get("stage_table"),
|
|
2606
|
+
conflict_keys=kwargs.get("conflict_keys"),
|
|
2607
|
+
on_conflict=kwargs.get("on_conflict", "update"),
|
|
2608
|
+
exclude_update_columns=kwargs.get("exclude_update_columns"),
|
|
2609
|
+
drop_stage_table=kwargs.get("drop_stage_table", True),
|
|
2610
|
+
drop_indexes=kwargs.get("drop_indexes", False),
|
|
2611
|
+
concurrent_indexes=kwargs.get("concurrent_indexes", False),
|
|
2612
|
+
checkpoint_table=kwargs.get("checkpoint_table"),
|
|
2613
|
+
checkpoint_phase=kwargs.get("checkpoint_phase", "default"),
|
|
2614
|
+
max_workers=kwargs.get("max_workers", 1),
|
|
2615
|
+
executor=kwargs.get("executor", "thread"),
|
|
2616
|
+
arrow_schema=kwargs.get("arrow_schema"),
|
|
2617
|
+
type_casts=kwargs.get("type_casts"),
|
|
2618
|
+
)
|
|
2619
|
+
arrow_table, inbound = await self._read_storage_arrow(source, file_format=file_format)
|
|
2620
|
+
return await self.load_from_arrow(
|
|
2621
|
+
table, arrow_table, partitioner=partitioner, overwrite=overwrite, telemetry=inbound
|
|
2622
|
+
)
|
|
2623
|
+
|
|
2624
|
+
def collect_rows(self, cursor: Any, fetched: "list[Any]") -> "tuple[list[Any], list[str], int]":
|
|
2625
|
+
"""Collect Oracle async rows for the direct execution path.
|
|
2626
|
+
|
|
2627
|
+
Falls back to the standard async dispatch path when rows contain async
|
|
2628
|
+
LOB locators, because those must be read with ``collect_async_rows``.
|
|
2629
|
+
"""
|
|
2630
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
2631
|
+
if fetched and any(_row_has_async_readable(row) for row in fetched):
|
|
2632
|
+
msg = "Oracle async LOB locators require async row collection"
|
|
2633
|
+
raise NotImplementedError(msg)
|
|
2634
|
+
data, column_names = collect_sync_rows(
|
|
2635
|
+
cast("list[Any] | None", fetched),
|
|
2636
|
+
cursor.description,
|
|
2637
|
+
self.driver_features,
|
|
2638
|
+
column_names=column_names,
|
|
2639
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
2640
|
+
)
|
|
2641
|
+
return data, column_names, len(data)
|
|
2642
|
+
|
|
2643
|
+
def resolve_rowcount(self, cursor: Any) -> int:
|
|
2644
|
+
"""Resolve rowcount from Oracle cursor for the direct execution path."""
|
|
2645
|
+
return resolve_rowcount(cursor)
|
|
2646
|
+
|
|
2647
|
+
async def _select_for_storage(
|
|
2648
|
+
self,
|
|
2649
|
+
statement: "Statement | QueryBuilder | SQL | str",
|
|
2650
|
+
/,
|
|
2651
|
+
*parameters: Any,
|
|
2652
|
+
statement_config: "StatementConfig | None" = None,
|
|
2653
|
+
**kwargs: Any,
|
|
2654
|
+
) -> "ArrowResult":
|
|
2655
|
+
"""Return an Arrow result that streams Oracle frames on demand for storage exports."""
|
|
2656
|
+
if "return_format" in kwargs or kwargs.get("native_only") or not supports_df_batches(self.connection):
|
|
2657
|
+
return await super()._select_for_storage(
|
|
2658
|
+
statement, *parameters, statement_config=statement_config, **kwargs
|
|
2659
|
+
)
|
|
2660
|
+
|
|
2661
|
+
ensure_pyarrow()
|
|
2662
|
+
batch_size = cast("int | None", kwargs.pop("batch_size", None))
|
|
2663
|
+
arrow_schema = cast("ArrowSchema | None", kwargs.pop("arrow_schema", None))
|
|
2664
|
+
|
|
2665
|
+
config = statement_config or self.statement_config
|
|
2666
|
+
prepared_statement = self.prepare_statement(statement, parameters, statement_config=config, kwargs=kwargs)
|
|
2667
|
+
sql, prepared_parameters = self._compiled_sql(prepared_statement, config)
|
|
2668
|
+
prepared_parameters = await coerce_large_parameters_async(
|
|
2669
|
+
self.connection,
|
|
2670
|
+
prepared_parameters,
|
|
2671
|
+
clob_type=DB_TYPE_CLOB,
|
|
2672
|
+
blob_type=DB_TYPE_BLOB,
|
|
2673
|
+
varchar2_byte_limit=self.driver_features.get("oracle_varchar2_byte_limit", 4000),
|
|
2674
|
+
raw_byte_limit=self.driver_features.get("oracle_raw_byte_limit", 2000),
|
|
2675
|
+
version_cache=self._oracle_version_cache,
|
|
2676
|
+
)
|
|
2677
|
+
prepared_parameters = cast("list[Any] | tuple[Any, ...] | dict[Any, Any] | None", prepared_parameters)
|
|
2678
|
+
self._apply_session_tracing(self.connection)
|
|
2679
|
+
return create_arrow_result(
|
|
2680
|
+
prepared_statement,
|
|
2681
|
+
self._iter_arrow_record_batches(sql, prepared_parameters, batch_size, arrow_schema),
|
|
2682
|
+
rows_affected=0,
|
|
2683
|
+
metadata={"streamed": True},
|
|
2684
|
+
)
|
|
2685
|
+
|
|
2686
|
+
async def _execute_cache_hit_with_cursor(
|
|
2687
|
+
self, sql: str, params: "tuple[Any, ...] | list[Any] | dict[str, Any]", cached: "CachedQuery"
|
|
2688
|
+
) -> "SQLResult":
|
|
2689
|
+
"""Execute an async cached query through the compiled Oracle cache-hit executor."""
|
|
2690
|
+
return await execute_cache_hit_async(
|
|
2691
|
+
self.connection, sql, params, cached, self.statement_config, self._cache_hit_state
|
|
2692
|
+
)
|
|
2693
|
+
|
|
2694
|
+
def _connection_in_transaction(self) -> bool:
|
|
2695
|
+
"""Report whether a transaction is open on the connection.
|
|
2696
|
+
|
|
2697
|
+
Oracle opens a transaction implicitly on the first DML, which the
|
|
2698
|
+
ownership flag alone cannot see, while ``begin()`` sets the flag without
|
|
2699
|
+
issuing SQL, which the native predicate alone cannot see. Both signals
|
|
2700
|
+
are required.
|
|
2701
|
+
"""
|
|
2702
|
+
return (
|
|
2703
|
+
self._sessionless_transaction_id is not None
|
|
2704
|
+
or self._transaction_active
|
|
2705
|
+
or bool(self.connection.transaction_in_progress)
|
|
2706
|
+
)
|
|
2707
|
+
|
|
2708
|
+
def _detect_oracledb_version(self) -> "tuple[int, int, int]":
|
|
2709
|
+
return ORACLEDB_VERSION
|
|
2710
|
+
|
|
2711
|
+
def _resolve_row_metadata(self, description: Any) -> "tuple[list[str], bool]":
|
|
2712
|
+
return resolve_row_metadata(description, self.driver_features, self._row_metadata_cache)
|
|
2713
|
+
|
|
2714
|
+
async def _dispatch_explain_plan(
|
|
2715
|
+
self,
|
|
2716
|
+
cursor: Any,
|
|
2717
|
+
explained_sql: str,
|
|
2718
|
+
parameters: Any,
|
|
2719
|
+
*,
|
|
2720
|
+
display_cursor: bool = False,
|
|
2721
|
+
xplan_format: str = "TYPICAL",
|
|
2722
|
+
) -> "ExecutionResult":
|
|
2723
|
+
"""Request a plan, read it back, and release the plan table rows.
|
|
2724
|
+
|
|
2725
|
+
Oracle writes the plan to a table instead of returning it, so the plan is
|
|
2726
|
+
tagged with a generated statement id, formatted through ``DBMS_XPLAN``, and
|
|
2727
|
+
deleted again. All three statements run in the caller's transaction, so the
|
|
2728
|
+
plan is read before a rollback can discard it. When ``display_cursor`` is
|
|
2729
|
+
enabled, the statement is executed first and formatted through
|
|
2730
|
+
``DBMS_XPLAN.DISPLAY_CURSOR``.
|
|
2731
|
+
|
|
2732
|
+
Args:
|
|
2733
|
+
cursor: Oracle cursor object.
|
|
2734
|
+
explained_sql: Statement whose plan is wanted.
|
|
2735
|
+
parameters: Bind values for the explained statement.
|
|
2736
|
+
display_cursor: Whether to inspect actual cursor execution statistics via ``DBMS_XPLAN.DISPLAY_CURSOR``.
|
|
2737
|
+
xplan_format: ``DBMS_XPLAN`` format string.
|
|
2738
|
+
|
|
2739
|
+
Returns:
|
|
2740
|
+
Execution result carrying the formatted plan rows.
|
|
2741
|
+
"""
|
|
2742
|
+
if display_cursor:
|
|
2743
|
+
await cursor.execute(explained_sql, parameters or {}, **self._fetch_kwargs)
|
|
2744
|
+
if cursor.description is not None:
|
|
2745
|
+
await cursor.fetchall()
|
|
2746
|
+
await cursor.execute(_format_display_cursor_sql(xplan_format), {}, **self._fetch_kwargs)
|
|
2747
|
+
fetched_data = await cursor.fetchall()
|
|
2748
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
2749
|
+
data, column_names = await collect_async_rows(
|
|
2750
|
+
cast("list[Any] | None", fetched_data),
|
|
2751
|
+
cursor.description,
|
|
2752
|
+
self.driver_features,
|
|
2753
|
+
column_names=column_names,
|
|
2754
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
2755
|
+
)
|
|
2756
|
+
return self.create_execution_result(
|
|
2757
|
+
cursor,
|
|
2758
|
+
selected_data=data,
|
|
2759
|
+
column_names=column_names,
|
|
2760
|
+
data_row_count=len(data),
|
|
2761
|
+
is_select_result=True,
|
|
2762
|
+
row_format="tuple",
|
|
2763
|
+
)
|
|
2764
|
+
|
|
2765
|
+
statement_id = _new_plan_statement_id()
|
|
2766
|
+
await cursor.execute(_tagged_explain_plan_sql(statement_id, explained_sql), parameters or {})
|
|
2767
|
+
display_sql = PLAN_DISPLAY_SQL if xplan_format == "TYPICAL" else _format_plan_display_sql(xplan_format)
|
|
2768
|
+
|
|
2769
|
+
display_error: Exception | None = None
|
|
2770
|
+
result: ExecutionResult | None = None
|
|
2771
|
+
try:
|
|
2772
|
+
await cursor.execute(display_sql, {"statement_id": statement_id}, **self._fetch_kwargs)
|
|
2773
|
+
fetched_data = await cursor.fetchall()
|
|
2774
|
+
column_names, requires_lob_coercion = self._resolve_row_metadata(cursor.description)
|
|
2775
|
+
data, column_names = await collect_async_rows(
|
|
2776
|
+
cast("list[Any] | None", fetched_data),
|
|
2777
|
+
cursor.description,
|
|
2778
|
+
self.driver_features,
|
|
2779
|
+
column_names=column_names,
|
|
2780
|
+
requires_lob_coercion=requires_lob_coercion,
|
|
2781
|
+
)
|
|
2782
|
+
result = self.create_execution_result(
|
|
2783
|
+
cursor,
|
|
2784
|
+
selected_data=data,
|
|
2785
|
+
column_names=column_names,
|
|
2786
|
+
data_row_count=len(data),
|
|
2787
|
+
is_select_result=True,
|
|
2788
|
+
row_format="tuple",
|
|
2789
|
+
)
|
|
2790
|
+
except Exception as exc:
|
|
2791
|
+
display_error = exc
|
|
2792
|
+
if display_error is not None:
|
|
2793
|
+
try:
|
|
2794
|
+
await cursor.execute(PLAN_CLEANUP_SQL, {"statement_id": statement_id})
|
|
2795
|
+
except Exception:
|
|
2796
|
+
logger.warning("Failed to clean up Oracle plan rows after plan retrieval failed", exc_info=True)
|
|
2797
|
+
raise display_error
|
|
2798
|
+
await cursor.execute(PLAN_CLEANUP_SQL, {"statement_id": statement_id})
|
|
2799
|
+
assert result is not None
|
|
2800
|
+
return result
|
|
2801
|
+
|
|
2802
|
+
async def _execute_arrow_dataframe(self, sql: str, parameters: "Any", batch_size: int | None) -> "Any":
|
|
2803
|
+
"""Execute SQL and return an Oracle DataFrame."""
|
|
2804
|
+
params = parameters if parameters is not None else []
|
|
2805
|
+
try:
|
|
2806
|
+
execute_df = self.connection.execute_df
|
|
2807
|
+
except AttributeError:
|
|
2808
|
+
execute_df = None
|
|
2809
|
+
if execute_df is not None:
|
|
2810
|
+
fallback_to_plain = False
|
|
2811
|
+
try:
|
|
2812
|
+
return await execute_df(sql, params, arraysize=batch_size or 1000)
|
|
2813
|
+
except TypeError:
|
|
2814
|
+
fallback_to_plain = True
|
|
2815
|
+
if fallback_to_plain:
|
|
2816
|
+
return await execute_df(sql, params)
|
|
2817
|
+
fetch_kwargs = build_arrow_fetch_kwargs(self.driver_features)
|
|
2818
|
+
retry_kwargs: dict[str, Any] | None = None
|
|
2819
|
+
fetch_error: TypeError | None = None
|
|
2820
|
+
try:
|
|
2821
|
+
return await self.connection.fetch_df_all(
|
|
2822
|
+
statement=sql, parameters=params, arraysize=batch_size or 1000, **fetch_kwargs
|
|
2823
|
+
)
|
|
2824
|
+
except TypeError as exc:
|
|
2825
|
+
fetch_error = exc
|
|
2826
|
+
retry_kwargs = _retry_arrow_without_fetch_lobs(exc, fetch_kwargs)
|
|
2827
|
+
if retry_kwargs is None:
|
|
2828
|
+
assert fetch_error is not None
|
|
2829
|
+
raise fetch_error
|
|
2830
|
+
return await self.connection.fetch_df_all(
|
|
2831
|
+
statement=sql, parameters=params, arraysize=batch_size or 1000, **retry_kwargs
|
|
2832
|
+
)
|
|
2833
|
+
|
|
2834
|
+
def _iter_arrow_record_batches(
|
|
2835
|
+
self,
|
|
2836
|
+
sql: str,
|
|
2837
|
+
parameters: "StatementParameters | None",
|
|
2838
|
+
batch_size: int | None,
|
|
2839
|
+
arrow_schema: "ArrowSchema | None",
|
|
2840
|
+
) -> "AsyncIterator[ArrowRecordBatch]":
|
|
2841
|
+
return _OracleAsyncArrowBatchIterator(
|
|
2842
|
+
self.connection, sql, parameters, batch_size, self.driver_features, arrow_schema
|
|
2843
|
+
)
|
|
2844
|
+
|
|
2845
|
+
async def _fetch_arrow_record_batches(
|
|
2846
|
+
self,
|
|
2847
|
+
sql: str,
|
|
2848
|
+
parameters: "StatementParameters | None",
|
|
2849
|
+
batch_size: int | None,
|
|
2850
|
+
arrow_schema: "ArrowSchema | None",
|
|
2851
|
+
) -> "tuple[list[ArrowRecordBatch], ArrowSchema | None]":
|
|
2852
|
+
record_batches: list[ArrowRecordBatch] = []
|
|
2853
|
+
batch_schema: ArrowSchema | None = None
|
|
2854
|
+
oracle_dfs = _fetch_dataframe_batches(
|
|
2855
|
+
self.connection, sql, parameters, batch_size, self.driver_features, arrow_schema
|
|
2856
|
+
)
|
|
2857
|
+
fetch_error: BaseException | None = None
|
|
2858
|
+
try:
|
|
2859
|
+
async for oracle_df in oracle_dfs:
|
|
2860
|
+
batch_table = _coerce_oracle_arrow_batch_table(oracle_df, self.driver_features, arrow_schema)
|
|
2861
|
+
if batch_schema is None:
|
|
2862
|
+
batch_schema = batch_table.schema
|
|
2863
|
+
record_batches.extend(batch_table.to_batches())
|
|
2864
|
+
except BaseException as exc:
|
|
2865
|
+
fetch_error = exc
|
|
2866
|
+
aclose_dfs = getattr(oracle_dfs, "aclose", None)
|
|
2867
|
+
if callable(aclose_dfs):
|
|
2868
|
+
await cast("Any", aclose_dfs)()
|
|
2869
|
+
else:
|
|
2870
|
+
close_dfs = getattr(oracle_dfs, "close", None)
|
|
2871
|
+
if callable(close_dfs):
|
|
2872
|
+
close_dfs()
|
|
2873
|
+
if fetch_error is not None:
|
|
2874
|
+
if isinstance(fetch_error, OracleError):
|
|
2875
|
+
raise with_cause(create_mapped_exception(fetch_error), fetch_error) from fetch_error
|
|
2876
|
+
raise fetch_error
|
|
2877
|
+
return record_batches, batch_schema
|
|
2878
|
+
|
|
2879
|
+
async def _execute_stack_native(
|
|
2880
|
+
self, stack: "StatementStack", *, continue_on_error: bool
|
|
2881
|
+
) -> "tuple[StackResult, ...]":
|
|
2882
|
+
|
|
2883
|
+
raw_operations = [self._prepare_pipeline_operation(op) for op in stack.operations]
|
|
2884
|
+
compiled_operations: list[_CompiledStackOperation] = []
|
|
2885
|
+
pipeline = create_oracle_pipeline()
|
|
2886
|
+
varchar2_limit = self.driver_features.get("oracle_varchar2_byte_limit", 4000)
|
|
2887
|
+
raw_limit = self.driver_features.get("oracle_raw_byte_limit", 2000)
|
|
2888
|
+
for compiled in raw_operations:
|
|
2889
|
+
if compiled.method == "execute_many":
|
|
2890
|
+
coerced_params: Any = await coerce_many_parameters_async(
|
|
2891
|
+
self.connection,
|
|
2892
|
+
compiled.parameters,
|
|
2893
|
+
clob_type=DB_TYPE_CLOB,
|
|
2894
|
+
blob_type=DB_TYPE_BLOB,
|
|
2895
|
+
varchar2_byte_limit=varchar2_limit,
|
|
2896
|
+
raw_byte_limit=raw_limit,
|
|
2897
|
+
version_cache=self._oracle_version_cache,
|
|
2898
|
+
)
|
|
2899
|
+
else:
|
|
2900
|
+
coerced_params = await coerce_large_parameters_async(
|
|
2901
|
+
self.connection,
|
|
2902
|
+
compiled.parameters,
|
|
2903
|
+
clob_type=DB_TYPE_CLOB,
|
|
2904
|
+
blob_type=DB_TYPE_BLOB,
|
|
2905
|
+
varchar2_byte_limit=varchar2_limit,
|
|
2906
|
+
raw_byte_limit=raw_limit,
|
|
2907
|
+
version_cache=self._oracle_version_cache,
|
|
2908
|
+
)
|
|
2909
|
+
coerced_op = compiled._replace(parameters=coerced_params)
|
|
2910
|
+
compiled_operations.append(coerced_op)
|
|
2911
|
+
self._add_pipeline_operation(pipeline, coerced_op)
|
|
2912
|
+
|
|
2913
|
+
results: list[StackResult] = []
|
|
2914
|
+
owns_transaction = not self._connection_in_transaction()
|
|
2915
|
+
|
|
2916
|
+
with StackExecutionObserver(self, stack, continue_on_error, native_pipeline=True) as observer:
|
|
2917
|
+
pipeline_error: Exception | None = None
|
|
2918
|
+
try:
|
|
2919
|
+
pipelined_commit = owns_transaction and not continue_on_error
|
|
2920
|
+
if owns_transaction:
|
|
2921
|
+
await self.begin()
|
|
2922
|
+
if pipelined_commit:
|
|
2923
|
+
pipeline.add_commit()
|
|
2924
|
+
self._apply_session_tracing(self.connection)
|
|
2925
|
+
pipeline_results = await self.connection.run_pipeline(pipeline, continue_on_error=continue_on_error)
|
|
2926
|
+
has_commit_result = pipelined_commit and len(pipeline_results) > len(compiled_operations)
|
|
2927
|
+
if has_commit_result:
|
|
2928
|
+
self._check_pipeline_commit_result(pipeline_results[len(compiled_operations)])
|
|
2929
|
+
statement_results = pipeline_results[: len(compiled_operations)]
|
|
2930
|
+
coerced_rows_by_index = {
|
|
2931
|
+
index: await coerce_pipeline_rows_async(result.rows, self.driver_features)
|
|
2932
|
+
for index, (compiled, result) in enumerate(
|
|
2933
|
+
zip(compiled_operations, statement_results, strict=False)
|
|
2934
|
+
)
|
|
2935
|
+
if compiled.returns_rows and getattr(result, "error", None) is None
|
|
2936
|
+
}
|
|
2937
|
+
results = self._build_stack_results_from_pipeline(
|
|
2938
|
+
compiled_operations,
|
|
2939
|
+
statement_results,
|
|
2940
|
+
continue_on_error,
|
|
2941
|
+
observer,
|
|
2942
|
+
coerced_rows_by_index=coerced_rows_by_index,
|
|
2943
|
+
)
|
|
2944
|
+
if owns_transaction:
|
|
2945
|
+
if has_commit_result:
|
|
2946
|
+
self._transaction_active = False
|
|
2947
|
+
elif not continue_on_error or any(item.error is None for item in results):
|
|
2948
|
+
await self.commit()
|
|
2949
|
+
else:
|
|
2950
|
+
await self.rollback()
|
|
2951
|
+
except Exception as exc:
|
|
2952
|
+
pipeline_error = exc
|
|
2953
|
+
if pipeline_error is not None:
|
|
2954
|
+
if owns_transaction:
|
|
2955
|
+
try:
|
|
2956
|
+
await self.rollback()
|
|
2957
|
+
except Exception as rollback_error:
|
|
2958
|
+
logger.debug("Rollback after pipeline failure failed: %s", rollback_error)
|
|
2959
|
+
if isinstance(pipeline_error, StackExecutionError):
|
|
2960
|
+
raise pipeline_error
|
|
2961
|
+
raise with_cause(
|
|
2962
|
+
self._wrap_pipeline_error(pipeline_error, stack, continue_on_error), pipeline_error
|
|
2963
|
+
) from pipeline_error
|
|
2964
|
+
|
|
2965
|
+
return tuple(results)
|
|
2966
|
+
|
|
2967
|
+
async def _pipeline_native_supported(self) -> bool:
|
|
2968
|
+
if self._pipeline_support is not None:
|
|
2969
|
+
return self._pipeline_support
|
|
2970
|
+
|
|
2971
|
+
if self.stack_native_disabled:
|
|
2972
|
+
self._pipeline_support = False
|
|
2973
|
+
self._pipeline_support_reason = "env_override"
|
|
2974
|
+
return False
|
|
2975
|
+
|
|
2976
|
+
if self._detect_oracledb_version() < PIPELINE_MIN_DRIVER_VERSION:
|
|
2977
|
+
self._pipeline_support = False
|
|
2978
|
+
self._pipeline_support_reason = "driver_version"
|
|
2979
|
+
return False
|
|
2980
|
+
|
|
2981
|
+
if not has_pipeline_capability(self.connection):
|
|
2982
|
+
self._pipeline_support = False
|
|
2983
|
+
self._pipeline_support_reason = "driver_api_missing"
|
|
2984
|
+
return False
|
|
2985
|
+
|
|
2986
|
+
if not connection_is_thin(self.connection):
|
|
2987
|
+
self._pipeline_support = False
|
|
2988
|
+
self._pipeline_support_reason = "thin_mode_required"
|
|
2989
|
+
return False
|
|
2990
|
+
|
|
2991
|
+
connection_major = resolve_oracle_connection_major(self.connection, self._oracle_version_cache)
|
|
2992
|
+
if connection_major is not None:
|
|
2993
|
+
if connection_major >= PIPELINE_MIN_DATABASE_MAJOR:
|
|
2994
|
+
self._pipeline_support = True
|
|
2995
|
+
self._pipeline_support_reason = None
|
|
2996
|
+
return True
|
|
2997
|
+
self._pipeline_support = False
|
|
2998
|
+
self._pipeline_support_reason = "database_version"
|
|
2999
|
+
return False
|
|
3000
|
+
|
|
3001
|
+
version_info = await self.data_dictionary.get_version(self)
|
|
3002
|
+
if version_info and version_info.major >= PIPELINE_MIN_DATABASE_MAJOR:
|
|
3003
|
+
self._pipeline_support = True
|
|
3004
|
+
self._pipeline_support_reason = None
|
|
3005
|
+
return True
|
|
3006
|
+
|
|
3007
|
+
self._pipeline_support = False
|
|
3008
|
+
self._pipeline_support_reason = "database_version"
|
|
3009
|
+
return False
|
|
3010
|
+
|
|
3011
|
+
|
|
3012
|
+
register_driver_profile("oracledb", driver_profile)
|
|
3013
|
+
|
|
3014
|
+
|
|
3015
|
+
class _CompiledStackOperation(NamedTuple):
|
|
3016
|
+
statement: SQL
|
|
3017
|
+
sql: str
|
|
3018
|
+
parameters: Any
|
|
3019
|
+
method: str
|
|
3020
|
+
returns_rows: bool
|
|
3021
|
+
summary: str
|
|
3022
|
+
|
|
3023
|
+
|
|
3024
|
+
def _arrow_schema_supports_direct_path(arrow_table: Any) -> bool:
|
|
3025
|
+
"""Report whether every column maps to a type direct path load can ingest.
|
|
3026
|
+
|
|
3027
|
+
This is an allow-list rather than a nested-type check. oracledb converts a
|
|
3028
|
+
limited set of Arrow types, and a conversion it cannot perform fails part
|
|
3029
|
+
way through the load, so anything unrecognized takes the insert path.
|
|
3030
|
+
|
|
3031
|
+
Args:
|
|
3032
|
+
arrow_table: The Arrow table about to be ingested.
|
|
3033
|
+
|
|
3034
|
+
Returns:
|
|
3035
|
+
True when every column type is known to be convertible.
|
|
3036
|
+
"""
|
|
3037
|
+
ensure_pyarrow()
|
|
3038
|
+
pa = import_pyarrow()
|
|
3039
|
+
|
|
3040
|
+
for field in arrow_table.schema:
|
|
3041
|
+
data_type = field.type
|
|
3042
|
+
supported = (
|
|
3043
|
+
pa.types.is_integer(data_type)
|
|
3044
|
+
or (pa.types.is_floating(data_type) and not pa.types.is_float16(data_type))
|
|
3045
|
+
or pa.types.is_boolean(data_type)
|
|
3046
|
+
or pa.types.is_string(data_type)
|
|
3047
|
+
or pa.types.is_large_string(data_type)
|
|
3048
|
+
or pa.types.is_binary(data_type)
|
|
3049
|
+
or pa.types.is_large_binary(data_type)
|
|
3050
|
+
or pa.types.is_timestamp(data_type)
|
|
3051
|
+
or pa.types.is_decimal128(data_type)
|
|
3052
|
+
)
|
|
3053
|
+
if not supported:
|
|
3054
|
+
return False
|
|
3055
|
+
return True
|
|
3056
|
+
|
|
3057
|
+
|
|
3058
|
+
def _resolve_direct_path_target(connection: Any, table: str) -> tuple[str, str]:
|
|
3059
|
+
parts = split_qualified_identifier(table, quote_chars='"', allow_bracket_quotes=False)
|
|
3060
|
+
if not parts:
|
|
3061
|
+
msg = "Table name must not be empty"
|
|
3062
|
+
raise SQLSpecError(msg)
|
|
3063
|
+
if len(parts) == 1:
|
|
3064
|
+
return connection.username, parts[0]
|
|
3065
|
+
return ".".join(parts[:-1]), parts[-1]
|
|
3066
|
+
|
|
3067
|
+
|
|
3068
|
+
def _row_has_async_readable(row: Any) -> bool:
|
|
3069
|
+
if isinstance(row, dict):
|
|
3070
|
+
return any(is_async_readable(value) for value in row.values())
|
|
3071
|
+
try:
|
|
3072
|
+
values = row if isinstance(row, (list, tuple)) else tuple(row)
|
|
3073
|
+
except TypeError:
|
|
3074
|
+
values = (row,)
|
|
3075
|
+
return any(is_async_readable(value) for value in values)
|
|
3076
|
+
|
|
3077
|
+
|
|
3078
|
+
def _managed_explain_statement(statement: "SQL", sql: str) -> "str | None":
|
|
3079
|
+
"""Extract a SQLSpec-built Oracle plan request without parsing SQL text.
|
|
3080
|
+
|
|
3081
|
+
``Explain.build()`` marks its SQLGlot command expression. Raw caller SQL has no
|
|
3082
|
+
marker and stays on the ordinary one-statement path. The marked form has one exact
|
|
3083
|
+
generated prefix, so extracting the inner statement is a constant-prefix slice,
|
|
3084
|
+
not a second SQL parse.
|
|
3085
|
+
|
|
3086
|
+
Args:
|
|
3087
|
+
statement: Prepared SQL object.
|
|
3088
|
+
sql: Compiled statement text.
|
|
3089
|
+
|
|
3090
|
+
Returns:
|
|
3091
|
+
The inner statement, or None when SQLSpec does not own the plan flow.
|
|
3092
|
+
|
|
3093
|
+
Raises:
|
|
3094
|
+
SQLSpecError: If a marked statement no longer has SQLSpec's generated shape.
|
|
3095
|
+
"""
|
|
3096
|
+
expression = statement.raw_expression
|
|
3097
|
+
if expression is None or not expression.meta.get(ORACLE_MANAGED_EXPLAIN_META_KEY, False):
|
|
3098
|
+
return None
|
|
3099
|
+
|
|
3100
|
+
if not sql.startswith(ORACLE_EXPLAIN_PREFIX) or len(sql) == len(ORACLE_EXPLAIN_PREFIX):
|
|
3101
|
+
msg = "SQLSpec-managed Oracle EXPLAIN statement lost its generated prefix"
|
|
3102
|
+
raise SQLSpecError(msg)
|
|
3103
|
+
return sql[len(ORACLE_EXPLAIN_PREFIX) :]
|
|
3104
|
+
|
|
3105
|
+
|
|
3106
|
+
def _new_plan_statement_id() -> str:
|
|
3107
|
+
"""Build an identifier that isolates one plan within the session plan table.
|
|
3108
|
+
|
|
3109
|
+
Returns:
|
|
3110
|
+
Identifier of at most ``PLAN_STATEMENT_ID_MAX_LENGTH`` alphanumeric characters.
|
|
3111
|
+
"""
|
|
3112
|
+
suffix_length = PLAN_STATEMENT_ID_MAX_LENGTH - len(PLAN_STATEMENT_ID_PREFIX)
|
|
3113
|
+
return f"{PLAN_STATEMENT_ID_PREFIX}{uuid4().hex[:suffix_length]}"
|
|
3114
|
+
|
|
3115
|
+
|
|
3116
|
+
def _tagged_explain_plan_sql(statement_id: str, explained_sql: str) -> str:
|
|
3117
|
+
"""Rewrite a plan request so its rows can be located and removed again.
|
|
3118
|
+
|
|
3119
|
+
Args:
|
|
3120
|
+
statement_id: Identifier produced by ``_new_plan_statement_id``.
|
|
3121
|
+
explained_sql: Statement whose plan is wanted, with its bind placeholders intact.
|
|
3122
|
+
|
|
3123
|
+
Returns:
|
|
3124
|
+
Plan request tagged with the statement id.
|
|
3125
|
+
"""
|
|
3126
|
+
return f"EXPLAIN PLAN SET STATEMENT_ID = '{statement_id}' FOR {explained_sql}"
|
|
3127
|
+
|
|
3128
|
+
|
|
3129
|
+
def _format_plan_display_sql(xplan_format: str = "TYPICAL") -> str:
|
|
3130
|
+
"""Build a DBMS_XPLAN.DISPLAY query with a validated format string."""
|
|
3131
|
+
if "'" in xplan_format:
|
|
3132
|
+
msg = f"Invalid Oracle XPLAN format string: {xplan_format!r}"
|
|
3133
|
+
raise SQLSpecError(msg)
|
|
3134
|
+
return f"SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY(NULL, :statement_id, '{xplan_format}'))"
|
|
3135
|
+
|
|
3136
|
+
|
|
3137
|
+
def _format_display_cursor_sql(xplan_format: str = "TYPICAL") -> str:
|
|
3138
|
+
"""Build a DBMS_XPLAN.DISPLAY_CURSOR query with a validated format string."""
|
|
3139
|
+
if "'" in xplan_format:
|
|
3140
|
+
msg = f"Invalid Oracle XPLAN format string: {xplan_format!r}"
|
|
3141
|
+
raise SQLSpecError(msg)
|
|
3142
|
+
return f"SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, '{xplan_format}'))"
|
|
3143
|
+
|
|
3144
|
+
|
|
3145
|
+
def _managed_explain_options(statement: "SQL") -> "tuple[bool, str]":
|
|
3146
|
+
"""Extract Oracle display_cursor and xplan_format options from a managed Explain statement."""
|
|
3147
|
+
expression = statement.raw_expression
|
|
3148
|
+
if expression is None:
|
|
3149
|
+
return False, "TYPICAL"
|
|
3150
|
+
display_cursor = bool(expression.meta.get(ORACLE_EXPLAIN_DISPLAY_CURSOR_META_KEY, False))
|
|
3151
|
+
raw_format = expression.meta.get(ORACLE_EXPLAIN_XPLAN_FORMAT_META_KEY)
|
|
3152
|
+
xplan_format = str(raw_format) if isinstance(raw_format, str) and raw_format else "TYPICAL"
|
|
3153
|
+
return display_cursor, xplan_format
|
|
3154
|
+
|
|
3155
|
+
|
|
3156
|
+
def _retry_arrow_without_fetch_lobs(exc: TypeError, fetch_kwargs: "dict[str, object]") -> "dict[str, object] | None":
|
|
3157
|
+
if "fetch_lobs" not in fetch_kwargs or "fetch_lobs" not in str(exc):
|
|
3158
|
+
return None
|
|
3159
|
+
retry_kwargs = dict(fetch_kwargs)
|
|
3160
|
+
retry_kwargs.pop("fetch_lobs", None)
|
|
3161
|
+
return retry_kwargs
|
|
3162
|
+
|
|
3163
|
+
|
|
3164
|
+
def _extract_statement_binds(statement: str) -> "tuple[set[str], int]":
|
|
3165
|
+
"""Extract named bind names (lowercased) and count of positional binds outside quotes and comments."""
|
|
3166
|
+
named_binds: set[str] = set()
|
|
3167
|
+
positional_count = 0
|
|
3168
|
+
n = len(statement)
|
|
3169
|
+
i = 0
|
|
3170
|
+
while i < n:
|
|
3171
|
+
ch = statement[i]
|
|
3172
|
+
if ch == "-" and i + 1 < n and statement[i + 1] == "-":
|
|
3173
|
+
end = statement.find("\n", i + 2)
|
|
3174
|
+
i = n if end == -1 else end + 1
|
|
3175
|
+
continue
|
|
3176
|
+
if ch == "/" and i + 1 < n and statement[i + 1] == "*":
|
|
3177
|
+
end = statement.find("*/", i + 2)
|
|
3178
|
+
i = n if end == -1 else end + 2
|
|
3179
|
+
continue
|
|
3180
|
+
if ch == "'":
|
|
3181
|
+
end = i + 1
|
|
3182
|
+
while end < n:
|
|
3183
|
+
if statement[end] == "'":
|
|
3184
|
+
if end + 1 < n and statement[end + 1] == "'":
|
|
3185
|
+
end += 2
|
|
3186
|
+
continue
|
|
3187
|
+
end += 1
|
|
3188
|
+
break
|
|
3189
|
+
end += 1
|
|
3190
|
+
i = end
|
|
3191
|
+
continue
|
|
3192
|
+
if ch == '"':
|
|
3193
|
+
end = i + 1
|
|
3194
|
+
while end < n:
|
|
3195
|
+
if statement[end] == '"':
|
|
3196
|
+
if end + 1 < n and statement[end + 1] == '"':
|
|
3197
|
+
end += 2
|
|
3198
|
+
continue
|
|
3199
|
+
end += 1
|
|
3200
|
+
break
|
|
3201
|
+
end += 1
|
|
3202
|
+
i = end
|
|
3203
|
+
continue
|
|
3204
|
+
if ch == ":" and (i == 0 or statement[i - 1] != ":"):
|
|
3205
|
+
start = i + 1
|
|
3206
|
+
if start < n and statement[start] != ":":
|
|
3207
|
+
end = start
|
|
3208
|
+
while end < n and (statement[end].isalnum() or statement[end] in {"_", "$", "#"}):
|
|
3209
|
+
end += 1
|
|
3210
|
+
if end > start:
|
|
3211
|
+
token = statement[start:end]
|
|
3212
|
+
if token.isdigit():
|
|
3213
|
+
positional_count += 1
|
|
3214
|
+
else:
|
|
3215
|
+
named_binds.add(token.lower())
|
|
3216
|
+
i = end
|
|
3217
|
+
continue
|
|
3218
|
+
i += 1
|
|
3219
|
+
return named_binds, positional_count
|
|
3220
|
+
|
|
3221
|
+
|
|
3222
|
+
def _slice_script_parameters(statement: str, parameters: Any, pos_offset: int) -> "tuple[Any, int]":
|
|
3223
|
+
"""Filter dictionary binds or slice positional binds for a single statement."""
|
|
3224
|
+
if not parameters:
|
|
3225
|
+
return {}, pos_offset
|
|
3226
|
+
named_binds, pos_count = _extract_statement_binds(statement)
|
|
3227
|
+
if isinstance(parameters, dict):
|
|
3228
|
+
filtered = {k: v for k, v in parameters.items() if str(k).lower() in named_binds}
|
|
3229
|
+
return filtered, pos_offset
|
|
3230
|
+
if isinstance(parameters, (list, tuple)):
|
|
3231
|
+
if pos_count > 0:
|
|
3232
|
+
sliced = list(parameters[pos_offset : pos_offset + pos_count])
|
|
3233
|
+
return sliced, pos_offset + pos_count
|
|
3234
|
+
return [], pos_offset
|
|
3235
|
+
return parameters, pos_offset
|
|
3236
|
+
|
|
3237
|
+
|
|
3238
|
+
def _fetch_dataframe_batches(
|
|
3239
|
+
connection: Any,
|
|
3240
|
+
sql: str,
|
|
3241
|
+
parameters: "StatementParameters | None",
|
|
3242
|
+
batch_size: int | None,
|
|
3243
|
+
driver_features: Any,
|
|
3244
|
+
arrow_schema: "ArrowSchema | None",
|
|
3245
|
+
) -> Any:
|
|
3246
|
+
"""Invoke Oracle fetch_df_batches with fetch_lobs fallback and error mapping."""
|
|
3247
|
+
params = parameters if parameters is not None else []
|
|
3248
|
+
fetch_kwargs = build_arrow_fetch_kwargs(driver_features, arrow_schema=arrow_schema)
|
|
3249
|
+
try:
|
|
3250
|
+
try:
|
|
3251
|
+
return connection.fetch_df_batches(
|
|
3252
|
+
statement=sql, parameters=params, size=batch_size or 1000, **fetch_kwargs
|
|
3253
|
+
)
|
|
3254
|
+
except TypeError as exc:
|
|
3255
|
+
retry_kwargs = _retry_arrow_without_fetch_lobs(exc, fetch_kwargs)
|
|
3256
|
+
if retry_kwargs is None:
|
|
3257
|
+
raise
|
|
3258
|
+
return connection.fetch_df_batches(
|
|
3259
|
+
statement=sql, parameters=params, size=batch_size or 1000, **retry_kwargs
|
|
3260
|
+
)
|
|
3261
|
+
except OracleError as exc:
|
|
3262
|
+
raise with_cause(create_mapped_exception(exc), exc) from exc
|
|
3263
|
+
|
|
3264
|
+
|
|
3265
|
+
def _coerce_oracle_arrow_batch_table(oracle_df: Any, driver_features: Any, arrow_schema: "ArrowSchema | None") -> Any:
|
|
3266
|
+
"""Convert one Oracle DataFrame batch to an Arrow table with normalized columns."""
|
|
3267
|
+
batch_table = coerce_oracle_df_to_arrow_table(oracle_df, import_pyarrow())
|
|
3268
|
+
column_names = normalize_column_names(batch_table.column_names, driver_features)
|
|
3269
|
+
if column_names != batch_table.column_names:
|
|
3270
|
+
batch_table = batch_table.rename_columns(column_names).replace_schema_metadata(batch_table.schema.metadata)
|
|
3271
|
+
if arrow_schema is not None:
|
|
3272
|
+
batch_table = batch_table.cast(arrow_schema)
|
|
3273
|
+
return batch_table
|