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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dlt_utils
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Shared utilities for dlt data pipelines with multi-company support
5
5
  Author: Jay van den Bos
6
6
  License: MIT
@@ -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.2.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
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dlt_utils
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Shared utilities for dlt data pipelines with multi-company support
5
5
  Author: Jay van den Bos
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dlt_utils"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Shared utilities for dlt data pipelines with multi-company support"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes