atquery 2.17.1__tar.gz → 2.19.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.17.1 → atquery-2.19.0}/PKG-INFO +7 -5
- {atquery-2.17.1 → atquery-2.19.0}/pyproject.toml +10 -10
- {atquery-2.17.1 → atquery-2.19.0}/pyproject.toml.orig +10 -11
- atquery-2.19.0/src/atquery/cli/iceberg.py +241 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/main.py +26 -0
- atquery-2.19.0/src/atquery/cli/patch.py +135 -0
- atquery-2.19.0/src/atquery/iceberg/__init__.py +6 -0
- atquery-2.19.0/src/atquery/iceberg/_catalog.py +478 -0
- atquery-2.19.0/src/atquery/iceberg/_schema.py +87 -0
- atquery-2.19.0/src/atquery/iceberg/cutoff.py +162 -0
- atquery-2.19.0/src/atquery/iceberg/exporter.py +252 -0
- atquery-2.19.0/src/atquery/patch/__init__.py +56 -0
- atquery-2.19.0/src/atquery/patch/_apply.py +317 -0
- atquery-2.19.0/src/atquery/patch/_convert.py +220 -0
- atquery-2.19.0/src/atquery/patch/_errors.py +52 -0
- atquery-2.19.0/src/atquery/patch/_log.py +182 -0
- atquery-2.19.0/src/atquery/patch/_meta.py +231 -0
- atquery-2.19.0/src/atquery/patch/_model.py +153 -0
- atquery-2.19.0/src/atquery/patch/_sql.py +135 -0
- {atquery-2.17.1 → atquery-2.19.0}/LICENSE +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/README.md +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/aio/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/aio/api.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/aio/engine.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/aio/query.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/api_v2.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/atquery2.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/columns.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/csv.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/ddl.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/diff.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/ecd.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/migrate.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/routines.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/scenario.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/schemas.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/cli/tables.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/duckdb.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/aio.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/core.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/dump/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/dump/__main__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/dump/core.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/meta.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/pooling.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/restore/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/restore/__main__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/mysql/restore/core.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/dialect/sqlite.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/diff/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/diff/comparator.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/diff/generator.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/diff/git_integration.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/diff/models.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/diff/parser.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/_toml.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/catalog.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/ddl.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/diff.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/erd.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/errors.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/model.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/parser.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/resolver.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/seed.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/ecd/skeleton.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/engine.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/factory.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/migration/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/migration/_migrator.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/migration/_protocol.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/migration/_standard.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/migration/_types.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/py.typed +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/testing/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/testing/creator.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/testing/loader.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/testing/schema.py +0 -0
- {atquery-2.17.1 → atquery-2.19.0}/src/atquery/testing/validator.py +0 -0
- {atquery-2.17.1 → atquery-2.19.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.19.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
|
|
@@ -14,21 +14,23 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
18
|
Classifier: Topic :: Database
|
|
18
19
|
Requires-Dist: tomli>=2.0.1 ; python_full_version < '3.11'
|
|
19
|
-
Requires-Dist: mysql-connector-python ; extra == 'all'
|
|
20
|
-
Requires-Dist: duckdb ; extra == 'all'
|
|
21
|
-
Requires-Dist: json5 ; extra == 'all'
|
|
22
|
-
Requires-Dist: sqlglot ; extra == 'all'
|
|
23
20
|
Requires-Dist: python-dotenv>=1.2.2 ; extra == 'all'
|
|
21
|
+
Requires-Dist: atquery[mysql,duckdb,testing,diff,iceberg-export] ; extra == 'all'
|
|
24
22
|
Requires-Dist: sqlglot>=30.4.2 ; extra == 'diff'
|
|
25
23
|
Requires-Dist: duckdb>=0.10.0 ; extra == 'duckdb'
|
|
24
|
+
Requires-Dist: mysql-connector-python>=8.0,<10 ; extra == 'iceberg-export'
|
|
25
|
+
Requires-Dist: pyiceberg>=0.12.0 ; extra == 'iceberg-export'
|
|
26
|
+
Requires-Dist: pyarrow>=15.0.0 ; extra == 'iceberg-export'
|
|
26
27
|
Requires-Dist: mysql-connector-python>=8.0,<10 ; extra == 'mysql'
|
|
27
28
|
Requires-Dist: json5>=0.12.1 ; extra == 'testing'
|
|
28
29
|
Requires-Python: >=3.10
|
|
29
30
|
Provides-Extra: all
|
|
30
31
|
Provides-Extra: diff
|
|
31
32
|
Provides-Extra: duckdb
|
|
33
|
+
Provides-Extra: iceberg-export
|
|
32
34
|
Provides-Extra: mysql
|
|
33
35
|
Provides-Extra: testing
|
|
34
36
|
Description-Content-Type: text/markdown
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "atquery"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.19.0"
|
|
8
8
|
description = "A Python module for simplifying DBAPI usage with one-query-per-file SQL management."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -28,6 +28,7 @@ classifiers = [
|
|
|
28
28
|
"Programming Language :: Python :: 3.11",
|
|
29
29
|
"Programming Language :: Python :: 3.12",
|
|
30
30
|
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Programming Language :: Python :: 3.14",
|
|
31
32
|
"Topic :: Database",
|
|
32
33
|
]
|
|
33
34
|
|
|
@@ -40,23 +41,21 @@ atquery = "atquery.cli.main:main"
|
|
|
40
41
|
[project.optional-dependencies]
|
|
41
42
|
mysql = ["mysql-connector-python>=8.0,<10"]
|
|
42
43
|
duckdb = ["duckdb>=0.10.0"]
|
|
44
|
+
iceberg-export = [
|
|
45
|
+
"mysql-connector-python>=8.0,<10",
|
|
46
|
+
"pyiceberg>=0.12.0",
|
|
47
|
+
"pyarrow>=15.0.0",
|
|
48
|
+
]
|
|
43
49
|
testing = ["json5>=0.12.1"]
|
|
44
50
|
diff = ["sqlglot>=30.4.2"]
|
|
45
51
|
all = [
|
|
46
|
-
"mysql-connector-python",
|
|
47
|
-
"duckdb",
|
|
48
|
-
"json5",
|
|
49
|
-
"sqlglot",
|
|
50
52
|
"python-dotenv>=1.2.2",
|
|
53
|
+
"atquery[mysql,duckdb,testing,diff,iceberg-export]",
|
|
51
54
|
]
|
|
52
55
|
|
|
53
56
|
[dependency-groups]
|
|
54
57
|
dev = [
|
|
55
|
-
"
|
|
56
|
-
"duckdb",
|
|
57
|
-
"json5",
|
|
58
|
-
"python-dotenv",
|
|
59
|
-
"sqlglot",
|
|
58
|
+
"atquery[all]",
|
|
60
59
|
"ruff",
|
|
61
60
|
"pyright",
|
|
62
61
|
"pytest>=7.0.0",
|
|
@@ -86,6 +85,7 @@ select = [
|
|
|
86
85
|
|
|
87
86
|
[tool.ruff.lint.per-file-ignores]
|
|
88
87
|
"docker/*.py" = ["INP"]
|
|
88
|
+
"examples/**/*.py" = ["INP"]
|
|
89
89
|
"scripts/*.py" = ["INP"]
|
|
90
90
|
"tests/*.py" = ["INP"]
|
|
91
91
|
"var/*.py" = ["INP"]
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "atquery"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.19.0"
|
|
8
8
|
description = "A Python module for simplifying DBAPI usage with one-query-per-file SQL management."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -26,6 +26,7 @@ classifiers = [
|
|
|
26
26
|
"Programming Language :: Python :: 3.11",
|
|
27
27
|
"Programming Language :: Python :: 3.12",
|
|
28
28
|
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Programming Language :: Python :: 3.14",
|
|
29
30
|
"Topic :: Database",
|
|
30
31
|
]
|
|
31
32
|
|
|
@@ -39,6 +40,11 @@ mysql = [
|
|
|
39
40
|
duckdb = [
|
|
40
41
|
"duckdb>=0.10.0",
|
|
41
42
|
]
|
|
43
|
+
iceberg-export = [
|
|
44
|
+
"mysql-connector-python>=8.0,<10",
|
|
45
|
+
"pyiceberg>=0.12.0",
|
|
46
|
+
"pyarrow>=15.0.0",
|
|
47
|
+
]
|
|
42
48
|
testing = [
|
|
43
49
|
"json5>=0.12.1",
|
|
44
50
|
]
|
|
@@ -46,21 +52,13 @@ diff = [
|
|
|
46
52
|
"sqlglot>=30.4.2",
|
|
47
53
|
]
|
|
48
54
|
all = [
|
|
49
|
-
"mysql-connector-python",
|
|
50
|
-
"duckdb",
|
|
51
|
-
"json5",
|
|
52
|
-
"sqlglot",
|
|
53
55
|
"python-dotenv>=1.2.2",
|
|
56
|
+
"atquery[mysql,duckdb,testing,diff,iceberg-export]"
|
|
54
57
|
]
|
|
55
58
|
|
|
56
59
|
[dependency-groups]
|
|
57
60
|
dev = [
|
|
58
|
-
|
|
59
|
-
"mysql-connector-python",
|
|
60
|
-
"duckdb",
|
|
61
|
-
"json5",
|
|
62
|
-
"python-dotenv",
|
|
63
|
-
"sqlglot",
|
|
61
|
+
"atquery[all]",
|
|
64
62
|
# -- ruff --
|
|
65
63
|
"ruff",
|
|
66
64
|
# -- pyright --
|
|
@@ -105,6 +103,7 @@ select = [
|
|
|
105
103
|
|
|
106
104
|
[tool.ruff.lint.per-file-ignores]
|
|
107
105
|
"docker/*.py" = ["INP"]
|
|
106
|
+
"examples/**/*.py" = ["INP"]
|
|
108
107
|
"scripts/*.py" = ["INP"]
|
|
109
108
|
"tests/*.py" = ["INP"]
|
|
110
109
|
"var/*.py" = ["INP"]
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"""atquery iceberg サブコマンド - MySQLテーブルのIcebergエクスポート(requires atquery[iceberg-export])"""
|
|
2
|
+
import argparse
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from atquery.cli.main import EXIT_ERROR, EXIT_SUCCESS, format_error_for_cli, resolve_datasource_uri
|
|
8
|
+
from atquery.dialect import create_datasource
|
|
9
|
+
|
|
10
|
+
_IMPORT_ERROR_MESSAGE = "Error: iceberg サブコマンドには atquery[iceberg-export] が必要です: pip install 'atquery[iceberg-export]'"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _add_common_args(parser: argparse.ArgumentParser, *, warehouse_required: bool = True) -> None:
|
|
14
|
+
"""各リーフコマンド共通のオプションを追加する。各オプションは対応する環境変数を default として参照する。"""
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"-d",
|
|
17
|
+
"--datasource",
|
|
18
|
+
default=argparse.SUPPRESS,
|
|
19
|
+
help="MySQL connection string (env: ATQUERY_DATASOURCE)",
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"-s",
|
|
23
|
+
"--schema",
|
|
24
|
+
default=argparse.SUPPRESS,
|
|
25
|
+
help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--warehouse",
|
|
29
|
+
default=os.environ.get("ATQUERY_ICEBERG_WAREHOUSE"),
|
|
30
|
+
metavar="URI",
|
|
31
|
+
help="Data file location, e.g. s3://bucket/warehouse (env: ATQUERY_ICEBERG_WAREHOUSE"
|
|
32
|
+
+ (")" if warehouse_required else ", optional)"),
|
|
33
|
+
)
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"--catalog-name",
|
|
36
|
+
default=os.environ.get("ATQUERY_ICEBERG_CATALOG_NAME", "atquery"),
|
|
37
|
+
dest="catalog_name",
|
|
38
|
+
metavar="NAME",
|
|
39
|
+
help="Catalog name that identifies which registered tables are visible "
|
|
40
|
+
"(env: ATQUERY_ICEBERG_CATALOG_NAME, default: atquery)",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--property",
|
|
44
|
+
action="append",
|
|
45
|
+
dest="properties",
|
|
46
|
+
default=[],
|
|
47
|
+
metavar="KEY=VALUE",
|
|
48
|
+
help="Storage property, e.g. s3.endpoint=http://localhost:9000 (repeatable)",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _add_namespace_arg(parser: argparse.ArgumentParser, *, schema_default: bool) -> None:
|
|
53
|
+
"""`schema_default=True`: 未指定時はテーブル名のschema(無ければdefault)。False: 全namespace。"""
|
|
54
|
+
help_text = "Iceberg namespace (env: ATQUERY_ICEBERG_NAMESPACE, default: "
|
|
55
|
+
help_text += (
|
|
56
|
+
"schema of table_name if given as schema.table, otherwise 'default')"
|
|
57
|
+
if schema_default
|
|
58
|
+
else "all namespaces)"
|
|
59
|
+
)
|
|
60
|
+
parser.add_argument("--namespace", default=os.environ.get("ATQUERY_ICEBERG_NAMESPACE"), help=help_text)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def setup_parser(parser: argparse.ArgumentParser) -> None:
|
|
64
|
+
"""iceberg サブコマンドのパーサーを設定する。"""
|
|
65
|
+
parser.formatter_class = argparse.RawDescriptionHelpFormatter
|
|
66
|
+
parser.epilog = """
|
|
67
|
+
Examples:
|
|
68
|
+
# Export a whole table (the Iceberg table is created automatically)
|
|
69
|
+
atquery iceberg export access_logs -d mysql://root@localhost/mydb --warehouse s3://bucket/warehouse
|
|
70
|
+
|
|
71
|
+
# Export a table in another schema (namespace defaults to the schema name: sails)
|
|
72
|
+
atquery iceberg export sails.activity_logs -d mysql://root@localhost/mydb --warehouse s3://bucket/warehouse
|
|
73
|
+
|
|
74
|
+
# Export the result of a query
|
|
75
|
+
atquery iceberg export access_logs --query "SELECT * FROM access_logs WHERE created_datetime < '2026-01-01'"
|
|
76
|
+
|
|
77
|
+
# Export under a different Iceberg table name
|
|
78
|
+
atquery iceberg export access_logs --output-name access_logs_2026
|
|
79
|
+
|
|
80
|
+
# Export rows older than the cutoff, then delete them from MySQL (safe to re-run)
|
|
81
|
+
atquery iceberg cutoff run access_logs --time-column created_datetime --cutoff-at 2026-01-01T00:00:00
|
|
82
|
+
|
|
83
|
+
# List tables in the catalog
|
|
84
|
+
atquery iceberg catalog list-tables
|
|
85
|
+
|
|
86
|
+
Notes:
|
|
87
|
+
Times are interpreted in the session time zone of the MySQL connection
|
|
88
|
+
(e.g. -d "mysql://.../mydb?time_zone=+09:00"). --cutoff-at must not carry a UTC offset.
|
|
89
|
+
Environment variables: ATQUERY_DATASOURCE, ATQUERY_ICEBERG_WAREHOUSE, ATQUERY_ICEBERG_NAMESPACE,
|
|
90
|
+
ATQUERY_ICEBERG_CATALOG_NAME
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
sub = parser.add_subparsers(dest="iceberg_command", help="iceberg commands")
|
|
94
|
+
|
|
95
|
+
export_parser = sub.add_parser("export", help="Export a MySQL table (or query result) to an Iceberg table")
|
|
96
|
+
export_parser.add_argument("table_name", help="Source MySQL table (also the Iceberg table name)")
|
|
97
|
+
export_parser.add_argument("--query", help="SELECT statement to export (default: all rows of table_name)")
|
|
98
|
+
export_parser.add_argument(
|
|
99
|
+
"--output-name",
|
|
100
|
+
dest="output_name",
|
|
101
|
+
metavar="NAME",
|
|
102
|
+
help="Iceberg table name to write to, without namespace (default: table_name)",
|
|
103
|
+
)
|
|
104
|
+
_add_common_args(export_parser)
|
|
105
|
+
_add_namespace_arg(export_parser, schema_default=True)
|
|
106
|
+
|
|
107
|
+
cutoff_parser = sub.add_parser("cutoff", help="Cutoff management for periodic log offloading")
|
|
108
|
+
cutoff_sub = cutoff_parser.add_subparsers(dest="cutoff_command", help="cutoff commands")
|
|
109
|
+
cutoff_run_parser = cutoff_sub.add_parser(
|
|
110
|
+
"run", help="Export rows older than the cutoff to Iceberg, then delete them from MySQL"
|
|
111
|
+
)
|
|
112
|
+
cutoff_run_parser.add_argument("table_name", help="Source MySQL table (also the Iceberg table name)")
|
|
113
|
+
cutoff_run_parser.add_argument(
|
|
114
|
+
"--cutoff-at",
|
|
115
|
+
required=True,
|
|
116
|
+
dest="cutoff_at",
|
|
117
|
+
metavar="DATETIME",
|
|
118
|
+
help="Rows with time_column < DATETIME are offloaded (ISO 8601, e.g. 2026-01-01T00:00:00)",
|
|
119
|
+
)
|
|
120
|
+
cutoff_run_parser.add_argument(
|
|
121
|
+
"--time-column",
|
|
122
|
+
required=True,
|
|
123
|
+
dest="time_column",
|
|
124
|
+
metavar="COLUMN",
|
|
125
|
+
help="DATETIME/TIMESTAMP column used for the cutoff",
|
|
126
|
+
)
|
|
127
|
+
cutoff_run_parser.add_argument(
|
|
128
|
+
"--purge-batch-size",
|
|
129
|
+
type=int,
|
|
130
|
+
default=10_000,
|
|
131
|
+
dest="purge_batch_size",
|
|
132
|
+
metavar="N",
|
|
133
|
+
help="Max rows per DELETE statement (default: 10000)",
|
|
134
|
+
)
|
|
135
|
+
_add_common_args(cutoff_run_parser)
|
|
136
|
+
_add_namespace_arg(cutoff_run_parser, schema_default=True)
|
|
137
|
+
|
|
138
|
+
catalog_parser = sub.add_parser("catalog", help="Inspect the catalog")
|
|
139
|
+
catalog_sub = catalog_parser.add_subparsers(dest="catalog_command", help="catalog commands")
|
|
140
|
+
list_tables_parser = catalog_sub.add_parser("list-tables", help="List tables registered in the catalog")
|
|
141
|
+
_add_common_args(list_tables_parser, warehouse_required=False)
|
|
142
|
+
_add_namespace_arg(list_tables_parser, schema_default=False)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def execute_iceberg(args: argparse.Namespace) -> int:
|
|
146
|
+
"""iceberg コマンドをディスパッチする。"""
|
|
147
|
+
command = args.iceberg_command
|
|
148
|
+
if command == "export":
|
|
149
|
+
return _run(args, _execute_export)
|
|
150
|
+
if command == "cutoff" and getattr(args, "cutoff_command", None) == "run":
|
|
151
|
+
return _run(args, _execute_cutoff_run)
|
|
152
|
+
if command == "catalog" and getattr(args, "catalog_command", None) == "list-tables":
|
|
153
|
+
return _run(args, _execute_list_tables)
|
|
154
|
+
print("usage: atquery iceberg {export,cutoff run,catalog list-tables} [options]", file=sys.stderr)
|
|
155
|
+
print("Run 'atquery iceberg --help' for more information.", file=sys.stderr)
|
|
156
|
+
return EXIT_ERROR
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _run(args: argparse.Namespace, func) -> int:
|
|
160
|
+
uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
|
|
161
|
+
if not uri:
|
|
162
|
+
print("Error: -d/--datasource または ATQUERY_DATASOURCE 環境変数を指定してください", file=sys.stderr)
|
|
163
|
+
return EXIT_ERROR
|
|
164
|
+
try:
|
|
165
|
+
properties = _parse_properties(args.properties)
|
|
166
|
+
with create_datasource(uri) as datasource:
|
|
167
|
+
func(args, datasource, properties)
|
|
168
|
+
return EXIT_SUCCESS
|
|
169
|
+
except ImportError as e:
|
|
170
|
+
print(f"{_IMPORT_ERROR_MESSAGE} ({e})", file=sys.stderr)
|
|
171
|
+
return EXIT_ERROR
|
|
172
|
+
except Exception as e:
|
|
173
|
+
print(f"Error: {format_error_for_cli(e)}", file=sys.stderr)
|
|
174
|
+
return EXIT_ERROR
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _parse_properties(values: list[str]) -> dict[str, str]:
|
|
178
|
+
properties: dict[str, str] = {}
|
|
179
|
+
for value in values:
|
|
180
|
+
key, sep, val = value.partition("=")
|
|
181
|
+
if not sep or not key:
|
|
182
|
+
raise ValueError(f"--property は KEY=VALUE 形式で指定してください: {value!r}")
|
|
183
|
+
properties[key] = val
|
|
184
|
+
return properties
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _require_warehouse(args: argparse.Namespace) -> str:
|
|
188
|
+
if not args.warehouse:
|
|
189
|
+
raise ValueError("--warehouse または ATQUERY_ICEBERG_WAREHOUSE 環境変数を指定してください")
|
|
190
|
+
return args.warehouse
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _execute_export(args: argparse.Namespace, datasource, properties: dict[str, str]) -> None:
|
|
194
|
+
from atquery.iceberg import IcebergExporter
|
|
195
|
+
|
|
196
|
+
exporter = IcebergExporter.from_datasource(
|
|
197
|
+
datasource,
|
|
198
|
+
_require_warehouse(args),
|
|
199
|
+
namespace=args.namespace,
|
|
200
|
+
catalog_name=args.catalog_name,
|
|
201
|
+
properties=properties,
|
|
202
|
+
)
|
|
203
|
+
exporter.export(args.table_name, query=args.query, output_name=args.output_name)
|
|
204
|
+
print("exported: " + ".".join(exporter.table_identifier(args.table_name, args.output_name)))
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _execute_cutoff_run(args: argparse.Namespace, datasource, properties: dict[str, str]) -> None:
|
|
208
|
+
from atquery.iceberg import IcebergCutoffOffloader, IcebergExporter
|
|
209
|
+
|
|
210
|
+
cutoff_at = _parse_datetime(args.cutoff_at)
|
|
211
|
+
exporter = IcebergExporter.from_datasource(
|
|
212
|
+
datasource,
|
|
213
|
+
_require_warehouse(args),
|
|
214
|
+
namespace=args.namespace,
|
|
215
|
+
catalog_name=args.catalog_name,
|
|
216
|
+
properties=properties,
|
|
217
|
+
)
|
|
218
|
+
IcebergCutoffOffloader(
|
|
219
|
+
exporter, time_column=args.time_column, purge_batch_size=args.purge_batch_size
|
|
220
|
+
).run(args.table_name, cutoff_at)
|
|
221
|
+
print(f"offloaded: {'.'.join(exporter.table_identifier(args.table_name))} (cutoff_at < {args.cutoff_at})")
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _execute_list_tables(args: argparse.Namespace, datasource, properties: dict[str, str]) -> None:
|
|
225
|
+
from atquery.iceberg._catalog import MySQLCatalog
|
|
226
|
+
|
|
227
|
+
catalog_properties = dict(properties)
|
|
228
|
+
if args.warehouse:
|
|
229
|
+
catalog_properties["warehouse"] = args.warehouse
|
|
230
|
+
catalog = MySQLCatalog(args.catalog_name, datasource, **catalog_properties)
|
|
231
|
+
namespaces = [(args.namespace,)] if args.namespace else sorted(catalog.list_namespaces())
|
|
232
|
+
for namespace in namespaces:
|
|
233
|
+
for identifier in sorted(catalog.list_tables(namespace)):
|
|
234
|
+
print(".".join(identifier))
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _parse_datetime(value: str) -> datetime:
|
|
238
|
+
try:
|
|
239
|
+
return datetime.fromisoformat(value)
|
|
240
|
+
except ValueError:
|
|
241
|
+
raise ValueError(f"--cutoff-at は ISO 8601 形式で指定してください: {value!r}") from None
|
|
@@ -707,6 +707,15 @@ Examples:
|
|
|
707
707
|
)
|
|
708
708
|
setup_migrate_parser(migrate_parser)
|
|
709
709
|
|
|
710
|
+
# patch サブコマンドの追加
|
|
711
|
+
from atquery.cli.patch import setup_parser as setup_patch_parser
|
|
712
|
+
patch_parser = subparsers.add_parser(
|
|
713
|
+
"patch",
|
|
714
|
+
help="Apply JSON change sets (PK-based insert/replace/delete) with an audit log",
|
|
715
|
+
description="Apply JSON change sets (PK-based insert/replace/delete) with an audit log",
|
|
716
|
+
)
|
|
717
|
+
setup_patch_parser(patch_parser)
|
|
718
|
+
|
|
710
719
|
# ecd サブコマンドの追加
|
|
711
720
|
from atquery.cli.ecd import setup_parser as setup_ecd_parser
|
|
712
721
|
ecd_parser = subparsers.add_parser(
|
|
@@ -716,6 +725,15 @@ Examples:
|
|
|
716
725
|
)
|
|
717
726
|
setup_ecd_parser(ecd_parser)
|
|
718
727
|
|
|
728
|
+
# iceberg サブコマンドの追加
|
|
729
|
+
from atquery.cli.iceberg import setup_parser as setup_iceberg_parser
|
|
730
|
+
iceberg_parser = subparsers.add_parser(
|
|
731
|
+
"iceberg",
|
|
732
|
+
help="Export MySQL tables to Iceberg: export/cutoff/catalog (requires atquery[iceberg-export])",
|
|
733
|
+
description="Export MySQL tables to Iceberg: export/cutoff/catalog",
|
|
734
|
+
)
|
|
735
|
+
setup_iceberg_parser(iceberg_parser)
|
|
736
|
+
|
|
719
737
|
parser.add_argument(
|
|
720
738
|
"-d",
|
|
721
739
|
"--datasource",
|
|
@@ -851,10 +869,18 @@ Examples:
|
|
|
851
869
|
from atquery.cli.migrate import execute_migrate
|
|
852
870
|
return execute_migrate(args)
|
|
853
871
|
|
|
872
|
+
if args.subcommand == "patch":
|
|
873
|
+
from atquery.cli.patch import execute_patch
|
|
874
|
+
return execute_patch(args)
|
|
875
|
+
|
|
854
876
|
if args.subcommand == "ecd":
|
|
855
877
|
from atquery.cli.ecd import execute_ecd
|
|
856
878
|
return execute_ecd(args)
|
|
857
879
|
|
|
880
|
+
if args.subcommand == "iceberg":
|
|
881
|
+
from atquery.cli.iceberg import execute_iceberg
|
|
882
|
+
return execute_iceberg(args)
|
|
883
|
+
|
|
858
884
|
# データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-s/--schemaがあればschema部分を上書き
|
|
859
885
|
database_uri = resolve_datasource_uri(args.datasource, args.schema)
|
|
860
886
|
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""atquery patch サブコマンド - JSON change set によるデータパッチの適用(ADR-0045)"""
|
|
2
|
+
import argparse
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from atquery.cli.main import EXIT_ERROR, EXIT_SUCCESS, resolve_datasource_uri
|
|
7
|
+
from atquery.dialect import create_datasource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _add_apply_args(parser: argparse.ArgumentParser) -> None:
|
|
11
|
+
parser.add_argument("file", help="change set のJSONファイル('-' で標準入力)")
|
|
12
|
+
parser.add_argument(
|
|
13
|
+
"-d",
|
|
14
|
+
"--datasource",
|
|
15
|
+
default=argparse.SUPPRESS,
|
|
16
|
+
help="Database connection string (env: ATQUERY_DATASOURCE)",
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"-s",
|
|
20
|
+
"--schema",
|
|
21
|
+
default=argparse.SUPPRESS,
|
|
22
|
+
help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"--idempotency-key",
|
|
26
|
+
default=None,
|
|
27
|
+
metavar="KEY",
|
|
28
|
+
help="Skip if a change set with the same key has already been applied (e.g. a queue message ID)",
|
|
29
|
+
)
|
|
30
|
+
parser.add_argument(
|
|
31
|
+
"--dry-run",
|
|
32
|
+
action="store_true",
|
|
33
|
+
dest="dry_run",
|
|
34
|
+
help="Execute inside a transaction, print the generated SQL and roll back (side effects such as triggers can still occur)",
|
|
35
|
+
)
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"--patch-table-prefix",
|
|
38
|
+
default=os.environ.get("ATQUERY_PATCH_TABLE_PREFIX", "atquery"),
|
|
39
|
+
dest="patch_table_prefix",
|
|
40
|
+
help="Prefix for the log table name (env: ATQUERY_PATCH_TABLE_PREFIX, default: atquery)",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--patch-schema",
|
|
44
|
+
default=os.environ.get("ATQUERY_PATCH_SCHEMA"),
|
|
45
|
+
dest="patch_schema",
|
|
46
|
+
metavar="SCHEMA",
|
|
47
|
+
help="Schema for the log table (env: ATQUERY_PATCH_SCHEMA)",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def setup_parser(parser: argparse.ArgumentParser) -> None:
|
|
52
|
+
"""patch サブコマンドのパーサーを設定する。"""
|
|
53
|
+
parser.formatter_class = argparse.RawDescriptionHelpFormatter
|
|
54
|
+
parser.epilog = """
|
|
55
|
+
A change set is a JSON file of PK-based insert / replace / delete operations applied in one transaction.
|
|
56
|
+
|
|
57
|
+
Examples:
|
|
58
|
+
# Show the generated SQL without committing
|
|
59
|
+
atquery patch apply fix.json --dry-run -d mysql://root@localhost/mydb
|
|
60
|
+
|
|
61
|
+
# Apply (the result is recorded in atquery_patch_logs)
|
|
62
|
+
atquery patch apply fix.json -d mysql://root@localhost/mydb
|
|
63
|
+
|
|
64
|
+
# Apply once per message even if delivered repeatedly
|
|
65
|
+
atquery patch apply fix.json --idempotency-key "$MESSAGE_ID"
|
|
66
|
+
"""
|
|
67
|
+
sub = parser.add_subparsers(dest="patch_command", help="patch commands")
|
|
68
|
+
apply_parser = sub.add_parser("apply", help="Apply a change set (JSON file)")
|
|
69
|
+
_add_apply_args(apply_parser)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def execute_patch(args: argparse.Namespace) -> int:
|
|
73
|
+
"""patch コマンドをディスパッチする。"""
|
|
74
|
+
if args.patch_command == "apply":
|
|
75
|
+
return _execute_apply(args)
|
|
76
|
+
print("usage: atquery patch apply FILE [options]", file=sys.stderr)
|
|
77
|
+
print("Run 'atquery patch --help' for more information.", file=sys.stderr)
|
|
78
|
+
return EXIT_ERROR
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _execute_apply(args: argparse.Namespace) -> int:
|
|
82
|
+
from atquery.patch import PatchError, PatchTransientError, apply, loads
|
|
83
|
+
|
|
84
|
+
uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
|
|
85
|
+
if not uri:
|
|
86
|
+
print("Error: -d/--datasource または ATQUERY_DATASOURCE 環境変数を指定してください", file=sys.stderr)
|
|
87
|
+
return EXIT_ERROR
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
if args.file == "-":
|
|
91
|
+
text = sys.stdin.read()
|
|
92
|
+
else:
|
|
93
|
+
with open(args.file, encoding="utf-8") as f:
|
|
94
|
+
text = f.read()
|
|
95
|
+
loads(text) # 構造エラーをDB接続前に検出する
|
|
96
|
+
|
|
97
|
+
with create_datasource(uri).connect() as conn:
|
|
98
|
+
result = apply(
|
|
99
|
+
conn,
|
|
100
|
+
text,
|
|
101
|
+
idempotency_key=args.idempotency_key,
|
|
102
|
+
dry_run=args.dry_run,
|
|
103
|
+
table_prefix=args.patch_table_prefix,
|
|
104
|
+
schema=args.patch_schema,
|
|
105
|
+
)
|
|
106
|
+
except PatchTransientError as e:
|
|
107
|
+
print(f"Error (transient, retryable): {e}", file=sys.stderr)
|
|
108
|
+
return EXIT_ERROR
|
|
109
|
+
except PatchError as e:
|
|
110
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
111
|
+
return EXIT_ERROR
|
|
112
|
+
except Exception as e:
|
|
113
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
114
|
+
return EXIT_ERROR
|
|
115
|
+
|
|
116
|
+
_print_result(result)
|
|
117
|
+
return EXIT_SUCCESS
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _print_result(result) -> None:
|
|
121
|
+
if result.status == "skipped":
|
|
122
|
+
print(f"Skipped: idempotency key {result.idempotency_key!r} has already been applied (log id: {result.log_id})")
|
|
123
|
+
return
|
|
124
|
+
|
|
125
|
+
if result.status == "dry_run":
|
|
126
|
+
print(f"Dry run: {len(result.operations)} operation(s) executed and rolled back")
|
|
127
|
+
else:
|
|
128
|
+
print(f"Applied: {len(result.operations)} operation(s) (log id: {result.log_id}, {result.execution_time_ms} ms)")
|
|
129
|
+
|
|
130
|
+
for op in result.operations:
|
|
131
|
+
print(f" [{op.index}] {op.op} {op.table}")
|
|
132
|
+
if result.status == "dry_run":
|
|
133
|
+
for line in op.sql.splitlines():
|
|
134
|
+
print(f" {line}")
|
|
135
|
+
print(f" params: {dict(op.params)}")
|