atquery 2.20.2__tar.gz → 2.25.0__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.
- {atquery-2.20.2 → atquery-2.25.0}/PKG-INFO +4 -7
- {atquery-2.20.2 → atquery-2.25.0}/README.md +1 -1
- {atquery-2.20.2 → atquery-2.25.0}/pyproject.toml +5 -6
- {atquery-2.20.2 → atquery-2.25.0}/pyproject.toml.orig +6 -8
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/__init__.py +4 -0
- atquery-2.25.0/src/atquery/_hide.py +110 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/aio/engine.py +9 -1
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/aio/query.py +17 -16
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/api_v2.py +3 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/atquery2.py +17 -16
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/columns.py +0 -1
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/ddl.py +0 -1
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/delta.py +30 -3
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/ecd.py +143 -5
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/routines.py +0 -1
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/schemas.py +0 -1
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/tables.py +0 -1
- atquery-2.25.0/src/atquery/delta/_schema.py +99 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/delta/cutoff.py +44 -3
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/delta/exporter.py +46 -17
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/__init__.py +35 -1
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/ddl.py +118 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/diff.py +105 -2
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/model.py +90 -0
- atquery-2.25.0/src/atquery/ecd/parser.py +410 -0
- atquery-2.25.0/src/atquery/ecd/routines.py +108 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/skeleton.py +33 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/engine.py +12 -2
- atquery-2.20.2/src/atquery/delta/_schema.py +0 -70
- atquery-2.20.2/src/atquery/ecd/_toml.py +0 -16
- atquery-2.20.2/src/atquery/ecd/parser.py +0 -241
- {atquery-2.20.2 → atquery-2.25.0}/LICENSE +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/aio/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/aio/api.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/csv.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/diff.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/main.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/migrate.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/patch.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/cli/scenario.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/delta/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/duckdb.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/aio.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/core.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/dump/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/dump/__main__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/dump/core.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/meta.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/pooling.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/restore/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/restore/__main__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/mysql/restore/core.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/dialect/sqlite.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/diff/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/diff/comparator.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/diff/generator.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/diff/git_integration.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/diff/models.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/diff/parser.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/catalog.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/erd.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/errors.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/resolver.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/ecd/seed.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/factory.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/migration/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/migration/_migrator.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/migration/_protocol.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/migration/_standard.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/migration/_types.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/_apply.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/_convert.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/_errors.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/_log.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/_meta.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/_model.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/patch/_sql.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/py.typed +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/testing/__init__.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/testing/creator.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/testing/loader.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/testing/schema.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/testing/validator.py +0 -0
- {atquery-2.20.2 → atquery-2.25.0}/src/atquery/type.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: atquery
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.25.0
|
|
4
4
|
Summary: A Python module for simplifying DBAPI usage with one-query-per-file SQL management.
|
|
5
5
|
Keywords: sql,database,dbapi,mysql,sqlite,duckdb
|
|
6
6
|
Author: alpine
|
|
@@ -10,23 +10,20 @@ Classifier: Development Status :: 4 - Beta
|
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
16
|
Classifier: Topic :: Database
|
|
19
|
-
Requires-Dist: tomli>=2.0.1 ; python_full_version < '3.11'
|
|
20
17
|
Requires-Dist: python-dotenv>=1.2.2 ; extra == 'all'
|
|
21
18
|
Requires-Dist: atquery[mysql,duckdb,testing,diff,delta-export] ; extra == 'all'
|
|
22
19
|
Requires-Dist: mysql-connector-python>=8.0,<10 ; extra == 'delta-export'
|
|
23
20
|
Requires-Dist: deltalake>=1.6.6 ; extra == 'delta-export'
|
|
24
|
-
Requires-Dist:
|
|
21
|
+
Requires-Dist: arro3-core>=0.9 ; extra == 'delta-export'
|
|
25
22
|
Requires-Dist: sqlglot>=30.4.2 ; extra == 'diff'
|
|
26
23
|
Requires-Dist: duckdb>=0.10.0 ; extra == 'duckdb'
|
|
27
24
|
Requires-Dist: mysql-connector-python>=8.0,<10 ; extra == 'mysql'
|
|
28
25
|
Requires-Dist: json5>=0.12.1 ; extra == 'testing'
|
|
29
|
-
Requires-Python: >=3.
|
|
26
|
+
Requires-Python: >=3.12
|
|
30
27
|
Provides-Extra: all
|
|
31
28
|
Provides-Extra: delta-export
|
|
32
29
|
Provides-Extra: diff
|
|
@@ -59,7 +56,7 @@ with ds.connect() as conn:
|
|
|
59
56
|
|
|
60
57
|
## 要件
|
|
61
58
|
|
|
62
|
-
- Python 3.
|
|
59
|
+
- Python 3.12以上
|
|
63
60
|
|
|
64
61
|
## ライセンス
|
|
65
62
|
|
|
@@ -4,13 +4,13 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "atquery"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.25.0"
|
|
8
8
|
description = "A Python module for simplifying DBAPI usage with one-query-per-file SQL management."
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
license-files = ["LICENSE"]
|
|
13
|
-
dependencies = [
|
|
13
|
+
dependencies = []
|
|
14
14
|
keywords = [
|
|
15
15
|
"sql",
|
|
16
16
|
"database",
|
|
@@ -24,8 +24,6 @@ classifiers = [
|
|
|
24
24
|
"Intended Audience :: Developers",
|
|
25
25
|
"Programming Language :: Python :: 3",
|
|
26
26
|
"Programming Language :: Python :: 3 :: Only",
|
|
27
|
-
"Programming Language :: Python :: 3.10",
|
|
28
|
-
"Programming Language :: Python :: 3.11",
|
|
29
27
|
"Programming Language :: Python :: 3.12",
|
|
30
28
|
"Programming Language :: Python :: 3.13",
|
|
31
29
|
"Programming Language :: Python :: 3.14",
|
|
@@ -44,7 +42,7 @@ duckdb = ["duckdb>=0.10.0"]
|
|
|
44
42
|
delta-export = [
|
|
45
43
|
"mysql-connector-python>=8.0,<10",
|
|
46
44
|
"deltalake>=1.6.6",
|
|
47
|
-
"
|
|
45
|
+
"arro3-core>=0.9",
|
|
48
46
|
]
|
|
49
47
|
testing = ["json5>=0.12.1"]
|
|
50
48
|
diff = ["sqlglot>=30.4.2"]
|
|
@@ -64,6 +62,7 @@ dev = [
|
|
|
64
62
|
"pyyaml>=6.0.3",
|
|
65
63
|
"rich>=14.3.3",
|
|
66
64
|
"pytest-asyncio>=1.4.0",
|
|
65
|
+
"pyarrow>=15.0.0",
|
|
67
66
|
]
|
|
68
67
|
|
|
69
68
|
[tool.uv]
|
|
@@ -4,15 +4,13 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "atquery"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.25.0"
|
|
8
8
|
description = "A Python module for simplifying DBAPI usage with one-query-per-file SQL management."
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
license-files = ["LICENSE"]
|
|
13
|
-
dependencies = [
|
|
14
|
-
"tomli>=2.0.1; python_version < '3.11'",
|
|
15
|
-
]
|
|
13
|
+
dependencies = []
|
|
16
14
|
authors = [
|
|
17
15
|
{ name = "alpine" },
|
|
18
16
|
]
|
|
@@ -22,8 +20,6 @@ classifiers = [
|
|
|
22
20
|
"Intended Audience :: Developers",
|
|
23
21
|
"Programming Language :: Python :: 3",
|
|
24
22
|
"Programming Language :: Python :: 3 :: Only",
|
|
25
|
-
"Programming Language :: Python :: 3.10",
|
|
26
|
-
"Programming Language :: Python :: 3.11",
|
|
27
23
|
"Programming Language :: Python :: 3.12",
|
|
28
24
|
"Programming Language :: Python :: 3.13",
|
|
29
25
|
"Programming Language :: Python :: 3.14",
|
|
@@ -43,7 +39,7 @@ duckdb = [
|
|
|
43
39
|
delta-export = [
|
|
44
40
|
"mysql-connector-python>=8.0,<10",
|
|
45
41
|
"deltalake>=1.6.6",
|
|
46
|
-
"
|
|
42
|
+
"arro3-core>=0.9",
|
|
47
43
|
]
|
|
48
44
|
testing = [
|
|
49
45
|
"json5>=0.12.1",
|
|
@@ -71,6 +67,8 @@ dev = [
|
|
|
71
67
|
"pyyaml>=6.0.3",
|
|
72
68
|
"rich>=14.3.3",
|
|
73
69
|
"pytest-asyncio>=1.4.0",
|
|
70
|
+
#-- delta tests (結果の検証にpyarrowを使う。atquery.delta本体はpyarrowに依存しない) --
|
|
71
|
+
"pyarrow>=15.0.0",
|
|
74
72
|
]
|
|
75
73
|
|
|
76
74
|
|
|
@@ -9,12 +9,14 @@ from .api_v2 import (
|
|
|
9
9
|
ATSQLError,
|
|
10
10
|
ATString,
|
|
11
11
|
ATWarning,
|
|
12
|
+
HiddenParams,
|
|
12
13
|
Resource,
|
|
13
14
|
create_datasource,
|
|
14
15
|
escape4like,
|
|
15
16
|
execute,
|
|
16
17
|
execute_script,
|
|
17
18
|
export_csv,
|
|
19
|
+
hide,
|
|
18
20
|
insert_csv,
|
|
19
21
|
load,
|
|
20
22
|
replace_csv,
|
|
@@ -33,11 +35,13 @@ __all__ = [
|
|
|
33
35
|
"ATSQLError",
|
|
34
36
|
"ATString",
|
|
35
37
|
"ATWarning",
|
|
38
|
+
"HiddenParams",
|
|
36
39
|
"Resource",
|
|
37
40
|
"create_datasource",
|
|
38
41
|
"escape4like",
|
|
39
42
|
"execute",
|
|
40
43
|
"execute_script",
|
|
44
|
+
"hide",
|
|
41
45
|
"insert_csv",
|
|
42
46
|
"load",
|
|
43
47
|
"sql",
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""SQLパラメータのSecrets(認証情報・鍵・ハッシュなど)を、例外の文字列から隠す(ADR-0056)。
|
|
2
|
+
|
|
3
|
+
呼び出し側が`hide()`で`params`に隠すキーを付ける(opt-in)。既定の出力は変えない。
|
|
4
|
+
`ATConnection.execute`と`ATQuery.execute_script`が、例外を捕まえて`conceal()`で隠して投げ直す。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
from collections.abc import Iterable, Mapping
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
MASK = "***"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class HiddenParams(dict):
|
|
17
|
+
"""隠すキーを持つ`params`。通常の`dict`として振る舞い、値はそのままDBへ渡る。
|
|
18
|
+
|
|
19
|
+
`repr()`(`Parameters:`の行や`%r`のログに出る)だけが、隠すキーの値を`'***'`にする。
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, data: Mapping[str, Any] | Iterable[tuple[str, Any]] = (), hidden: Iterable[str] = ()) -> None:
|
|
23
|
+
super().__init__(data)
|
|
24
|
+
self.hidden: frozenset[str] = frozenset(hidden)
|
|
25
|
+
|
|
26
|
+
def __repr__(self) -> str:
|
|
27
|
+
items = (
|
|
28
|
+
f"{key!r}: {MASK!r}" if key in self.hidden else f"{key!r}: {value!r}"
|
|
29
|
+
for key, value in self.items()
|
|
30
|
+
)
|
|
31
|
+
return "{" + ", ".join(items) + "}"
|
|
32
|
+
|
|
33
|
+
def copy(self) -> HiddenParams:
|
|
34
|
+
return HiddenParams(self, self.hidden)
|
|
35
|
+
|
|
36
|
+
def hidden_values(self) -> tuple[Any, ...]:
|
|
37
|
+
"""隠すキーの値(`None`は除く)。"""
|
|
38
|
+
return tuple(value for key in self.hidden if (value := self.get(key)) is not None)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def hide(params: Mapping[str, Any] | None, *names: str) -> HiddenParams:
|
|
42
|
+
"""`params`の`names`の値を、例外の文字列とログから隠す`params`にする。
|
|
43
|
+
|
|
44
|
+
`params`に無い名前を指定してもエラーにしない。`hide()`の結果にさらに`hide()`すると、隠すキーが加わる。
|
|
45
|
+
|
|
46
|
+
Example:
|
|
47
|
+
>>> params = atquery.hide({"key_id": key_id, "secret": secret}, "key_id", "secret")
|
|
48
|
+
>>> atquery.execute_script(conn, script, params)
|
|
49
|
+
"""
|
|
50
|
+
hidden = set(names)
|
|
51
|
+
if isinstance(params, HiddenParams):
|
|
52
|
+
hidden |= params.hidden
|
|
53
|
+
return HiddenParams(params or {}, hidden)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _forms(value: Any) -> list[str]:
|
|
57
|
+
"""`value`が、文字列(SQLやDBのエラー文)に現れうる形。"""
|
|
58
|
+
if isinstance(value, (bytes, bytearray, memoryview)):
|
|
59
|
+
text = bytes(value).decode("utf-8", "replace")
|
|
60
|
+
else:
|
|
61
|
+
text = str(value)
|
|
62
|
+
forms = [text]
|
|
63
|
+
if isinstance(value, str):
|
|
64
|
+
forms.append(text.replace("'", "''")) # execute_scriptが展開するSQLの文字列リテラル
|
|
65
|
+
return [form for form in forms if form]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def scrub(text: str, values: Iterable[Any]) -> str:
|
|
69
|
+
"""`text`の中の、`values`と一致する部分を`***`にする。長い文字列から先に置き換える。"""
|
|
70
|
+
if not text:
|
|
71
|
+
return text
|
|
72
|
+
forms = sorted({form for value in values for form in _forms(value)}, key=len, reverse=True)
|
|
73
|
+
for form in forms:
|
|
74
|
+
text = text.replace(form, MASK)
|
|
75
|
+
return text
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def log_sql(logger: logging.Logger, sql: str, params: Any, sql_file: str | None = None, strip: bool = False) -> None:
|
|
79
|
+
"""`atquery.sql`ロガーのDEBUGログに、SQLとパラメータを出す。`hide()`された値は`***`にする。
|
|
80
|
+
|
|
81
|
+
`execute_script`のSQLは値を展開済みなので、隠す値と一致する部分を`***`にする。
|
|
82
|
+
`strip`は、SQLの前後の空白を除く(DEBUGが無効なときは、何もしない)。
|
|
83
|
+
"""
|
|
84
|
+
if not logger.isEnabledFor(logging.DEBUG):
|
|
85
|
+
return
|
|
86
|
+
if sql_file:
|
|
87
|
+
logger.debug("[file] %s", sql_file)
|
|
88
|
+
if strip:
|
|
89
|
+
sql = sql.strip()
|
|
90
|
+
if isinstance(params, HiddenParams):
|
|
91
|
+
sql = scrub(sql, params.hidden_values())
|
|
92
|
+
logger.debug("[sql]\n%s\n[params]\n%r", sql, params)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def conceal(error: Any, params: HiddenParams) -> Any:
|
|
96
|
+
"""`ATSQLError`の出力から、`params`の隠す値を取り除く(`error`を書き換えて返す)。
|
|
97
|
+
|
|
98
|
+
- `message`・`sql`と、`str(error)`に出る`orig`の文字列: 隠す値を`***`にする
|
|
99
|
+
- `params`: 内部で作り直される前の`HiddenParams`に戻す(`Parameters:`の行が隠れる)
|
|
100
|
+
`orig`の属性そのものと`params`の値は、プログラムから参照できるように残す。
|
|
101
|
+
呼び出し側は、トレースバックの連鎖を切る`raise ... from None`で投げること。
|
|
102
|
+
"""
|
|
103
|
+
values = params.hidden_values()
|
|
104
|
+
error.hidden_values = values
|
|
105
|
+
error.message = scrub(error.message, values)
|
|
106
|
+
if error.sql:
|
|
107
|
+
error.sql = scrub(error.sql, values)
|
|
108
|
+
error.params = params
|
|
109
|
+
error.args = (error.message,)
|
|
110
|
+
return error
|
|
@@ -9,6 +9,7 @@ import inspect
|
|
|
9
9
|
import logging
|
|
10
10
|
from typing import Any, Callable, Generic, Sequence, TypeVar
|
|
11
11
|
|
|
12
|
+
from atquery._hide import HiddenParams, conceal
|
|
12
13
|
from atquery.engine import (
|
|
13
14
|
ATConnectionPoolTimeoutError,
|
|
14
15
|
ATDataSource,
|
|
@@ -144,14 +145,21 @@ class ATAsyncConnection(Generic[ConnType]):
|
|
|
144
145
|
|
|
145
146
|
_reject_multi_statement_sql(sql, params)
|
|
146
147
|
|
|
148
|
+
params_source = params if isinstance(params, HiddenParams) else None
|
|
147
149
|
params = {k: (None if v is NULL else v) for k, v in params.items()} if params else {}
|
|
148
150
|
|
|
149
151
|
try:
|
|
150
152
|
return await self.__aexecute__(self.connection, sql, params, buffered)
|
|
151
153
|
except ATSQLError as ex:
|
|
154
|
+
if params_source is not None:
|
|
155
|
+
# dialectの内部でparamsは作り直されるので、元のHiddenParamsに戻して隠す(ADR-0056)
|
|
156
|
+
raise conceal(ex, params_source) from None
|
|
152
157
|
raise ex
|
|
153
158
|
except Exception as ex:
|
|
154
|
-
|
|
159
|
+
error = ATSQLError(str(ex), ex, sql=sql, sql_file=None, params=params)
|
|
160
|
+
if params_source is not None:
|
|
161
|
+
raise conceal(error, params_source) from None
|
|
162
|
+
raise error
|
|
155
163
|
|
|
156
164
|
async def __aexecute__(
|
|
157
165
|
self, conn: ConnType, sql: str, params: dict, buffered: bool
|
|
@@ -19,6 +19,7 @@ from typing import (
|
|
|
19
19
|
cast,
|
|
20
20
|
)
|
|
21
21
|
|
|
22
|
+
from atquery._hide import HiddenParams, conceal, log_sql
|
|
22
23
|
from atquery.aio.engine import ATAsyncConnection, ATAsyncResult
|
|
23
24
|
from atquery.atquery2 import ATQuery, CodeBlock
|
|
24
25
|
from atquery.engine import ATRowCountError, ATSQLError
|
|
@@ -83,10 +84,7 @@ class ATAsyncQuery:
|
|
|
83
84
|
expect_rowcount: "int | tuple[int, int | None] | None" = None,
|
|
84
85
|
) -> ATAsyncResult:
|
|
85
86
|
sql = self._q.to_sql(params, orderby=orderby, limit=limit, offset=offset)
|
|
86
|
-
|
|
87
|
-
if self._sql_file:
|
|
88
|
-
_logger.debug("[file] %s", self._sql_file)
|
|
89
|
-
_logger.debug("[sql]\n%s\n[params]\n%r", sql.strip(), params)
|
|
87
|
+
log_sql(_logger, sql, params, self._sql_file, strip=True)
|
|
90
88
|
try:
|
|
91
89
|
result = await conn.execute(sql=sql, params=params, buffered=buffered)
|
|
92
90
|
except ATSQLError as ex:
|
|
@@ -171,10 +169,7 @@ class ATAsyncQuery:
|
|
|
171
169
|
) -> int:
|
|
172
170
|
try:
|
|
173
171
|
sql = self._q.to_count(params, limit=limit)
|
|
174
|
-
|
|
175
|
-
if self._sql_file:
|
|
176
|
-
_logger.debug("[file] %s", self._sql_file)
|
|
177
|
-
_logger.debug("[sql]\n%s\n[params]\n%r", sql.strip(), params)
|
|
172
|
+
log_sql(_logger, sql, params, self._sql_file, strip=True)
|
|
178
173
|
result = await conn.execute(sql, params, buffered=True)
|
|
179
174
|
return await result.scalar()
|
|
180
175
|
except ATSQLError as ex:
|
|
@@ -186,32 +181,38 @@ class ATAsyncQuery:
|
|
|
186
181
|
self, conn: ATAsyncConnection, params: dict | None = None
|
|
187
182
|
) -> None:
|
|
188
183
|
script_sql = self._q.to_sql(params, bind=True)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
_logger.debug("[file] %s", self._sql_file)
|
|
192
|
-
_logger.debug("[sql]\n%s\n[params]\n%r", script_sql, params)
|
|
184
|
+
log_sql(_logger, script_sql, params, self._sql_file)
|
|
185
|
+
hidden_params = params if isinstance(params, HiddenParams) else None
|
|
193
186
|
try:
|
|
194
187
|
await conn.execute_script(script_sql)
|
|
195
188
|
except ATSQLError as ex:
|
|
196
189
|
params_to_set = params if ex.params is None and params is not None else ex.params
|
|
197
190
|
sql_file_to_set = ex.sql_file or self._sql_file
|
|
191
|
+
error = ex
|
|
198
192
|
if params_to_set is not ex.params or sql_file_to_set is not ex.sql_file:
|
|
199
|
-
|
|
193
|
+
error = ATSQLError(
|
|
200
194
|
str(ex.orig),
|
|
201
195
|
ex.orig,
|
|
202
196
|
sql=ex.sql or script_sql,
|
|
203
197
|
sql_file=sql_file_to_set or "",
|
|
204
198
|
params=params_to_set,
|
|
205
|
-
)
|
|
199
|
+
)
|
|
200
|
+
if hidden_params is not None:
|
|
201
|
+
raise conceal(error, hidden_params) from None
|
|
202
|
+
if error is not ex:
|
|
203
|
+
raise error from ex.orig
|
|
206
204
|
raise
|
|
207
205
|
except Exception as ex:
|
|
208
|
-
|
|
206
|
+
error = ATSQLError(
|
|
209
207
|
str(ex),
|
|
210
208
|
ex,
|
|
211
209
|
sql=script_sql,
|
|
212
210
|
sql_file=self._sql_file or "",
|
|
213
211
|
params=params,
|
|
214
|
-
)
|
|
212
|
+
)
|
|
213
|
+
if hidden_params is not None:
|
|
214
|
+
raise conceal(error, hidden_params) from None
|
|
215
|
+
raise error from ex
|
|
215
216
|
|
|
216
217
|
async def iter_lines(
|
|
217
218
|
self,
|
|
@@ -3,6 +3,7 @@ from pathlib import Path
|
|
|
3
3
|
from textwrap import dedent
|
|
4
4
|
from typing import Union
|
|
5
5
|
|
|
6
|
+
from ._hide import HiddenParams, hide
|
|
6
7
|
from .atquery2 import ATQuery
|
|
7
8
|
from .dialect import create_datasource
|
|
8
9
|
from .engine import (
|
|
@@ -28,11 +29,13 @@ __all__ = [
|
|
|
28
29
|
"ATSQLError",
|
|
29
30
|
"ATString",
|
|
30
31
|
"ATWarning",
|
|
32
|
+
"HiddenParams",
|
|
31
33
|
"create_datasource",
|
|
32
34
|
"escape4like",
|
|
33
35
|
"execute",
|
|
34
36
|
"execute_script",
|
|
35
37
|
"export_csv",
|
|
38
|
+
"hide",
|
|
36
39
|
"insert_csv",
|
|
37
40
|
"load",
|
|
38
41
|
"replace_csv",
|
|
@@ -17,6 +17,7 @@ from typing import (
|
|
|
17
17
|
cast,
|
|
18
18
|
)
|
|
19
19
|
|
|
20
|
+
from ._hide import HiddenParams, conceal, log_sql
|
|
20
21
|
from .engine import ATConnection, ATResult, ATRow, ATSQLError
|
|
21
22
|
from .type import NULL, ATString, AttrDict
|
|
22
23
|
|
|
@@ -262,10 +263,7 @@ class ATQuery:
|
|
|
262
263
|
from .engine import ATRowCountError
|
|
263
264
|
|
|
264
265
|
sql = self.to_sql(params, orderby=orderby, limit=limit, offset=offset)
|
|
265
|
-
|
|
266
|
-
if self._sql_file:
|
|
267
|
-
_logger.debug("[file] %s", self._sql_file)
|
|
268
|
-
_logger.debug("[sql]\n%s\n[params]\n%r", sql.strip(), params)
|
|
266
|
+
log_sql(_logger, sql, params, self._sql_file, strip=True)
|
|
269
267
|
try:
|
|
270
268
|
result = conn.execute(sql=sql, params=params, buffered=buffered)
|
|
271
269
|
except ATSQLError as ex:
|
|
@@ -411,10 +409,7 @@ class ATQuery:
|
|
|
411
409
|
"""
|
|
412
410
|
try:
|
|
413
411
|
sql = self.to_count(params, limit=limit)
|
|
414
|
-
|
|
415
|
-
if self._sql_file:
|
|
416
|
-
_logger.debug("[file] %s", self._sql_file)
|
|
417
|
-
_logger.debug("[sql]\n%s\n[params]\n%r", sql.strip(), params)
|
|
412
|
+
log_sql(_logger, sql, params, self._sql_file, strip=True)
|
|
418
413
|
return conn.execute(sql, params, buffered=True).scalar()
|
|
419
414
|
except ATSQLError as ex:
|
|
420
415
|
if ex.sql_file is None and self._sql_file is not None:
|
|
@@ -437,33 +432,39 @@ class ATQuery:
|
|
|
437
432
|
ATSQLError: スクリプト実行時のエラー
|
|
438
433
|
"""
|
|
439
434
|
script_sql = self.to_sql(params, bind=True)
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
_logger.debug("[file] %s", self._sql_file)
|
|
443
|
-
_logger.debug("[sql]\n%s\n[params]\n%r", script_sql, params)
|
|
435
|
+
log_sql(_logger, script_sql, params, self._sql_file)
|
|
436
|
+
hidden_params = params if isinstance(params, HiddenParams) else None
|
|
444
437
|
try:
|
|
445
438
|
conn.execute_script(script_sql)
|
|
446
439
|
except ATSQLError as ex:
|
|
447
440
|
# パラメータ情報またはsql_fileが未設定の場合は補完する
|
|
448
441
|
params_to_set = params if ex.params is None and params is not None else ex.params
|
|
449
442
|
sql_file_to_set = ex.sql_file or self._sql_file
|
|
443
|
+
error = ex
|
|
450
444
|
if params_to_set is not ex.params or sql_file_to_set is not ex.sql_file:
|
|
451
|
-
|
|
445
|
+
error = ATSQLError(
|
|
452
446
|
str(ex.orig),
|
|
453
447
|
ex.orig,
|
|
454
448
|
sql=ex.sql or script_sql,
|
|
455
449
|
sql_file=sql_file_to_set or "",
|
|
456
450
|
params=params_to_set
|
|
457
|
-
)
|
|
451
|
+
)
|
|
452
|
+
if hidden_params is not None:
|
|
453
|
+
raise conceal(error, hidden_params) from None
|
|
454
|
+
if error is not ex:
|
|
455
|
+
raise error from ex.orig
|
|
458
456
|
raise
|
|
459
457
|
except Exception as ex:
|
|
460
|
-
|
|
458
|
+
error = ATSQLError(
|
|
461
459
|
str(ex),
|
|
462
460
|
ex,
|
|
463
461
|
sql=script_sql,
|
|
464
462
|
sql_file=self._sql_file or "",
|
|
465
463
|
params=params
|
|
466
|
-
)
|
|
464
|
+
)
|
|
465
|
+
if hidden_params is not None:
|
|
466
|
+
raise conceal(error, hidden_params) from None
|
|
467
|
+
raise error from ex
|
|
467
468
|
|
|
468
469
|
def iter_lines(
|
|
469
470
|
self,
|
|
@@ -76,9 +76,15 @@ Examples:
|
|
|
76
76
|
# Export rows older than the cutoff, then delete them from MySQL (safe to re-run)
|
|
77
77
|
atquery delta cutoff run access_logs --time-column created_datetime --cutoff-at 2026-01-01T00:00:00
|
|
78
78
|
|
|
79
|
-
#
|
|
79
|
+
# Same, with the exported rows sorted by member_id (fewer row groups to read per member)
|
|
80
|
+
atquery delta cutoff run access_logs --time-column created_datetime --cutoff-at 2026-01-01T00:00:00 --order-by member_id
|
|
81
|
+
|
|
82
|
+
# Rewrite small data files into fewer, larger ones (does not keep the row order)
|
|
80
83
|
atquery delta compact access_logs
|
|
81
84
|
|
|
85
|
+
# Rewrite the data files ordered by a column (z-order; rewrites the whole table)
|
|
86
|
+
atquery delta compact access_logs --z-order member_id
|
|
87
|
+
|
|
82
88
|
# Physically delete data files removed more than 7 days ago
|
|
83
89
|
atquery delta vacuum access_logs --older-than 7d
|
|
84
90
|
|
|
@@ -124,10 +130,28 @@ Notes:
|
|
|
124
130
|
metavar="N",
|
|
125
131
|
help="Max rows per DELETE statement (default: 10000)",
|
|
126
132
|
)
|
|
133
|
+
cutoff_run_parser.add_argument(
|
|
134
|
+
"--order-by",
|
|
135
|
+
action="append",
|
|
136
|
+
dest="order_by",
|
|
137
|
+
default=[],
|
|
138
|
+
metavar="COLUMN",
|
|
139
|
+
help="Sort the exported rows by this column, ascending (repeatable). "
|
|
140
|
+
"Rows are ordered within one export, so lookups by the first column read fewer row groups",
|
|
141
|
+
)
|
|
127
142
|
_add_common_args(cutoff_run_parser)
|
|
128
143
|
|
|
129
144
|
compact_parser = sub.add_parser("compact", help="Rewrite small data files into fewer, larger ones")
|
|
130
145
|
compact_parser.add_argument("table_name", help="Source MySQL table (also the Delta table name)")
|
|
146
|
+
compact_parser.add_argument(
|
|
147
|
+
"--z-order",
|
|
148
|
+
action="append",
|
|
149
|
+
dest="z_order",
|
|
150
|
+
default=[],
|
|
151
|
+
metavar="COLUMN",
|
|
152
|
+
help="Z-order the data by this column instead of plain compaction (repeatable). "
|
|
153
|
+
"Plain compaction does not keep the row order; z-order rewrites the whole table",
|
|
154
|
+
)
|
|
131
155
|
_add_output_name_arg(compact_parser, "Delta table name to compact, without namespace (default: table_name)")
|
|
132
156
|
_add_common_args(compact_parser)
|
|
133
157
|
|
|
@@ -212,13 +236,16 @@ def _execute_cutoff_run(args: argparse.Namespace, exporter) -> None:
|
|
|
212
236
|
|
|
213
237
|
cutoff_at = _parse_datetime(args.cutoff_at)
|
|
214
238
|
DeltaCutoffOffloader(
|
|
215
|
-
exporter,
|
|
239
|
+
exporter,
|
|
240
|
+
time_column=args.time_column,
|
|
241
|
+
purge_batch_size=args.purge_batch_size,
|
|
242
|
+
order_by=args.order_by or None,
|
|
216
243
|
).run(args.table_name, cutoff_at)
|
|
217
244
|
print(f"offloaded: {'.'.join(exporter.table_identifier(args.table_name))} (cutoff_at < {args.cutoff_at})")
|
|
218
245
|
|
|
219
246
|
|
|
220
247
|
def _execute_compact(args: argparse.Namespace, exporter) -> None:
|
|
221
|
-
result = exporter.compact(args.table_name, output_name=args.output_name)
|
|
248
|
+
result = exporter.compact(args.table_name, output_name=args.output_name, z_order=args.z_order or None)
|
|
222
249
|
identifier = ".".join(exporter.table_identifier(args.table_name, args.output_name))
|
|
223
250
|
print(
|
|
224
251
|
f"compacted: {identifier} "
|