dlt-utils 0.2.0__tar.gz → 0.3.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.
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/PKG-INFO +1 -1
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/__init__.py +3 -1
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/pipeline.py +45 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils.egg-info/PKG-INFO +1 -1
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/pyproject.toml +1 -1
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/README.md +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/args.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/azure_keyvault.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/dates.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/incremental.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/logging.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils/schema.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils.egg-info/SOURCES.txt +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils.egg-info/dependency_links.txt +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils.egg-info/requires.txt +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/dlt_utils.egg-info/top_level.txt +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/setup.cfg +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/tests/test_azure_keyvault.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/tests/test_dates.py +0 -0
- {dlt_utils-0.2.0 → dlt_utils-0.3.0}/tests/test_incremental.py +0 -0
|
@@ -30,6 +30,7 @@ from .args import (
|
|
|
30
30
|
from .azure_keyvault import AzureKeyVault
|
|
31
31
|
from .logging import configure_logging
|
|
32
32
|
from .pipeline import (
|
|
33
|
+
cleanup_tombstones,
|
|
33
34
|
filter_resources,
|
|
34
35
|
get_resource_names,
|
|
35
36
|
mask_sensitive_value,
|
|
@@ -38,7 +39,7 @@ from .pipeline import (
|
|
|
38
39
|
)
|
|
39
40
|
|
|
40
41
|
|
|
41
|
-
__version__ = "0.
|
|
42
|
+
__version__ = "0.3.0"
|
|
42
43
|
|
|
43
44
|
__all__ = [
|
|
44
45
|
# Incremental
|
|
@@ -59,6 +60,7 @@ __all__ = [
|
|
|
59
60
|
# logging
|
|
60
61
|
"configure_logging",
|
|
61
62
|
# pipeline
|
|
63
|
+
"cleanup_tombstones",
|
|
62
64
|
"filter_resources",
|
|
63
65
|
"get_resource_names",
|
|
64
66
|
"mask_sensitive_value",
|
|
@@ -124,3 +124,48 @@ def mask_sensitive_value(value: str | None, show_chars: int = 2) -> str:
|
|
|
124
124
|
|
|
125
125
|
mid = len(value) // 2
|
|
126
126
|
return f"{value[:show_chars]}..{value[mid:mid+show_chars]}..***"
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def cleanup_tombstones(
|
|
130
|
+
pipeline: Any,
|
|
131
|
+
resources: list[str],
|
|
132
|
+
column_name: str = "_tt_is_tombstone",
|
|
133
|
+
) -> None:
|
|
134
|
+
"""
|
|
135
|
+
Clean up tombstone records from tables after a successful pipeline run.
|
|
136
|
+
|
|
137
|
+
Tombstones are placeholder records used to ensure delete-insert semantics
|
|
138
|
+
work correctly for partitions that have no real data. After the pipeline
|
|
139
|
+
completes, these tombstone records should be removed.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
pipeline: A dlt pipeline object with sql_client() method.
|
|
143
|
+
resources: List of resource/table names to clean tombstones from.
|
|
144
|
+
column_name: The boolean column name that marks tombstone records.
|
|
145
|
+
Defaults to "_tt_is_tombstone".
|
|
146
|
+
|
|
147
|
+
Example:
|
|
148
|
+
# Clean up tombstones from all resources except 'customer'
|
|
149
|
+
tombstone_resources = [r for r in sync_resources if r != "customer"]
|
|
150
|
+
cleanup_tombstones(pipeline, tombstone_resources)
|
|
151
|
+
|
|
152
|
+
# Clean up with a custom column name
|
|
153
|
+
cleanup_tombstones(pipeline, ["my_table"], column_name="is_tombstone")
|
|
154
|
+
"""
|
|
155
|
+
if not resources:
|
|
156
|
+
logger.debug("No resources provided for tombstone cleanup")
|
|
157
|
+
return
|
|
158
|
+
|
|
159
|
+
with pipeline.sql_client() as sql_client:
|
|
160
|
+
for resource_name in resources:
|
|
161
|
+
table_name = sql_client.make_qualified_table_name(resource_name)
|
|
162
|
+
delete_query = f"DELETE FROM {table_name} WHERE {column_name} = TRUE"
|
|
163
|
+
|
|
164
|
+
try:
|
|
165
|
+
sql_client.execute_sql(delete_query)
|
|
166
|
+
logger.info(f"Cleaned up tombstone records from {table_name}")
|
|
167
|
+
except Exception as e:
|
|
168
|
+
# Table might not exist on first run or if resource wasn't selected
|
|
169
|
+
logger.warning(
|
|
170
|
+
f"Could not clean tombstones from {table_name}: {e}"
|
|
171
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|