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(python): skip empty row groups during stats gathering #2172

Merged
merged 3 commits into from
Feb 6, 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 python/deltalake/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ def get_file_stats_from_metadata(

def iter_groups(metadata: Any) -> Iterator[Any]:
for i in range(metadata.num_row_groups):
yield metadata.row_group(i)
if metadata.row_group(i).num_rows > 0:
yield metadata.row_group(i)

for column_idx in range(metadata.num_columns):
name = metadata.row_group(0).column(column_idx).path_in_schema
Expand Down
22 changes: 22 additions & 0 deletions python/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,3 +1251,25 @@ def test_with_deltalake_schema(tmp_path: pathlib.Path, sample_data: pa.Table):
)
delta_table = DeltaTable(tmp_path)
assert delta_table.schema().to_pyarrow() == sample_data.schema


def test_write_stats_empty_rowgroups(tmp_path: pathlib.Path):
# https://github.com/delta-io/delta-rs/issues/2169
data = pa.table(
{
"data": pa.array(["B"] * 1024 * 33),
}
)
write_deltalake(
tmp_path,
data,
max_rows_per_file=1024 * 32,
max_rows_per_group=1024 * 16,
min_rows_per_group=8 * 1024,
mode="overwrite",
)
dt = DeltaTable(tmp_path)
assert (
dt.to_pyarrow_dataset().to_table(filter=(pc.field("data") == "B")).shape[0]
== 33792
)
Loading