Skip to content

Commit 4462de8

Browse files
committed
added fields to TTableReference
1 parent 1265a50 commit 4462de8

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

dlt/common/schema/typing.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
NewType,
1414
Union,
1515
)
16-
from typing_extensions import Never
16+
from typing_extensions import Never, NotRequired
1717

1818
from dlt.common.data_types import TDataType
1919
from dlt.common.normalizers.typing import TNormalizersConfig
@@ -276,14 +276,43 @@ class TScd2StrategyDict(TMergeDispositionDict, total=False):
276276
]
277277

278278

279+
TReferenceCardinality = Literal["-", "<", ">", "<>"]
280+
"""Represents cardinality between `column` (left) and `referenced_column` (right)
281+
`-`: one-to-one
282+
`<`: one-to-many
283+
`>`: many-to-one
284+
`<>`: many-to-many
285+
286+
Note that `column <> referenced_column` is equivalent to specifying
287+
both `column < referenced_column` and `column > referenced_column`
288+
"""
289+
290+
279291
class TTableReference(TypedDict):
280292
"""Describes a reference to another table's columns.
281293
`columns` corresponds to the `referenced_columns` in the referenced table and their order should match.
282294
"""
283295

296+
label: NotRequired[str]
297+
"""Label to describe the relation 'liked'."""
298+
299+
cardinality: NotRequired[TReferenceCardinality]
300+
"""Cardinality of the relationship between `table.column` (left) and `referenced_table.referenced_column` (right)."""
301+
302+
table: NotRequired[str]
303+
"""Name of the table.
304+
When `TTableReference` is defined on a `TTableSchema` (i.e., "inline reference"), the `table`
305+
value is determined by `TTableSchema["name"]`
306+
"""
307+
284308
columns: Sequence[str]
309+
"""Name of the column(s) from `table`"""
310+
285311
referenced_table: str
312+
"""Name of the referenced table"""
313+
286314
referenced_columns: Sequence[str]
315+
"""Name of the columns(s) from `referenced_table`"""
287316

288317

289318
TTableReferenceParam = Sequence[TTableReference]

0 commit comments

Comments
 (0)