Skip to content

feat: make output file name of write task consistent with java api #1720

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

Open
wants to merge 2 commits into
base: main
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
12 changes: 10 additions & 2 deletions pyiceberg/io/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,7 @@ def _dataframe_to_data_files(
table_metadata: TableMetadata,
df: pa.Table,
io: FileIO,
task_id: int = 0,
write_uuid: Optional[uuid.UUID] = None,
counter: Optional[itertools.count[int]] = None,
) -> Iterable[DataFile]:
Expand Down Expand Up @@ -2574,7 +2575,13 @@ def _dataframe_to_data_files(
table_metadata=table_metadata,
tasks=iter(
[
WriteTask(write_uuid=write_uuid, task_id=next(counter), record_batches=batches, schema=task_schema)
WriteTask(
task_id=task_id,
write_uuid=write_uuid,
counter_id=next(counter),
record_batches=batches,
schema=task_schema,
)
for batches in bin_pack_arrow_table(df, target_file_size)
]
),
Expand All @@ -2587,8 +2594,9 @@ def _dataframe_to_data_files(
tasks=iter(
[
WriteTask(
task_id=task_id,
write_uuid=write_uuid,
task_id=next(counter),
counter_id=next(counter),
record_batches=batches,
partition_key=partition.partition_key,
schema=task_schema,
Expand Down
5 changes: 3 additions & 2 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,8 +1864,9 @@ def count(self) -> int:
class WriteTask:
"""Task with the parameters for writing a DataFile."""

write_uuid: uuid.UUID
task_id: int
write_uuid: uuid.UUID
counter_id: int
schema: Schema
record_batches: List[pa.RecordBatch]
sort_order_id: Optional[int] = None
Expand All @@ -1874,7 +1875,7 @@ class WriteTask:
def generate_data_file_filename(self, extension: str) -> str:
Copy link
Contributor

@Fokko Fokko Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Suggested change
def generate_data_file_filename(self, extension: str) -> str:
def generate_data_file_filename(self, extension: str, task_id: Optional[int] = None) -> str:

To only include the task ID for distributed engines?

# Mimics the behavior in the Java API:
# https://github.com/apache/iceberg/blob/a582968975dd30ff4917fbbe999f1be903efac02/core/src/main/java/org/apache/iceberg/io/OutputFileFactory.java#L92-L101
return f"00000-{self.task_id}-{self.write_uuid}.{extension}"
return f"00000-{self.task_id}-{self.write_uuid}-{self.counter_id:05d}.{extension}"


@dataclass(frozen=True)
Expand Down