mtsql 1.12.33__py3-none-any.whl → 1.12.35__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 +48 -14
- mt/sql/version.py +1 -1
- {mtsql-1.12.33.dist-info → mtsql-1.12.35.dist-info}/METADATA +1 -1
- {mtsql-1.12.33.dist-info → mtsql-1.12.35.dist-info}/RECORD +7 -7
- {mtsql-1.12.33.dist-info → mtsql-1.12.35.dist-info}/WHEEL +0 -0
- {mtsql-1.12.33.dist-info → mtsql-1.12.35.dist-info}/licenses/LICENSE +0 -0
- {mtsql-1.12.33.dist-info → mtsql-1.12.35.dist-info}/top_level.txt +0 -0
mt/sql/base.py
CHANGED
|
@@ -299,6 +299,36 @@ def exec_sql(
|
|
|
299
299
|
)
|
|
300
300
|
|
|
301
301
|
|
|
302
|
+
# ----- functions dealing with id tuples -----
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def id_tuple2sql(a_ids: list, int_type: str = "int") -> str:
|
|
306
|
+
"""Converts an id tuple list into an SQL string representing the tuple list.
|
|
307
|
+
|
|
308
|
+
Parameters
|
|
309
|
+
----------
|
|
310
|
+
a_ids : list
|
|
311
|
+
list of fixed-sized arrays of ids
|
|
312
|
+
int_type : str
|
|
313
|
+
an SQL string representing the int type
|
|
314
|
+
|
|
315
|
+
Returns
|
|
316
|
+
-------
|
|
317
|
+
str
|
|
318
|
+
SQL string representing the tuple list
|
|
319
|
+
"""
|
|
320
|
+
n = len(a_ids)
|
|
321
|
+
if n < 2:
|
|
322
|
+
raise ValueError("a_ids must have at least 2 elements")
|
|
323
|
+
|
|
324
|
+
if int_type == "bigint":
|
|
325
|
+
values = ",".join((str(x) for x in a_ids))
|
|
326
|
+
else:
|
|
327
|
+
values = ",".join((str(int(x)) for x in a_ids))
|
|
328
|
+
|
|
329
|
+
return f"({values})"
|
|
330
|
+
|
|
331
|
+
|
|
302
332
|
# ----- functions navigating the database -----
|
|
303
333
|
|
|
304
334
|
|
|
@@ -659,7 +689,7 @@ def find_common_ids(
|
|
|
659
689
|
|
|
660
690
|
def find_common_id_tuples(
|
|
661
691
|
la_ids: tp.List[tp.List[int]],
|
|
662
|
-
|
|
692
|
+
l_idCols: tp.List[str],
|
|
663
693
|
frame_name: str,
|
|
664
694
|
engine: sa.engine.Engine,
|
|
665
695
|
schema: tp.Optional[str] = None,
|
|
@@ -672,7 +702,7 @@ def find_common_id_tuples(
|
|
|
672
702
|
----------
|
|
673
703
|
la_ids : list of list of int
|
|
674
704
|
list of id tuples to be checked
|
|
675
|
-
|
|
705
|
+
l_idCols : list of str
|
|
676
706
|
name of the id columns in the frame
|
|
677
707
|
frame_name : str
|
|
678
708
|
name of the frame to be checked against
|
|
@@ -680,7 +710,7 @@ def find_common_id_tuples(
|
|
|
680
710
|
connection engine to the server
|
|
681
711
|
schema : str, optional
|
|
682
712
|
schema of the frame. If None, the default schema is used.
|
|
683
|
-
|
|
713
|
+
l_idCols : list of str
|
|
684
714
|
name of the id column in the frame
|
|
685
715
|
int_type : str
|
|
686
716
|
an SQL string representing the int type of the id column
|
|
@@ -689,26 +719,30 @@ def find_common_id_tuples(
|
|
|
689
719
|
|
|
690
720
|
Returns
|
|
691
721
|
-------
|
|
692
|
-
list of int
|
|
693
|
-
list of
|
|
722
|
+
list of list of int
|
|
723
|
+
list of cpommon id tuples
|
|
694
724
|
"""
|
|
695
725
|
|
|
696
726
|
with conn_ctx(engine) as conn:
|
|
697
|
-
temp_table =
|
|
727
|
+
temp_table = create_temp_id_tuple_table(
|
|
728
|
+
la_ids, conn, int_type=int_type, logger=logger
|
|
729
|
+
)
|
|
698
730
|
|
|
699
731
|
full_frame_name = frame_sql(frame_name, schema=schema)
|
|
700
732
|
|
|
701
|
-
sql =
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
""
|
|
733
|
+
sql = "SELECT t.id1"
|
|
734
|
+
for i in range(1, len(l_idCols)):
|
|
735
|
+
sql += f", t.id{i+1}"
|
|
736
|
+
sql += f" FROM {temp_table} AS t INNER JOIN {full_frame_name} AS f ON "
|
|
737
|
+
sql += " AND ".join(
|
|
738
|
+
(f"t.id{i+1} = f.{l_idCols[i]}" for i in range(len(l_idCols)))
|
|
739
|
+
)
|
|
740
|
+
sql += ";"
|
|
706
741
|
|
|
707
742
|
df_common = read_sql(sql, conn, index_col=None, logger=logger)
|
|
743
|
+
la_commonIds = df_common.to_numpy()
|
|
708
744
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return l_commonIds
|
|
745
|
+
return la_commonIds
|
|
712
746
|
|
|
713
747
|
|
|
714
748
|
def find_common_str_ids(
|
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.35
|
|
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=zbWafsfTW6mw8yH1Ox3_j9virsSt3ZGO6-dp0HUqjTA,24787
|
|
3
3
|
mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
|
|
4
4
|
mt/sql/psql.py,sha256=U8XEyg4rQYr5gm8KohRWrpCNJKl5WC1yxJMBkkm1k_A,68125
|
|
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=l6eatYcFZJwHDnQ4NVgwoM_k0RqJb1HHDVUPp9Jer68,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.35.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
|
|
14
|
+
mtsql-1.12.35.dist-info/METADATA,sha256=IMATsEFAIbflVvIYBi9yNq93vfvXpGZUbgz7k_FIx6Q,736
|
|
15
|
+
mtsql-1.12.35.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
16
|
+
mtsql-1.12.35.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
|
|
17
|
+
mtsql-1.12.35.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|