mtsql 1.12.28__py3-none-any.whl → 1.12.29__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 CHANGED
@@ -29,6 +29,7 @@ __all__ = [
29
29
  "temp_table_find_new_id",
30
30
  "temp_table_drop",
31
31
  "to_temp_table",
32
+ "find_common_ids",
32
33
  ]
33
34
 
34
35
 
@@ -97,7 +98,7 @@ def run_func(
97
98
  raise
98
99
 
99
100
 
100
- def conn_ctx(engine):
101
+ def conn_ctx(engine: sa.engine.Engine):
101
102
  if isinstance(engine, sa.engine.Engine):
102
103
  return engine.begin()
103
104
  return ctx.nullcontext(engine)
@@ -456,10 +457,10 @@ def temp_table_drop(
456
457
 
457
458
  Parameters
458
459
  ----------
459
- id : int or str
460
- table id or table name. An id can be generated by invoking :func:`temp_table_find_new_id`.
461
460
  engine : sqlalchemy.engine.Engine
462
461
  connection engine to the server
462
+ id : int or str
463
+ table id or table name. An id can be generated by invoking :func:`temp_table_find_new_id`.
463
464
  logger : mt.logg.IndentedLoggerAdapter, optional
464
465
  logger for debugging
465
466
  """
@@ -494,3 +495,52 @@ def to_temp_table(df: pd.DataFrame, engine: sa.engine.Engine, **kwds):
494
495
  yield name
495
496
  finally:
496
497
  temp_table_drop(engine, tid)
498
+
499
+
500
+ def find_common_ids(
501
+ l_ids: tp.List[int],
502
+ frame_name: str,
503
+ engine: sa.engine.Engine,
504
+ schema: tp.Optional[str] = None,
505
+ id_col: str = "id",
506
+ logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
507
+ ) -> tp.List[int]:
508
+ """Finds common ids between a list of ids and the ids in a given frame.
509
+
510
+ Parameters
511
+ ----------
512
+ l_ids : list of int
513
+ list of ids to be checked
514
+ frame_name : str
515
+ name of the frame to be checked against
516
+ engine : sqlalchemy.engine.Engine
517
+ connection engine to the server
518
+ schema : str, optional
519
+ schema of the frame. If None, the default schema is used.
520
+ id_col : str
521
+ name of the id column in the frame
522
+ logger : mt.logg.IndentedLoggerAdapter, optional
523
+ logger for debugging
524
+
525
+ Returns
526
+ -------
527
+ list of int
528
+ list of common ids
529
+ """
530
+
531
+ with conn_ctx(engine) as conn:
532
+ temp_table = create_temp_id_table(l_ids, conn, logger=logger)
533
+
534
+ full_frame_name = frame_sql(frame_name, schema=schema)
535
+
536
+ sql = f"""
537
+ SELECT t.id FROM {temp_table} AS t
538
+ INNER JOIN {full_frame_name} AS f
539
+ ON t.id = f.{id_col};
540
+ """
541
+
542
+ df_common = read_sql(sql, conn, index_col=None, logger=logger)
543
+
544
+ l_commonIds = df_common["id"].tolist()
545
+
546
+ return l_commonIds
mt/sql/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 1
2
2
  MINOR_VERSION = 12
3
- PATCH_VERSION = 28
3
+ PATCH_VERSION = 29
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtsql
3
- Version: 1.12.28
3
+ Version: 1.12.29
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=S44nryyeguGNnzdf5ETmKXb9ewbAveiGYhEXVoS7lC8,13732
2
+ mt/sql/base.py,sha256=YM7BnNf1e3WizzH5Amg5xK-L5s0w9Cnl9-90htUqJlg,15096
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=s9O6vZP85_qckYPCAa8UMcuMzYn1fIdaCEIpTTQIoHw,208
6
+ mt/sql/version.py,sha256=I7DJlgmw1b2vkxA_AWJYjd0FWS4W3BxvUIL3cHr587E,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.28.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
- mtsql-1.12.28.dist-info/METADATA,sha256=9Kx_mlxJwgCMqwBM8CO3YYNzzz3fkATwYPW8Fcm7xWg,740
15
- mtsql-1.12.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- mtsql-1.12.28.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
- mtsql-1.12.28.dist-info/RECORD,,
13
+ mtsql-1.12.29.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
+ mtsql-1.12.29.dist-info/METADATA,sha256=dsOJv6kpa6gxLeky_Hsw939aE8bK3F8EMel1g4S1Xyo,740
15
+ mtsql-1.12.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ mtsql-1.12.29.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
+ mtsql-1.12.29.dist-info/RECORD,,