|
10 | 10 | import shutil |
11 | 11 | import threading |
12 | 12 | from time import sleep |
13 | | -from typing import Any, List, Tuple, cast |
| 13 | +from typing import Any, List, Tuple, cast, Union |
14 | 14 | from tenacity import retry_if_exception, Retrying, stop_after_attempt |
15 | 15 | from unittest.mock import patch |
16 | 16 | import pytest |
@@ -1837,6 +1837,50 @@ def infer(): |
1837 | 1837 | # print(pipeline.default_schema.to_pretty_yaml()) |
1838 | 1838 |
|
1839 | 1839 |
|
| 1840 | +@pytest.mark.parametrize( |
| 1841 | + "empty_value", |
| 1842 | + ["", []], |
| 1843 | + ids=["empty_string", "empty_list"], |
| 1844 | +) |
| 1845 | +def test_apply_hints_with_empty_values(empty_value: Union[str, List[Any]]) -> None: |
| 1846 | + @dlt.resource |
| 1847 | + def some_data(): |
| 1848 | + yield {"id": 1, "val": "some_data"} |
| 1849 | + |
| 1850 | + s = some_data() |
| 1851 | + pipeline = dlt.pipeline(pipeline_name="empty_value_hints", destination=DUMMY_COMPLETE) |
| 1852 | + |
| 1853 | + # check initial schema |
| 1854 | + pipeline.run(s) |
| 1855 | + table = pipeline.default_schema.get_table("some_data") |
| 1856 | + assert table["columns"]["id"] == { |
| 1857 | + "name": "id", |
| 1858 | + "data_type": "bigint", |
| 1859 | + "nullable": True, |
| 1860 | + } |
| 1861 | + |
| 1862 | + # check schema after setting primary key |
| 1863 | + s.apply_hints(primary_key=["id"]) |
| 1864 | + pipeline.run(s) |
| 1865 | + table = pipeline.default_schema.get_table("some_data") |
| 1866 | + assert table["columns"]["id"] == { |
| 1867 | + "name": "id", |
| 1868 | + "data_type": "bigint", |
| 1869 | + "nullable": False, |
| 1870 | + "primary_key": True, |
| 1871 | + } |
| 1872 | + |
| 1873 | + # check schema after passin an empty value as hints, which should remove primary |
| 1874 | + s.apply_hints(primary_key="") |
| 1875 | + pipeline.run(s) |
| 1876 | + table = pipeline.default_schema.get_table("some_data") |
| 1877 | + assert table["columns"]["id"] == { |
| 1878 | + "name": "id", |
| 1879 | + "data_type": "bigint", |
| 1880 | + "nullable": False, |
| 1881 | + } |
| 1882 | + |
| 1883 | + |
1840 | 1884 | def test_invalid_data_edge_cases() -> None: |
1841 | 1885 | # pass lambda directly to run, allowed now because functions can be extracted too |
1842 | 1886 | pipeline = dlt.pipeline(pipeline_name="invalid", destination=DUMMY_COMPLETE) |
|
0 commit comments