Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 91327b7

Browse files
author
Matthias Ekundayo
committed
removed args
1 parent 33acff9 commit 91327b7

File tree

5 files changed

+31
-53
lines changed

5 files changed

+31
-53
lines changed

data_diff/databases/connect.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ def connect_to_uri(db_uri: str, thread_count: Optional[int] = 1) -> Database:
143143
assert not dsn.port
144144
kw["user"] = dsn.user
145145
kw["password"] = dsn.password
146+
147+
# if scheme == "presto":
148+
# kw["user"] = dsn.user
149+
# # kw["password"] = dsn.password
150+
# kw["host"] = dsn.host
151+
# kw["port"] = dsn.port
152+
# # kw["catalog"] = dsn.catalog
153+
# # kw["schema"] = dsn.schema
154+
146155
else:
147156
kw["host"] = dsn.host
148157
kw["port"] = dsn.port

data_diff/databases/presto.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import re
2-
32
from .database_types import *
43
from .base import Database, import_helper, _query_conn
54
from .base import (
@@ -35,28 +34,26 @@ class Presto(Database):
3534
}
3635
ROUNDS_ON_PREC_LOSS = True
3736

38-
def __init__(self, host, port, user, password, *, catalog, schema=None, **kw):
37+
def __init__(self, **kw):
3938
prestodb = import_presto()
40-
self.args = dict(
41-
host=host, port=port, user=user, catalog=catalog, schema=schema, **kw
42-
) # include port if specified
43-
44-
if (
45-
"cert" in self.args
46-
): # cert used after connection to verify session, but keyword is not valid so remove from connection params
47-
self.args.pop("cert")
4839

49-
if "auth" in kw and kw.get("auth") == "basic": # if auth=basic, add basic authenticator for Presto
50-
self.args["auth"] = prestodb.auth.BasicAuthentication(user, password)
40+
if kw.get("schema"):
41+
self.default_schema = kw.get("schema")
5142

52-
if schema: # if schema was specified in URI, override default
53-
self.default_schema = schema
54-
self._conn = prestodb.dbapi.connect(**self.args)
55-
# self._conn = prestodb.dbapi.connect(**kw)
43+
if (
44+
"password" in kw and "auth" in kw and kw.get("auth") == "basic"
45+
): # if auth=basic, add basic authenticator for Presto
46+
kw["auth"] = prestodb.auth.BasicAuthentication(kw.get("user"), kw.get("password"))
47+
kw.pop("password")
5648

5749
if "cert" in kw: # if a certificate was specified in URI, verify session with cert
58-
self._conn._http_session.verify = kw.get("cert")
50+
cert = kw.get("cert")
51+
kw.pop("cert")
52+
self._conn = prestodb.dbapi.connect(**kw)
53+
self._conn._http_session.verify = cert
5954

55+
else:
56+
self._conn = prestodb.dbapi.connect(**kw)
6057

6158
def quote(self, s: str):
6259
return f'"{s}"'

data_diff/databases/snowflake.py

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def import_snowflake():
99
import snowflake.connector
1010
from cryptography.hazmat.primitives import serialization
1111
from cryptography.hazmat.backends import default_backend
12-
12+
1313
return snowflake, serialization, default_backend
1414

1515

@@ -27,18 +27,7 @@ class Snowflake(Database):
2727
}
2828
ROUNDS_ON_PREC_LOSS = False
2929

30-
def __init__(self,
31-
account: str,
32-
user: str,
33-
*,
34-
warehouse: str,
35-
schema: str,
36-
database: str,
37-
role: str = None,
38-
_port: int = None,
39-
password: str = None, # default to None incase ssh key is used
40-
**kw,
41-
):
30+
def __init__(self, *, schema: str, **kw):
4231
snowflake, serialization, default_backend = import_snowflake()
4332
logging.getLogger("snowflake.connector").setLevel(logging.WARNING)
4433

@@ -49,7 +38,7 @@ def __init__(self,
4938

5039
assert '"' not in schema, "Schema name should not contain quotes!"
5140
if (
52-
not password and "key" in kw
41+
"password" not in kw and "key" in kw
5342
): # if private keys are used instead of password for Snowflake connection, read in key from path specified and pass as "private_key" to connector.
5443
with open(kw.get("key"), "rb") as key:
5544
p_key = serialization.load_pem_private_key(key.read(), password=None, backend=default_backend())
@@ -59,27 +48,10 @@ def __init__(self,
5948
format=serialization.PrivateFormat.PKCS8,
6049
encryption_algorithm=serialization.NoEncryption(),
6150
)
62-
self._conn = snowflake.connector.connect(
63-
user=user,
64-
private_key=pkb, # replaces password
65-
account=account,
66-
role=role,
67-
database=database,
68-
warehouse=warehouse,
69-
schema=f'"{schema}"',
70-
**kw,
71-
)
51+
self._conn = snowflake.connector.connect(private_key=pkb, schema=f'"{schema}"', **kw) # replaces password
52+
7253
else: # otherwise use password for connection
73-
self._conn = snowflake.connector.connect(
74-
user=user,
75-
password=password,
76-
account=account,
77-
role=role,
78-
database=database,
79-
warehouse=warehouse,
80-
schema=f'"{schema}"',
81-
**kw,
82-
)
54+
self._conn = snowflake.connector.connect(schema=f'"{schema}"', **kw)
8355

8456
self.default_schema = schema
8557

docs/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ sphinx_markdown_tables
44
sphinx-copybutton
55
sphinx-rtd-theme
66
recommonmark
7-
cryptography
87

98
# Requirements. TODO Use poetry instead of this redundant list
109
data_diff

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ preql = "^0.2.17"
3737
mysql-connector-python = "*"
3838
databricks-sql-connector = "*"
3939
snowflake-connector-python = "*"
40+
cryptography = "*"
4041
trino = "^0.314.0"
4142
psycopg2 = "*"
4243
presto-python-client = "*"
@@ -46,7 +47,7 @@ presto-python-client = "*"
4647
preql = ["preql"]
4748
mysql = ["mysql-connector-python"]
4849
postgresql = ["psycopg2"]
49-
snowflake = ["snowflake-connector-python"]
50+
snowflake = ["snowflake-connector-python", "cryptography"]
5051
presto = ["presto-python-client"]
5152
oracle = ["cx_Oracle"]
5253
databricks = ["databricks-sql-connector"]

0 commit comments

Comments
 (0)