Skip to content

Commit 6db9854

Browse files
committed
Drop column from child table test
1 parent 01c69a4 commit 6db9854

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

docs/website/docs/reference/command-line-interface.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ Selectively drop columns from specified tables.
495495
496496
**Usage**
497497
```sh
498-
dlt pipeline [pipeline_name] drop-columns [-h] [--from [FROM_RESOURCES ...]]
499-
[--columns [COLUMNS ...]]
498+
dlt pipeline [pipeline_name] drop-columns [-h] [--from-resources [FROM_RESOURCES
499+
...]] [--from-tables [FROM_TABLES ...]] [--columns [COLUMNS ...]]
500500
```
501501
502502
**Description**
@@ -520,8 +520,9 @@ Inherits arguments from [`dlt pipeline`](#dlt-pipeline).
520520
521521
**Options**
522522
* `-h, --help` - Show this help message and exit
523-
* `--from [FROM_RESOURCES ...]` - (with --columns) resource names to drop columns from.
524-
* `--columns [COLUMNS ...]` - (with --from) column names to drop from the specified resources.
523+
* `--from-resources [FROM_RESOURCES ...]` - Resource names to drop columns from.
524+
* `--from-tables [FROM_TABLES ...]` - Table names to drop columns from.
525+
* `--columns [COLUMNS ...]` - Column names to drop from the specified resources.
525526
526527
</details>
527528

tests/load/pipeline/test_drop_column.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def test_drop_column_command_resources(destination_config: DestinationTestConfig
2929
"""Test the drop command with resource and verify correct data is deleted from destination"""
3030
source: Any = droppable_source()
3131

32-
pipeline = destination_config.setup_pipeline("droppbale", dev_mode=True)
32+
pipeline = destination_config.setup_pipeline(
33+
"test_drop_column_command_resources", dev_mode=True
34+
)
3335
info = pipeline.run(source, **destination_config.run_kwargs)
3436
assert_load_info(info)
3537

@@ -81,3 +83,37 @@ def test_drop_column_command_resources(destination_config: DestinationTestConfig
8183
remaining_cols = pipeline.default_schema.get_table_columns(must_drop_info["from_table"])
8284
for dropped_col in must_drop_info["drop_columns"]:
8385
assert dropped_col not in remaining_cols
86+
87+
88+
@pytest.mark.parametrize(
89+
"destination_config",
90+
destinations_configs(
91+
default_sql_configs=True,
92+
local_filesystem_configs=True,
93+
all_buckets_filesystem_configs=True,
94+
table_format_local_configs=True,
95+
),
96+
ids=lambda x: x.name,
97+
)
98+
def test_drop_column_from_child_table(destination_config: DestinationTestConfiguration) -> None:
99+
"""Test the drop command with column and child table and verify correct data is deleted from destination"""
100+
source: Any = droppable_source()
101+
102+
pipeline = destination_config.setup_pipeline("test_drop_column_from_child_table", dev_mode=True)
103+
info = pipeline.run(source, **destination_config.run_kwargs)
104+
assert_load_info(info)
105+
106+
original_parent_tbl_cols = pipeline.default_schema.get_table_columns("droppable_b")
107+
assert "m" in pipeline.default_schema.get_table_columns("droppable_b__items")
108+
109+
drop_cmd = helpers.DropCommand(
110+
pipeline, from_resources=["droppable_b"], from_tables=["droppable_b__items"], columns=["m"]
111+
)
112+
must_drop_infos = drop_cmd.from_tables_drop_cols
113+
114+
assert [{"from_table": "droppable_b__items", "drop_columns": ["m"]}] == must_drop_infos
115+
116+
drop_cmd()
117+
118+
assert "m" not in pipeline.default_schema.get_table_columns("droppable_b__items")
119+
assert original_parent_tbl_cols == pipeline.default_schema.get_table_columns("droppable_b")

0 commit comments

Comments
 (0)