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 delta table dangling Parquet file bug #1695

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
3 changes: 2 additions & 1 deletion dlt/destinations/impl/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from dlt.destinations.job_impl import (
ReferenceFollowupJob,
FinalizedLoadJob,
FinalizedLoadJobWithFollowupJobs,
)
from dlt.destinations.impl.filesystem.configuration import FilesystemDestinationClientConfiguration
from dlt.destinations import path_utils
Expand Down Expand Up @@ -366,7 +367,7 @@ def create_load_job(
if ReferenceFollowupJob.is_reference_job(file_path):
return DeltaLoadFilesystemJob(file_path)
# otherwise just continue
return FilesystemLoadJobWithFollowup(file_path)
return FinalizedLoadJobWithFollowupJobs(file_path)

cls = FilesystemLoadJobWithFollowup if self.config.as_staging else FilesystemLoadJob
return cls(file_path)
Expand Down
45 changes: 45 additions & 0 deletions tests/load/pipeline/test_filesystem_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,51 @@ def data_types():
assert len(rows) == 10


@pytest.mark.parametrize(
"destination_config",
destinations_configs(
table_format_filesystem_configs=True,
table_format="delta",
bucket_subset=(FILE_BUCKET),
),
ids=lambda x: x.name,
)
def test_delta_table_does_not_contain_job_files(
destination_config: DestinationTestConfiguration,
) -> None:
"""Asserts Parquet job files do not end up in Delta table."""

pipeline = destination_config.setup_pipeline("fs_pipe", dev_mode=True)

@dlt.resource(table_format="delta")
def delta_table():
yield [{"foo": 1}]

# create Delta table
info = pipeline.run(delta_table())
assert_load_info(info)

# get Parquet jobs
completed_jobs = info.load_packages[0].jobs["completed_jobs"]
parquet_jobs = [
job
for job in completed_jobs
if job.job_file_info.table_name == "delta_table" and job.file_path.endswith(".parquet")
]
assert len(parquet_jobs) == 1

# get Parquet files in Delta table folder
with pipeline.destination_client() as client:
assert isinstance(client, FilesystemClient)
table_dir = client.get_table_dir("delta_table")
parquet_files = [f for f in client.fs_client.ls(table_dir) if f.endswith(".parquet")]
assert len(parquet_files) == 1

# Parquet file should not be the job file
file_id = parquet_jobs[0].job_file_info.file_id
assert file_id not in parquet_files[0]


@pytest.mark.parametrize(
"destination_config",
destinations_configs(
Expand Down
Loading