mtsql 1.12.24__py3-none-any.whl → 1.12.26__py3-none-any.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.
- mt/sql/base.py +6 -1
- mt/sql/psql.py +15 -10
- mt/sql/version.py +1 -1
- {mtsql-1.12.24.dist-info → mtsql-1.12.26.dist-info}/METADATA +1 -1
- {mtsql-1.12.24.dist-info → mtsql-1.12.26.dist-info}/RECORD +8 -8
- {mtsql-1.12.24.dist-info → mtsql-1.12.26.dist-info}/WHEEL +0 -0
- {mtsql-1.12.24.dist-info → mtsql-1.12.26.dist-info}/licenses/LICENSE +0 -0
- {mtsql-1.12.24.dist-info → mtsql-1.12.26.dist-info}/top_level.txt +0 -0
mt/sql/base.py
CHANGED
|
@@ -6,6 +6,7 @@ import sqlalchemy as sa
|
|
|
6
6
|
import sqlalchemy.exc as se
|
|
7
7
|
import psycopg as ps
|
|
8
8
|
import ssl
|
|
9
|
+
import time
|
|
9
10
|
|
|
10
11
|
from mt import tp, logg, pd, ctx, halo
|
|
11
12
|
|
|
@@ -77,12 +78,16 @@ def run_func(
|
|
|
77
78
|
se.PendingRollbackError,
|
|
78
79
|
ssl.SSLEOFError,
|
|
79
80
|
ssl.SSLZeroReturnError,
|
|
80
|
-
):
|
|
81
|
+
) as e:
|
|
81
82
|
if x < nb_trials - 1:
|
|
82
83
|
if logger:
|
|
83
84
|
msg = f"Ignored an exception raised by failed attempt {x+1}/{nb_trials} to execute `{func.__module__}.{func.__name__}()`"
|
|
84
85
|
with logger.scoped_warn(msg):
|
|
85
86
|
logger.warn_last_exception()
|
|
87
|
+
if isinstance(e, se.PendingRollbackError):
|
|
88
|
+
time.sleep(60)
|
|
89
|
+
elif isinstance(e, ssl.SSLEOFError):
|
|
90
|
+
time.sleep(3)
|
|
86
91
|
else:
|
|
87
92
|
msg = f"Attempted {nb_trials} times to execute `{func.__module__}.{func.__name__}` but failed."
|
|
88
93
|
logg.error(msg, logger=logger)
|
mt/sql/psql.py
CHANGED
|
@@ -640,7 +640,7 @@ def rename_table(
|
|
|
640
640
|
nb_trials: int = 3,
|
|
641
641
|
logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
|
|
642
642
|
):
|
|
643
|
-
"""Renames a table of a schema.
|
|
643
|
+
"""Renames a (foreign) table of a schema.
|
|
644
644
|
|
|
645
645
|
Parameters
|
|
646
646
|
----------
|
|
@@ -653,7 +653,7 @@ def rename_table(
|
|
|
653
653
|
schema : str or None
|
|
654
654
|
a valid schema name returned from `list_schemas()`
|
|
655
655
|
foreign : bool
|
|
656
|
-
whether the table to rename
|
|
656
|
+
whether the table to rename is a foreign table
|
|
657
657
|
nb_trials : int
|
|
658
658
|
number of query trials
|
|
659
659
|
logger : mt.logg.IndentedLoggerAdapter, optional
|
|
@@ -717,21 +717,24 @@ def drop_table(
|
|
|
717
717
|
table_name,
|
|
718
718
|
engine,
|
|
719
719
|
schema: tp.Optional[str] = None,
|
|
720
|
-
|
|
720
|
+
foreign: bool = False,
|
|
721
|
+
restrict: bool = True,
|
|
721
722
|
nb_trials: int = 3,
|
|
722
723
|
logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
|
|
723
724
|
):
|
|
724
|
-
"""Drops a table if it exists, with restrict or cascade options.
|
|
725
|
+
"""Drops a (foreign) table if it exists, with restrict or cascade options.
|
|
725
726
|
|
|
726
727
|
Parameters
|
|
727
728
|
----------
|
|
728
729
|
table_name : str
|
|
729
730
|
table name
|
|
730
|
-
engine: sqlalchemy.engine.Engine
|
|
731
|
+
engine : sqlalchemy.engine.Engine
|
|
731
732
|
an sqlalchemy connection engine created by function `create_engine()`
|
|
732
|
-
schema: str or None
|
|
733
|
+
schema : str or None
|
|
733
734
|
a valid schema name returned from `list_schemas()`
|
|
734
|
-
|
|
735
|
+
foreign : bool
|
|
736
|
+
whether the table to drop is a foreign table
|
|
737
|
+
restrict : bool
|
|
735
738
|
If True, refuses to drop table if there is any object depending on it. Otherwise it is the
|
|
736
739
|
'cascade' option which allows you to remove those dependent objects together with the table
|
|
737
740
|
automatically.
|
|
@@ -745,9 +748,11 @@ def drop_table(
|
|
|
745
748
|
whatever exec_sql() returns
|
|
746
749
|
"""
|
|
747
750
|
frame_sql_str = frame_sql(table_name, schema=schema)
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
+
if foreign:
|
|
752
|
+
query_str = "DROP FOREIGN TABLE "
|
|
753
|
+
else:
|
|
754
|
+
query_str = "DROP TABLE "
|
|
755
|
+
query_str += f'IF EXISTS {frame_sql_str} {"RESTRICT" if restrict else "CASCADE"};'
|
|
751
756
|
return exec_sql(query_str, engine, nb_trials=nb_trials, logger=logger)
|
|
752
757
|
|
|
753
758
|
|
mt/sql/version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mtsql
|
|
3
|
-
Version: 1.12.
|
|
3
|
+
Version: 1.12.26
|
|
4
4
|
Summary: Extra Python modules to deal with the interaction between pandas dataframes and remote SQL servers, for Minh-Tri Pham
|
|
5
5
|
Home-page: https://github.com/inteplus/mtsql
|
|
6
6
|
Author: ['Minh-Tri Pham']
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
|
|
2
|
-
mt/sql/base.py,sha256=
|
|
2
|
+
mt/sql/base.py,sha256=KnvqVa97Iw69-t1azX_ObjEXiZn3eMsKvTQn-yV7iPM,13702
|
|
3
3
|
mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
|
|
4
|
-
mt/sql/psql.py,sha256=
|
|
4
|
+
mt/sql/psql.py,sha256=8gWsF6ZobwkAxHsfecF95Em_cAlMitHHdQzinZLCi6s,67110
|
|
5
5
|
mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
|
|
6
|
-
mt/sql/version.py,sha256=
|
|
6
|
+
mt/sql/version.py,sha256=7H6Be4Lf31DCXBrPsrhgH2aZx8WIvPlTMAIIKab7Vik,208
|
|
7
7
|
mt/sql/redshift/__init__.py,sha256=S-eRxJWcrvncF7LZXuulCdPV-UERu9eiw6uyDb5aGsM,443
|
|
8
8
|
mt/sql/redshift/commands.py,sha256=xhGUBf3bL66EYdZI5HCUtOx-XqPCnXT_P-LnhPgtzrY,40193
|
|
9
9
|
mt/sql/redshift/ddl.py,sha256=eUcZj9oIajiE1wKKBAP-V64gYJ7cVnSAt8dLFfluOJA,9777
|
|
10
10
|
mt/sql/redshift/dialect.py,sha256=-0JjJubZZHRw0abhl6H6rKWaUE9pKtGwAuX-62T0e_c,53399
|
|
11
11
|
mt/sql/redshift/main.py,sha256=H8_5sjtJ7dzWoCMXzPNjYhrMQ18eLUQ9xg-aYl5QeTc,17104
|
|
12
12
|
mt/sql/redshift/redshift-ca-bundle.crt,sha256=532qYkOpQOstFE0mdXE1GVtL3v00XDKgZNTr6gK5-KE,8621
|
|
13
|
-
mtsql-1.12.
|
|
14
|
-
mtsql-1.12.
|
|
15
|
-
mtsql-1.12.
|
|
16
|
-
mtsql-1.12.
|
|
17
|
-
mtsql-1.12.
|
|
13
|
+
mtsql-1.12.26.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
|
|
14
|
+
mtsql-1.12.26.dist-info/METADATA,sha256=D4MnXyMYGf2Oei5QSgCte55ETTzk_uPxC8mw70R1PTA,740
|
|
15
|
+
mtsql-1.12.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
+
mtsql-1.12.26.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
|
|
17
|
+
mtsql-1.12.26.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|