MsSQL Performance and Limitations
mainConnectorX provides significant performance improvements over Pandas for MsSQL, using approximately 3x less memory and 14x less time.
Limitation: Modin does not support read_sql on MsSQL.
repository·main·Indexed 25 days ago
https://github.com/sfu-db/connector-xA high-performance data connector written in Rust designed to load data from various databases into Python dataframes (Pandas, Polars, etc.) and Arrow formats. It supports parallel data downloading via partitioning, federated queries across multiple databases, and streaming via Arrow RecordBatches. Supported backends include PostgreSQL, MySQL, SQLite, MSSQL, Oracle, BigQuery, DuckDB, and Redshift.
ConnectorX provides significant performance improvements over Pandas for MsSQL, using approximately 3x less memory and 14x less time.
Limitation: Modin does not support read_sql on MsSQL.
ConnectorX supports high-performance data retrieval from the following databases:
Each database has specific configuration requirements and type conversion behaviors between database types and Pandas types.
To view detailed Rust logs while using ConnectorX in Python, set the RUST_LOG environment variable before importing connectorx. You can specify log levels for connectorx and connectorx_python.
import os
os.environ["RUST_LOG"]="connectorx=debug,connectorx_python=debug"
import connectorx as cx
df = cx.read_sql(conn, query)To build ConnectorX from source, follow these steps:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shjust: cargo install justPoetry: pip3 install poetrygit clone https://github.com/sfu-db/connector-x.git.github/workflows/release.yml for the latest version).rustup install {version}
rustup override set {version}.github/workflows/release.yml file for the specific dependencies required for your operating system.just bootstrap-pythonjust build-python-wheelOPENSSL_NO_VENDOR=1 during compilation.pyenv, you must install Python with shared libraries enabled using:
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install {version}git clone https://github.com/sfu-db/connector-x.git
rustup install {version}
rustup override set {version}
just bootstrap-python
just build-python-wheelscript/benchmarks/tpch-reshift.sql script to update credentials and optionally change the TPC-H data size in the S3 from string. Then run the script using psql.To generate TPC-H benchmark data, compile the tpch-kit and use dbgen. You can generate all tables or target specific tables like LINEITEM using the -T option.
# 1. Download and compile TPC-H toolkit
git clone https://github.com/gregrahn/tpch-kit.git
cd tpch-kit/dbgen && make MACHINE=LINUX DATABASE=POSTGRESQL
# 2. Generate data (Scale factor 10)
# Generate all tables
./dbgen -s 10
# Alternatively, only generate LINEITEM table
./dbgen -s 10 -T LTo read data from MsSQL, use the cx.read_sql function with a connection URI. Note that for MsSQL, you do not need to specify a protocol in the URI.
Important: If your password contains special characters, you must sanitize it using urllib.parse.quote_plus to ensure the connection string is valid.
username and password in the connection string.To connect to BigQuery, you must provide a path to a Google Cloud Platform authentication JSON file within the connection string. The connection string format is bigquery://<path_to_auth_json>.
Note: BigQuery does not require a protocol specification in the connection string beyond the bigquery:// prefix.
import connectorx as cx
authentication_file_path = '/home/user/path/auth.json' # path to your authentication json file
conn = 'bigquery://' + authentication_file_path # connection token
query = 'SELECT * FROM `database.dataset.table`' # query string
cx.read_sql(conn, query) # read data from BigQueryTo read data from Trino, use the trino+https:// or trino+http:// protocol in your connection string.
Security Notes:
trino+http disables TLS for the connection.?verify=false to your connection string.import connectorx as cx
conn = 'trino+https://username:password@server:port/catalog' # connection token
query = "SELECT * FROM table" # query string
cx.read_sql(conn, query) # read data from TrinoThe partition_on parameter specifies the column used to partition the query. To achieve maximum performance: