atquery 2.17.1__tar.gz → 2.18.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.18.0}/PKG-INFO +7 -5
- {atquery-2.17.1 → atquery-2.18.0}/pyproject.toml +10 -10
- {atquery-2.17.1 → atquery-2.18.0}/pyproject.toml.orig +10 -11
- atquery-2.18.0/src/atquery/cli/iceberg.py +241 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/main.py +13 -0
- atquery-2.18.0/src/atquery/iceberg/__init__.py +6 -0
- atquery-2.18.0/src/atquery/iceberg/_catalog.py +478 -0
- atquery-2.18.0/src/atquery/iceberg/_schema.py +87 -0
- atquery-2.18.0/src/atquery/iceberg/cutoff.py +162 -0
- atquery-2.18.0/src/atquery/iceberg/exporter.py +252 -0
- {atquery-2.17.1 → atquery-2.18.0}/LICENSE +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/README.md +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/aio/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/aio/api.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/aio/engine.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/aio/query.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/api_v2.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/atquery2.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/columns.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/csv.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/ddl.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/diff.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/ecd.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/migrate.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/routines.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/scenario.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/schemas.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/cli/tables.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/duckdb.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/aio.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/core.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/dump/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/dump/__main__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/dump/core.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/meta.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/pooling.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/restore/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/restore/__main__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/mysql/restore/core.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/dialect/sqlite.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/diff/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/diff/comparator.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/diff/generator.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/diff/git_integration.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/diff/models.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/diff/parser.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/_toml.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/catalog.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/ddl.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/diff.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/erd.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/errors.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/model.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/parser.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/resolver.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/seed.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/ecd/skeleton.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/engine.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/factory.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/migration/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/migration/_migrator.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/migration/_protocol.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/migration/_standard.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/migration/_types.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/py.typed +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/testing/__init__.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/testing/creator.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/testing/loader.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/testing/schema.py +0 -0
- {atquery-2.17.1 → atquery-2.18.0}/src/atquery/testing/validator.py +0 -0
- {atquery-2.17.1 → atquery-2.18.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.18.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.18.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.18.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
|
|
@@ -716,6 +716,15 @@ Examples:
|
|
|
716
716
|
)
|
|
717
717
|
setup_ecd_parser(ecd_parser)
|
|
718
718
|
|
|
719
|
+
# iceberg サブコマンドの追加
|
|
720
|
+
from atquery.cli.iceberg import setup_parser as setup_iceberg_parser
|
|
721
|
+
iceberg_parser = subparsers.add_parser(
|
|
722
|
+
"iceberg",
|
|
723
|
+
help="Export MySQL tables to Iceberg: export/cutoff/catalog (requires atquery[iceberg-export])",
|
|
724
|
+
description="Export MySQL tables to Iceberg: export/cutoff/catalog",
|
|
725
|
+
)
|
|
726
|
+
setup_iceberg_parser(iceberg_parser)
|
|
727
|
+
|
|
719
728
|
parser.add_argument(
|
|
720
729
|
"-d",
|
|
721
730
|
"--datasource",
|
|
@@ -855,6 +864,10 @@ Examples:
|
|
|
855
864
|
from atquery.cli.ecd import execute_ecd
|
|
856
865
|
return execute_ecd(args)
|
|
857
866
|
|
|
867
|
+
if args.subcommand == "iceberg":
|
|
868
|
+
from atquery.cli.iceberg import execute_iceberg
|
|
869
|
+
return execute_iceberg(args)
|
|
870
|
+
|
|
858
871
|
# データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-s/--schemaがあればschema部分を上書き
|
|
859
872
|
database_uri = resolve_datasource_uri(args.datasource, args.schema)
|
|
860
873
|
|