mtsql 1.4.202308011012__py3-none-any.whl → 1.5.202308101008__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/psql.py +65 -3
- mt/sql/version.py +5 -5
- {mtsql-1.4.202308011012.dist-info → mtsql-1.5.202308101008.dist-info}/METADATA +1 -1
- mtsql-1.5.202308101008.dist-info/RECORD +11 -0
- mtsql-1.4.202308011012.dist-info/RECORD +0 -11
- {mtsql-1.4.202308011012.dist-info → mtsql-1.5.202308101008.dist-info}/LICENSE +0 -0
- {mtsql-1.4.202308011012.dist-info → mtsql-1.5.202308101008.dist-info}/WHEEL +0 -0
- {mtsql-1.4.202308011012.dist-info → mtsql-1.5.202308101008.dist-info}/top_level.txt +0 -0
mt/sql/psql.py
CHANGED
|
@@ -45,6 +45,7 @@ __all__ = [
|
|
|
45
45
|
"list_primary_columns",
|
|
46
46
|
"rename_column",
|
|
47
47
|
"drop_column",
|
|
48
|
+
"make_primary",
|
|
48
49
|
"comparesync_table",
|
|
49
50
|
"readsync_table",
|
|
50
51
|
"writesync_table",
|
|
@@ -714,6 +715,7 @@ def vacuum_table(
|
|
|
714
715
|
table_name,
|
|
715
716
|
engine,
|
|
716
717
|
schema: tp.Optional[str] = None,
|
|
718
|
+
full: bool = False,
|
|
717
719
|
nb_trials: int = 3,
|
|
718
720
|
logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
|
|
719
721
|
):
|
|
@@ -726,6 +728,8 @@ def vacuum_table(
|
|
|
726
728
|
an sqlalchemy connection engine created by function `create_engine()`
|
|
727
729
|
schema: str or None
|
|
728
730
|
a valid schema name returned from `list_schemas()`
|
|
731
|
+
full : bool
|
|
732
|
+
whether or not to do a full vacuuming
|
|
729
733
|
nb_trials: int
|
|
730
734
|
number of query trials
|
|
731
735
|
logger: mt.logg.IndentedLoggerAdapter, optional
|
|
@@ -737,9 +741,11 @@ def vacuum_table(
|
|
|
737
741
|
"""
|
|
738
742
|
frame_sql_str = frame_sql(table_name, schema=schema)
|
|
739
743
|
engine2 = engine.execution_options(isolation_level="AUTOCOMMIT")
|
|
740
|
-
|
|
741
|
-
f"VACUUM {frame_sql_str};"
|
|
742
|
-
|
|
744
|
+
if full:
|
|
745
|
+
stmt = f"VACUUM FULL {frame_sql_str};"
|
|
746
|
+
else:
|
|
747
|
+
stmt = f"VACUUM {frame_sql_str};"
|
|
748
|
+
return exec_sql(stmt, engine2, nb_trials=nb_trials, logger=logger)
|
|
743
749
|
|
|
744
750
|
|
|
745
751
|
def drop_table(
|
|
@@ -1291,6 +1297,62 @@ def drop_column(
|
|
|
1291
1297
|
exec_sql(query_str, engine, nb_trials=nb_trials, logger=logger)
|
|
1292
1298
|
|
|
1293
1299
|
|
|
1300
|
+
def make_primary(
|
|
1301
|
+
table_name: str,
|
|
1302
|
+
l_columns: list,
|
|
1303
|
+
engine,
|
|
1304
|
+
schema: tp.Optional[str] = None,
|
|
1305
|
+
nb_trials: int = 3,
|
|
1306
|
+
logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
|
|
1307
|
+
):
|
|
1308
|
+
"""Removes all duplicate records from an unindexed table based on a list of keys and then make the keys primary.
|
|
1309
|
+
|
|
1310
|
+
Parameters
|
|
1311
|
+
----------
|
|
1312
|
+
table_name: str
|
|
1313
|
+
a valid table name returned from `list_tables()`
|
|
1314
|
+
l_columns: list,
|
|
1315
|
+
list of columns to be made as primary keys
|
|
1316
|
+
engine: sqlalchemy.engine.Engine
|
|
1317
|
+
an sqlalchemy connection engine created by function `create_engine()`
|
|
1318
|
+
schema: str or None
|
|
1319
|
+
a valid schema name returned from `list_schemas()`
|
|
1320
|
+
nb_trials: int
|
|
1321
|
+
number of query trials
|
|
1322
|
+
logger: mt.logg.IndentedLoggerAdapter, optional
|
|
1323
|
+
logger for debugging
|
|
1324
|
+
"""
|
|
1325
|
+
if not frame_exists(
|
|
1326
|
+
table_name, engine, schema=schema, nb_trials=nb_trials, logger=logger
|
|
1327
|
+
):
|
|
1328
|
+
if schema is None:
|
|
1329
|
+
s = "Table or view with name '{}' does not exists.".format(table_name)
|
|
1330
|
+
else:
|
|
1331
|
+
s = "Table or view with name '{}' from schema '{}' does not exists.".format(
|
|
1332
|
+
table_name, schema
|
|
1333
|
+
)
|
|
1334
|
+
raise ps.ProgrammingError(s)
|
|
1335
|
+
|
|
1336
|
+
frame_sql_str = frame_sql(table_name, schema=schema)
|
|
1337
|
+
column_str = ", ".join(l_columns)
|
|
1338
|
+
msg = f"Deleting duplicates from {frame_sql_str} distinct on {column_str}..."
|
|
1339
|
+
logg.info(msg, logger=logger)
|
|
1340
|
+
query_str = f"""
|
|
1341
|
+
DELETE FROM {frame_sql_str}
|
|
1342
|
+
WHERE ctid IN (
|
|
1343
|
+
SELECT ctid FROM {frame_sql_str}
|
|
1344
|
+
EXCEPT SELECT MIN(ctid) FROM {frame_sql_str} GROUP BY {column_str}
|
|
1345
|
+
);"""
|
|
1346
|
+
exec_sql(query_str, engine, nb_trials=nb_trials, logger=logger)
|
|
1347
|
+
|
|
1348
|
+
msg = f"Making {column_str} of {frame_sql_str} primary..."
|
|
1349
|
+
logg.info(msg, logger=logger)
|
|
1350
|
+
query_str = """
|
|
1351
|
+
ALTER TABLE {frame_sql_str} ADD PRIMARY KEY ({column_str})
|
|
1352
|
+
;"""
|
|
1353
|
+
exec_sql(query_str, engine, nb_trials=nb_trials, logger=logger)
|
|
1354
|
+
|
|
1355
|
+
|
|
1294
1356
|
# ----- functions to synchronise between a local table and a remote table -----
|
|
1295
1357
|
|
|
1296
1358
|
|
mt/sql/version.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
VERSION_YEAR = 2023
|
|
2
2
|
VERSION_MONTH = int('08')
|
|
3
|
-
VERSION_DAY = int('
|
|
3
|
+
VERSION_DAY = int('10')
|
|
4
4
|
VERSION_HOUR = int('10')
|
|
5
|
-
VERSION_MINUTE = int('
|
|
5
|
+
VERSION_MINUTE = int('08')
|
|
6
6
|
MAJOR_VERSION = 1
|
|
7
|
-
MINOR_VERSION =
|
|
8
|
-
PATCH_VERSION =
|
|
9
|
-
version_date = '2023/08/
|
|
7
|
+
MINOR_VERSION = 5
|
|
8
|
+
PATCH_VERSION = 202308101008
|
|
9
|
+
version_date = '2023/08/10 10:08'
|
|
10
10
|
version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
|
|
11
11
|
__all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version_date', 'version']
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mtsql
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.202308101008
|
|
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']
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
|
|
2
|
+
mt/sql/base.py,sha256=sFr7O_Odfsf2AHr9kq3DXGCAFInCKgHSgLJaen507_I,9994
|
|
3
|
+
mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
|
|
4
|
+
mt/sql/psql.py,sha256=RNzne4AObfpaW7yR5qyabtHDMSZY2SAJXxu3NZuJZdA,67411
|
|
5
|
+
mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
|
|
6
|
+
mt/sql/version.py,sha256=M-fHIdX1ra_rUT6GZ_H6J08r0yOTUnG_c1G2Ykue_KA,396
|
|
7
|
+
mtsql-1.5.202308101008.dist-info/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
|
|
8
|
+
mtsql-1.5.202308101008.dist-info/METADATA,sha256=uZ_unsYOO4ALex7eM3Sp2rSeg3rmHL_-QE8V80suk40,597
|
|
9
|
+
mtsql-1.5.202308101008.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
10
|
+
mtsql-1.5.202308101008.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
|
|
11
|
+
mtsql-1.5.202308101008.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
|
|
2
|
-
mt/sql/base.py,sha256=sFr7O_Odfsf2AHr9kq3DXGCAFInCKgHSgLJaen507_I,9994
|
|
3
|
-
mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
|
|
4
|
-
mt/sql/psql.py,sha256=xzxYkgqmtM081cOKRfczbk5bW9Osp4d3S2zq7g-_2n0,65229
|
|
5
|
-
mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
|
|
6
|
-
mt/sql/version.py,sha256=1zg-L-U2I2GzgDToL-mg_6LpqsQdAxue2MRfPsujyq0,396
|
|
7
|
-
mtsql-1.4.202308011012.dist-info/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
|
|
8
|
-
mtsql-1.4.202308011012.dist-info/METADATA,sha256=lCQD-yX7uV5PTUAaaarM-Es4J35FiqZf37xem_0zRIg,597
|
|
9
|
-
mtsql-1.4.202308011012.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
10
|
-
mtsql-1.4.202308011012.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
|
|
11
|
-
mtsql-1.4.202308011012.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|