@@ -64,6 +64,7 @@ class TResourceHints(TResourceHintsBase, total=False):
64
64
file_format : TTableHintTemplate [TFileFormat ]
65
65
validator : ValidateItem
66
66
original_columns : TTableHintTemplate [TAnySchemaColumns ]
67
+ additional_table_hints : Optional [Dict [str , TTableHintTemplate [Any ]]]
67
68
68
69
69
70
class HintsMeta :
@@ -87,6 +88,7 @@ def make_hints(
87
88
schema_contract : TTableHintTemplate [TSchemaContract ] = None ,
88
89
table_format : TTableHintTemplate [TTableFormat ] = None ,
89
90
file_format : TTableHintTemplate [TFileFormat ] = None ,
91
+ additional_table_hints : Optional [Dict [str , TTableHintTemplate [Any ]]] = None ,
90
92
references : TTableHintTemplate [TTableReferenceParam ] = None ,
91
93
incremental : TIncrementalConfig = None ,
92
94
) -> TResourceHints :
@@ -121,6 +123,8 @@ def make_hints(
121
123
new_template ["merge_key" ] = merge_key
122
124
if validator :
123
125
new_template ["validator" ] = validator
126
+ if additional_table_hints is not None :
127
+ new_template ["additional_table_hints" ] = additional_table_hints
124
128
DltResourceHints .validate_dynamic_hints (new_template )
125
129
if incremental is not None : # TODO: Validate
126
130
new_template ["incremental" ] = Incremental .ensure_instance (incremental )
@@ -277,16 +281,16 @@ def apply_hints(
277
281
# if there is no template yet, create and set a new one.
278
282
default_wd = None if parent_table_name else DEFAULT_WRITE_DISPOSITION
279
283
t = make_hints (
280
- table_name ,
281
- parent_table_name ,
282
- write_disposition or default_wd ,
283
- columns ,
284
- primary_key ,
285
- merge_key ,
286
- schema_contract ,
287
- table_format ,
288
- file_format ,
289
- references ,
284
+ table_name = table_name ,
285
+ parent_table_name = parent_table_name ,
286
+ write_disposition = write_disposition or default_wd ,
287
+ columns = columns ,
288
+ primary_key = primary_key ,
289
+ merge_key = merge_key ,
290
+ schema_contract = schema_contract ,
291
+ table_format = table_format ,
292
+ file_format = file_format ,
293
+ references = references ,
290
294
)
291
295
else :
292
296
t = self ._clone_hints (t )
@@ -332,12 +336,14 @@ def apply_hints(
332
336
else :
333
337
t .pop ("schema_contract" , None )
334
338
if additional_table_hints is not None :
335
- for k , v in additional_table_hints .items ():
336
- if v :
337
- t [k ] = v # type: ignore[literal-required]
339
+ if additional_table_hints :
340
+ if t .get ("additional_table_hints" ) is not None :
341
+ for k , v in additional_table_hints .items ():
342
+ t ["additional_table_hints" ][k ] = v
338
343
else :
339
- t .pop (k , None ) # type: ignore[misc]
340
- t .pop ("additional_table_hints" , None ) # type: ignore
344
+ t ["additional_table_hints" ] = additional_table_hints
345
+ else :
346
+ t .pop ("additional_table_hints" , None )
341
347
342
348
# recreate validator if column definition or contract changed
343
349
if schema_contract is not None or columns is not None :
@@ -425,6 +431,7 @@ def merge_hints(
425
431
schema_contract = hints_template .get ("schema_contract" ),
426
432
table_format = hints_template .get ("table_format" ),
427
433
file_format = hints_template .get ("file_format" ),
434
+ additional_table_hints = hints_template .get ("additional_table_hints" ),
428
435
references = hints_template .get ("references" ),
429
436
create_table_variant = create_table_variant ,
430
437
)
@@ -546,6 +553,11 @@ def _create_table_schema(resource_hints: TResourceHints, resource_name: str) ->
546
553
if "incremental" in resource_hints :
547
554
DltResourceHints ._merge_incremental_column_hint (resource_hints ) # type: ignore[arg-type]
548
555
dict_ = cast (TTableSchema , resource_hints )
556
+ # apply table hints
557
+ if additional_table_hints := resource_hints .get ("additional_table_hints" ):
558
+ for k , v in additional_table_hints .items ():
559
+ dict_ [k ] = v # type: ignore[literal-required]
560
+ resource_hints .pop ("additional_table_hints" , None )
549
561
dict_ ["resource" ] = resource_name
550
562
return dict_
551
563
0 commit comments