Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow dispatching items to nested tables when specified parent_table_name equals resource.table_name #2106

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dlt/common/schema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,11 @@ def diff_table(
partial_table[k] = v # type: ignore

# this should not really happen
if is_nested_table(tab_a) and (resource := tab_b.get("resource")):
if (
is_nested_table(tab_a)
and (resource := tab_b.get("resource"))
and resource != tab_a.get("parent")
):
raise TablePropertiesConflictException(
schema_name, table_name, "resource", resource, tab_a.get("parent")
)
Expand Down
22 changes: 22 additions & 0 deletions tests/pipeline/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,28 @@ def with_table_hints():
assert_data_table_counts(pipeline, {"table_a": 2, "table_b": 2, "table_c": 1})


def test_mark_parent_table() -> None:
@dlt.resource()
def my_table():
yield {"id": 1}
yield dlt.mark.with_hints(
{"id": 10},
dlt.mark.make_hints(table_name="my_other_table", parent_table_name="my_table"),
)

pipeline_name = "pipe_" + uniq_id()
pipeline = dlt.pipeline(pipeline_name=pipeline_name, destination="duckdb")
info = pipeline.run(my_table)
assert_load_info(info)
assert pipeline.last_trace.last_normalize_info.row_counts == {
"_dlt_pipeline_state": 1,
"my_table": 1,
"my_other_table": 1,
}
# check table counts
assert_data_table_counts(pipeline, {"my_table": 1, "my_other_table": 1})


def test_restore_state_on_dummy() -> None:
pipeline_name = "pipe_" + uniq_id()
p = dlt.pipeline(pipeline_name=pipeline_name, destination=DUMMY_COMPLETE)
Expand Down
Loading