interloper-sql 0.1.0__tar.gz → 0.2.0rc1__tar.gz

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.
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: interloper-sql
3
- Version: 0.1.0
3
+ Version: 0.2.0rc1
4
4
  Summary: Interloper SQLAlchemy IO managers
5
5
  Author: Guillaume Onfroy
6
6
  Author-email: Guillaume Onfroy <guillaume@digitlcloud.com>
7
7
  Requires-Dist: sqlalchemy>=2.0
8
- Requires-Dist: interloper
8
+ Requires-Dist: interloper-core
9
9
  Requires-Dist: pymysql>=1.1 ; extra == 'mysql'
10
10
  Requires-Dist: psycopg2-binary>=2.9 ; extra == 'postgres'
11
11
  Requires-Python: >=3.10
@@ -3,14 +3,14 @@
3
3
  # ###############
4
4
  [project]
5
5
  name = "interloper-sql"
6
- version = "0.1.0"
6
+ version = "0.2.0-rc.1"
7
7
  description = "Interloper SQLAlchemy IO managers"
8
8
  readme = "README.md"
9
9
  authors = [{ name = "Guillaume Onfroy", email = "guillaume@digitlcloud.com" }]
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
12
  "sqlalchemy>=2.0",
13
- "interloper",
13
+ "interloper-core",
14
14
  ]
15
15
 
16
16
  [project.optional-dependencies]
@@ -22,7 +22,7 @@ requires = ["uv_build>=0.9.5,<0.10.0"]
22
22
  build-backend = "uv_build"
23
23
 
24
24
  [tool.uv.sources]
25
- interloper = { workspace = true }
25
+ interloper-core = { workspace = true }
26
26
 
27
27
  # ###############
28
28
  # RUFF
@@ -1,3 +1,5 @@
1
+ """Interloper SQL integration for relational database IO via SQLAlchemy."""
2
+
1
3
  from interloper_sql.io import MySQLIO, PostgresIO, SqlIO, SqliteIO
2
4
 
3
5
  __all__ = [
@@ -242,6 +242,35 @@ class SqlIO(DatabaseIO):
242
242
  result = conn.execute(sa_table.select().where(sa_table.c[column] == value))
243
243
  return [dict(row._mapping) for row in result]
244
244
 
245
+ # ------------------------------------------------------------------
246
+ # Introspection
247
+ # ------------------------------------------------------------------
248
+
249
+ def _count_by_partition(
250
+ self, table: str, schema: str | None, column: str,
251
+ ) -> dict[str, int]:
252
+ """Return row counts grouped by partition column via SQL ``GROUP BY``.
253
+
254
+ Args:
255
+ table: Target table name
256
+ schema: Database schema
257
+ column: Column to group by
258
+
259
+ Returns:
260
+ Mapping from partition value (as string) to row count.
261
+
262
+ Raises:
263
+ TableNotFoundError: If the table does not exist.
264
+ """
265
+ from sqlalchemy import func
266
+
267
+ sa_table = self._require_table(table, schema)
268
+ col = sa_table.c[column]
269
+ stmt = sa_table.select().with_only_columns(col, func.count()).group_by(col)
270
+ with self._engine.connect() as conn:
271
+ result = conn.execute(stmt)
272
+ return {str(row[0]): row[1] for row in result}
273
+
245
274
  # ------------------------------------------------------------------
246
275
  # Lifecycle
247
276
  # ------------------------------------------------------------------