Skip to content

Commit d7d9e35

Browse files
author
Jorrit Sandbrink
committed
add support for additional table hints
1 parent da5cdac commit d7d9e35

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

dlt/destinations/impl/synapse/synapse_adapter.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Literal, Set, get_args, Final
1+
from typing import Any, Literal, Set, get_args, Final, Dict
22

33
from dlt.extract import DltResource, resource as make_resource
44
from dlt.extract.typing import TTableHintTemplate
@@ -39,12 +39,14 @@ def synapse_adapter(data: Any, table_index_type: TTableIndexType = None) -> DltR
3939
"""
4040
resource = ensure_resource(data)
4141

42+
additional_table_hints: Dict[str, TTableHintTemplate[Any]] = {}
4243
if table_index_type is not None:
4344
if table_index_type not in TABLE_INDEX_TYPES:
4445
allowed_types = ", ".join(TABLE_INDEX_TYPES)
4546
raise ValueError(
4647
f"Table index type {table_index_type} is invalid. Allowed table index"
4748
f" types are: {allowed_types}."
4849
)
49-
resource._hints[TABLE_INDEX_TYPE_HINT] = table_index_type # type: ignore[typeddict-unknown-key]
50+
additional_table_hints[TABLE_INDEX_TYPE_HINT] = table_index_type
51+
resource.apply_hints(additional_table_hints=additional_table_hints)
5052
return resource

dlt/extract/hints.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from copy import copy, deepcopy
2-
from typing import List, TypedDict, cast, Any
2+
from typing import List, TypedDict, cast, Any, Optional, Dict
33

44
from dlt.common.schema.utils import DEFAULT_WRITE_DISPOSITION, merge_columns, new_column, new_table
55
from dlt.common.schema.typing import (
@@ -125,6 +125,7 @@ def apply_hints(
125125
merge_key: TTableHintTemplate[TColumnNames] = None,
126126
incremental: Incremental[Any] = None,
127127
schema_contract: TTableHintTemplate[TSchemaContract] = None,
128+
additional_table_hints: Optional[Dict[str, TTableHintTemplate[Any]]] = None,
128129
) -> None:
129130
"""Creates or modifies existing table schema by setting provided hints. Accepts both static and dynamic hints based on data.
130131
@@ -208,6 +209,14 @@ def apply_hints(
208209
t["incremental"] = None
209210
else:
210211
t["incremental"] = incremental
212+
if additional_table_hints is not None:
213+
# loop through provided hints and add, overwrite, or remove them
214+
for k, v in additional_table_hints.items():
215+
if v:
216+
t[k] = v # type: ignore[literal-required]
217+
else:
218+
t.pop(k, None) # type: ignore[misc]
219+
211220
self.set_hints(t)
212221

213222
def set_hints(self, hints_template: TResourceHints) -> None:

0 commit comments

Comments
 (0)