Skip to content

Commit

Permalink
0.2.2-alpha.3: add mssql instance name
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiaoying committed Nov 5, 2021
1 parent a10710d commit bd66558
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connectorx-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Weiyuan Wu <youngw@sfu.ca>"]
edition = "2018"
name = "connectorx-python"
version = "0.2.2-alpha.2"
version = "0.2.2-alpha.3"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion connectorx-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ license = "MIT"
maintainers = ["Weiyuan Wu <youngw@sfu.ca>"]
name = "connectorx"
readme = "README.md" # Markdown files are supported
version = "0.2.2-alpha.2"
version = "0.2.2-alpha.3"

[tool.poetry.dependencies]
dask = {version = "^2021", optional = true, extras = ["dataframe"]}
Expand Down
17 changes: 3 additions & 14 deletions connectorx-python/src/source_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::errors::{ConnectorXPythonError, Result};
use anyhow::anyhow;
use connectorx::{
sources::{
mssql::{FloatN, IntN, MsSQLTypeSystem},
mssql::{mssql_config, FloatN, IntN, MsSQLTypeSystem},
mysql::{MySQLSourceError, MySQLTypeSystem},
oracle::OracleDialect,
postgres::{rewrite_tls_args, PostgresTypeSystem},
Expand Down Expand Up @@ -235,21 +235,10 @@ fn mysql_get_partition_range(conn: &Url, query: &str, col: &str) -> (i64, i64) {

#[throws(ConnectorXPythonError)]
fn mssql_get_partition_range(conn: &Url, query: &str, col: &str) -> (i64, i64) {
use tiberius::{AuthMethod, Client, Config, EncryptionLevel};
use tiberius::Client;
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
let mut config = Config::new();

config.host(decode(conn.host_str().unwrap_or("localhost"))?.into_owned());
config.port(conn.port().unwrap_or(1433));
config.authentication(AuthMethod::sql_server(
decode(conn.username())?.into_owned(),
decode(conn.password().unwrap_or(""))?.into_owned(),
));

config.database(&conn.path()[1..]); // remove the leading "/"
config.encryption(EncryptionLevel::NotSupported);

let config = mssql_config(conn)?;
let tcp = rt.block_on(TcpStream::connect(config.get_addr()))?;
tcp.set_nodelay(true)?;

Expand Down
2 changes: 1 addition & 1 deletion connectorx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
name = "connectorx"
readme = "../README.md"
repository = "https://github.com/sfu-db/connector-x"
version = "0.2.2-alpha.2"
version = "0.2.2-alpha.3"

[dependencies]
anyhow = "1"
Expand Down
42 changes: 28 additions & 14 deletions connectorx/src/sources/mssql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,38 @@ pub struct MsSQLSource {
buf_size: usize,
}

#[throws(MsSQLSourceError)]
pub fn mssql_config(url: &Url) -> Config {
let mut config = Config::new();

let host = decode(url.host_str().unwrap_or("localhost"))?.into_owned();
let hosts: Vec<&str> = host.split('\\').collect();
match hosts.len() {
1 => config.host(host),
2 => {
// SQL Server support instance name: `server\instance:port`
config.host(hosts[0]);
config.instance_name(hosts[1]);
}
_ => throw!(anyhow!("MsSQL hostname parse error: {}", host)),
}
config.port(url.port().unwrap_or(1433));
// remove the leading "/"
config.database(&url.path()[1..]);
// Using SQL Server authentication.
config.authentication(AuthMethod::sql_server(
decode(url.username())?.to_owned(),
decode(url.password().unwrap_or(""))?.to_owned(),
));
config.encryption(EncryptionLevel::NotSupported);
config
}

impl MsSQLSource {
#[throws(MsSQLSourceError)]
pub fn new(rt: Arc<Runtime>, conn: &str, nconn: usize) -> Self {
let mut config = Config::new();
let url = Url::parse(conn)?;

config.host(decode(url.host_str().unwrap_or("localhost"))?.into_owned());
config.port(url.port().unwrap_or(1433));

// Using SQL Server authentication.
config.authentication(AuthMethod::sql_server(
decode(url.username())?.to_owned(),
decode(url.password().unwrap_or(""))?.to_owned(),
));

config.database(&url.path()[1..]); // remove the leading "/"
config.encryption(EncryptionLevel::NotSupported);

let config = mssql_config(&url)?;
let manager = bb8_tiberius::ConnectionManager::new(config);
let pool = rt.block_on(Pool::builder().max_size(nconn as u32).build(manager))?;

Expand Down

2 comments on commit bd66558

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectorX TPC-H Scale@1 Benchmarks

Benchmark suite Current: bd66558 Previous: a10710d Ratio
connectorx/tests/benchmarks.py::bench_mysql 0.059639656855164466 iter/sec (stddev: 0.6536601398689655) 0.0654021976683567 iter/sec (stddev: 0.6670761761618038) 1.10
connectorx/tests/benchmarks.py::bench_postgres 0.0715655439391161 iter/sec (stddev: 2.8564064649330674) 0.07456568481245497 iter/sec (stddev: 2.155062630146363) 1.04

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectorX TPC-H Scale@1 Benchmarks

Benchmark suite Current: bd66558 Previous: a10710d Ratio
connectorx/tests/benchmarks.py::bench_mysql 0.06078909818294486 iter/sec (stddev: 0.11850730366963984) 0.0654021976683567 iter/sec (stddev: 0.6670761761618038) 1.08
connectorx/tests/benchmarks.py::bench_postgres 0.056167765383764584 iter/sec (stddev: 3.117850560349933) 0.07456568481245497 iter/sec (stddev: 2.155062630146363) 1.33

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.